48173f8e21373eacd7754924c6f908d1cfdc0bcd
[bottlenecks.git] / monitor / custom-dashboard.py
1 ##############################################################################
2 # Copyright (c) 2018 Huawei Tech and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import json
11
12 def customize_query(filename, rowtitle, panelname, expr):
13     with open(filename, 'r+') as f:
14         data = json.load(f)
15         x = data['rows'] #this is an array of the rows of the dashboard
16         for y in x:
17             if y['title'] == rowtitle:
18                 pan = y['panels']
19                 for i in range(len(pan)-1) :
20                     z = pan[i]
21                     if z['title'] == panelname:
22                         tar = z['targets']
23                         for a in tar:
24                             a['expr'] = expr
25                             f.seek(0)       # <--- reset file position to start
26                             json.dump(data, f, indent=4)
27                             f.truncate()
28
29 customize_query("/home/opnfv/bottlenecks/monitor/custom-query-dashboard.json",
30     "Dashboard Row", "Memory Usage per Container", "Sample Prometheus Query")
31