-
Notifications
You must be signed in to change notification settings - Fork 0
/
StressHyperion.py
executable file
·103 lines (83 loc) · 2.8 KB
/
StressHyperion.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
96
97
98
99
100
101
102
103
#!/usr/bin/env python
"""
This script sends a bunch of Hyperion queryies to collect API endpoint reliability Data
"""
__author__ = "ghobson"
__created__ = ""
__revision__ = ""
__date__ = ""
from prometheus_client import Enum, Gauge, Info, generate_latest , push_to_gateway, pushadd_to_gateway, CollectorRegistry
import requests, json, time, os, sys, getopt
import traceback
import socket
import uuid
import socket
RPCNODE = "http://127.0.0.1:3056"
PROMETHEUS_GATEWAY = 'http://wax.stats.eosusa.news'
PROMETHEUS_JOB = 'waxhypproxy'
DEBUG = False
VERSION=1.0
registry = CollectorRegistry()
rLabels = ['endpoint','range','source']
nLabels = []
wax_rpc_metrics = Gauge('wax_hyp_rpc_metrics','WAX RPC metrics',rLabels, registry=registry)
wax_probe_version = Gauge('wax_hyp_probe_version','probe version',nLabels, registry=registry)
headers = { 'accept': 'application/json', 'content-type': 'application/json' }
def getBotID():
try:
return "%s"%(socket.getfqdn())
except:
return uuid.uuid1()
def logToPrometheus():
wax_probe_version.set(VERSION)
totcalls = 0
print("Stressing hyperion endpoints...")
i=0
while i < 40:
try:
history=requests.get(url = RPCNODE+"/v2/history/get_actions?account=producerjson", timeout=30)
sys.stdout.write(".")
sys.stdout.flush()
totcalls+=1
except:
traceback.print_exc()
i+=1
print("")
proxy = requests.get( url = RPCNODE+"/metrics" ).json()
totcalls+=1
#print(json.dumps(proxy, indent=4, sort_keys=True))
# RPC PROXY METRICS
for i in proxy:
for j in proxy[i]:
wax_rpc_metrics.labels(endpoint=i[8:],range=j,source=getBotID()).set(float(proxy[i][j]))
print("BOTID: %s: Stress run completed, processed %.0f calls"%(getBotID(),totcalls))
return True
def promFlush():
#print(generate_latest(registry))
pushadd_to_gateway(PROMETHEUS_GATEWAY, job=getBotID(), registry=registry)
if __name__ == '__main__':
null = None
false = False
true = True # fix the json below
try:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
## Create an abstract socket, by prefixing it with null.
s.bind( '\0stresshyperion_notify_lock')
except socket.error as e:
error_code = e.args[0]
error_string = e.args[1]
print "Process already running (%d:%s ). Exiting" % ( error_code, error_string)
sys.exit (0)
try:
opts, args = getopt.getopt(sys.argv[1:], "hdt:", ["help", "debug", "test"])
except getopt.error as msg:
print(msg)
sys.exit("Invalid arguments.")
for o, a in opts:
if o in ("-h", "--help"):
print("Usage: promgateway -d")
sys.exit()
if o in ("-d", "--debug"):
DEBUG = True
logToPrometheus()
promFlush()