|
1 | 1 |
|
2 | 2 | import requests
|
3 |
| -import pandas as pd |
4 |
| -import numpy as np |
5 |
| -from netdata_pandas.data import get_data |
6 |
| -import matplotlib.pyplot as plt |
7 | 3 | import streamlit as st
|
8 | 4 | from collections import OrderedDict
|
9 | 5 | from urllib.parse import urlparse
|
10 | 6 | import re
|
11 | 7 |
|
12 | 8 |
|
13 |
| - |
14 | 9 | def parse_netdata_url(url):
|
15 | 10 | if url.startswith('http'):
|
16 | 11 | url_parsed = urlparse(url)
|
@@ -71,13 +66,32 @@ def parse_netdata_url(url):
|
71 | 66 | url_weights = f"http://{host}/api/v1/weights?after={after}&before={before}&options=raw"
|
72 | 67 | print(url_weights)
|
73 | 68 |
|
| 69 | +url_charts = f"http://{host}/api/v1/charts" |
| 70 | +charts_data = requests.get(url_charts).json()['charts'] |
| 71 | +data_chart_order = dict() |
| 72 | +for chart in charts_data: |
| 73 | + data_chart_order[chart] = dict() |
| 74 | + data_chart_order[chart]['priority'] = charts_data[chart]['priority'] |
| 75 | + data_chart_order[chart]['context'] = charts_data[chart]['context'] |
| 76 | +print(data_chart_order) |
| 77 | + |
| 78 | +#%% |
| 79 | + |
| 80 | +import pandas as pd |
| 81 | + |
| 82 | +df_chart_order = pd.DataFrame.from_dict(data_chart_order).transpose().reset_index() |
| 83 | +df_chart_order.columns = ['chart', 'priority', 'context'] |
| 84 | +df_chart_order = df_chart_order[['context', 'chart', 'priority']].sort_values('priority') |
| 85 | + |
| 86 | +#%% |
| 87 | + |
74 | 88 | weights_data = requests.get(url_weights).json()
|
75 | 89 |
|
76 | 90 | data = OrderedDict()
|
77 |
| -for context in weights_data['contexts']: |
| 91 | +for context in df_chart_order['context'].unique(): |
78 | 92 | context_key = f"{context}: {round(weights_data['contexts'][context]['weight'],2)}"
|
79 | 93 | data[context_key] = dict()
|
80 |
| - for chart in weights_data['contexts'][context]['charts']: |
| 94 | + for chart in df_chart_order[df_chart_order['context'] == context]['chart'].unique(): |
81 | 95 | chart_key = f"{chart}: {round(weights_data['contexts'][context]['charts'][chart]['weight'],2)}"
|
82 | 96 | data[context_key][chart_key] = dict()
|
83 | 97 | for dim in weights_data['contexts'][context]['charts'][chart]['dimensions']:
|
|
0 commit comments