-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetric.py
79 lines (71 loc) · 3.48 KB
/
metric.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
import datetime
def metric_pool(data, tags):
string = "# Pools Data\n"
string += "cgminer_pool_count{%s} %s\n"%(tags, len(data['POOLS']))
for pool in data['POOLS']:
localtags = 'pool="%s",url="%s",stratum_url="%s",%s'%(pool['POOL'], pool['URL'], pool['Stratum URL'], tags)
string += 'cgminer_pool_diff_accepted{%s} %s\n'%(localtags, pool['Difficulty Accepted'])
string += 'cgminer_pool_rejected{%s} %s\n'%(localtags, pool['Difficulty Accepted'])
string += 'cgminer_pool_diff_rejected{%s} %s\n'%(localtags, pool['Difficulty Rejected'])
string += 'cgminer_pool_stale{%s} %s\n'%(localtags, pool['Stale'])
try:
[hr, mn, ss] = [int(x) for x in pool['Last Share Time'].split(':')]
sharetime = datetime.timedelta(hours=hr, minutes=mn, seconds=ss).seconds
except:
sharetime = 0
string += 'cgminer_pool_last_share{%s} %s\n'%(localtags, sharetime)
string += 'cgminer_pool_getworks{%s} %s\n'%(localtags, pool['Getworks'])
string += 'cgminer_pool_last_diff{%s} %s\n'%(localtags, pool['Last Share Difficulty'])
if pool['Status'] == "Alive":
status = 1
else:
status = 0
string += 'cgminer_pool_status{%s} %s\n'%(localtags, status)
if pool['Stratum Active']:
active = 1
else:
active = 0
string += 'cgminer_pool_stratum_active{%s} %s\n'%(localtags, active)
return (string)
def metric_summary(data, tags):
string = "#Pool Summary\n"
localtags = tags
string += 'cgminer_summary_rejected{%s} %s\n'%(localtags, data['SUMMARY'][0]['Rejected'])
string += 'cgminer_summary_found_blocks{%s} %s\n'%(localtags, data['SUMMARY'][0]['Found Blocks'])
string += 'cgminer_summary_elapsed{%s} %s\n'%(localtags, data['SUMMARY'][0]['Elapsed'])
string += 'cgminer_summary_hardware_errors{%s} %s\n'%(localtags, data['SUMMARY'][0]['Hardware Errors'])
string += 'cgminer_summary_total_mh{%s} %s\n'%(localtags, data['SUMMARY'][0]['Total MH'])
string += 'cgminer_summary_ghs_average{%s} %s\n'%(localtags, data['SUMMARY'][0]['GHS av'])
string += 'cgminer_summary_ghs_5s{%s} %s\n'%(localtags, data['SUMMARY'][0]['GHS 5s'])
return (string)
def metric_stats(data, tags):
string = "# Stats\n"
statdata = data['STATS'][1]
localtags = '%s'%(tags)
for entry in statdata:
if 'temp' in entry:
tempnum = entry.replace("temp","")
temp = statdata['temp%s'%(tempnum)]
# if '-' in temp:
# temp = temp.split('-')[1] or '0'
if str(temp) == '-':
continue
if '-' in str(temp):
temp = temp.split('-')[-1]
string += 'cgminer_stats_temp{temp="%s",%s} %s\n'%(tempnum, localtags, temp)
if 'chain_hw' in entry:
chainnum = entry.replace("chain_hw","")
if statdata['chain_rate%s'%(chainnum)]:
string += 'cgminer_stats_chain_rate{chain="%s",%s} %s\n'%(chainnum, localtags, statdata['chain_rate%s'%(chainnum)])
else:
string += 'cgminer_stats_chain_rate{chain="%s",%s} %s\n'%(chainnum, localtags, 0)
string += 'cgminer_stats_chain_acn{chain="%s",%s} %s\n'%(chainnum, localtags, statdata['chain_acn%s'%(chainnum)])
string += 'cgminer_stats_chain_hw{chain="%s",%s} %s\n'%(chainnum, localtags, statdata['chain_hw%s'%(chainnum)])
if 'fan' in entry and entry != "manual_fan_mode":
fannum = entry.replace("fan","")
string += 'cgminer_stats_fan{fan="%s",%s} %s\n'%(fannum, localtags, statdata['fan%s'%(fannum)])
if 'freq_avg' in entry:
freqnum = entry.replace("freq_avg","")
string += 'cgminer_stats_freq{freq="%s",%s} %s\n'%(freqnum, localtags, statdata['freq_avg%s'%(freqnum)])
string += 'cgminer_stats_frequency{%s} %s\n'%(localtags, statdata['frequency'])
return (string)