Merge "Prometheus Prototype Dashboard" into stable/fraser
[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
13 def customize_query(filename, rowtitle, panelname, expr):
14     with open(filename, 'r+') as f:
15         data = json.load(f)
16         x = data['rows']  # this is an array of the rows of the dashboard
17         for y in x:
18             if y['title'] == rowtitle:
19                 pan = y['panels']
20                 for i in range(len(pan) - 1):
21                     z = pan[i]
22                     if z['title'] == panelname:
23                         tar = z['targets']
24                         for a in tar:
25                             a['expr'] = expr
26                             f.seek(0)       # <--- reset file position to start
27                             json.dump(data, f, indent=4)
28                             f.truncate()
29
30
31 customize_query("/home/opnfv/bottlenecks/monitor/custom-query-dashboard.json",
32                 "Dashboard Row", "Memory Usage per Container",
33                 "Sample Prometheus Query")