forked from edgelaboratories/cassandra-exporter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
github-metric-help.py
97 lines (64 loc) · 2.27 KB
/
github-metric-help.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import collections
import itertools
import json
import re
import urllib.request
def combine_dicts(dicts):
res = collections.defaultdict(list)
for (key, value) in itertools.chain.from_iterable(map(dict.items, dicts)):
res[key].append(value)
return res
label_help = {
r'cassandra_cache.*': {
'cache': 'The cache name.'
},
r'cassandra_table_.*': {
'keyspace': 'The keyspace name.',
'table': 'The table name.',
'table_type': 'Type of table: `table`, `index` or `view`.',
'compaction_strategy_class': 'The compaction strategy class of the table.'
}
}
def get_label_help(family, label):
for (pattern, labels) in label_help.items():
if not re.match(pattern, family):
continue
return labels.get(label, '_No help specified._')
request = urllib.request.Request(url='http://localhost:9500/metrics', headers={'Accept': 'application/json'})
response = urllib.request.urlopen(request)
data = json.load(response)
print('== Contents')
print('''.Metric Families
|===
|Metric Family |Type |Help
''')
for (familyName, metricFamily) in sorted(data['metricFamilies'].items()):
print('|', '<<_{},{}>>'.format(familyName, familyName))
print('|', metricFamily['type'].lower())
print('|', metricFamily.get('help', '_No help specified._'))
print()
print('|===')
def exclude_system_table_labels(labels):
if labels.get('keyspace') in ('system_traces', 'system_schema', 'system_auth', 'system', 'system_distributed'):
return {}
return labels
print('== Metric Families')
for (familyName, metricFamily) in sorted(data['metricFamilies'].items()):
print('===', familyName)
print(metricFamily.get('help', '_No help specified._'))
print()
print('''.Available Labels
|===
|Label |Help |Example
''')
labels = combine_dicts(map(lambda m: exclude_system_table_labels(m.get('labels') or {}), metricFamily['metrics']))
if len(labels) == 0:
print('3+| _No labels defined._')
else:
for label, examples in labels.items():
print('|', '`{}`'.format(label))
print('|', get_label_help(familyName, label))
print('|', ', '.join(map(lambda e: '`{}`'.format(e), set(examples))))
print()
print('|===')
print()