-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStressWax.py
executable file
·163 lines (137 loc) · 5.67 KB
/
StressWax.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python
"""
This script sends a bunch of Wax Chain 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:3055"
PROMETHEUS_GATEWAY = 'http://wax.stats.eosusa.news'
PROMETHEUS_JOB = 'waxproxy'
DEBUG = False
VERSION=1.0
registry = CollectorRegistry()
rLabels = ['endpoint','range','source']
nLabels = []
wax_rpc_metrics = Gauge('wax_rpc_metrics','WAX RPC metrics',rLabels, registry=registry)
wax_probe_version = Gauge('wax_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 retryRPC( payload ):
retry=1
code=-1
while code != 200:
try:
rest_api = requests.post( url = RPCNODE+"/v1/chain/get_table_rows", timeout=10, headers=headers, data = json.dumps(payload)).json()
except:
code = 0
# if rows doesnt exist we have an ERROR
if "rows" in rest_api:
code = 200
else:
# if rows doesnt exist then we got an error, so we enter retry mode
code = 0
if code != 200:
if(retry > 10): return rest_api
if(DEBUG):
print(rest_api)
print("api call returned "+str(code)+" retry attempt "+str(retry))
time.sleep(1*retry) # Newdex doesn't like spamming , so reducing call rate
retry+=1
return rest_api
def is_non_zero_file(fpath):
return os.path.isfile(fpath) and os.path.getsize(fpath) > 0
def logToPrometheus():
wax_probe_version.set(VERSION)
PARAMS_DELPHISTATS = {"json":true,"code":"delphioracle","scope":"delphioracle","table":"stats","table_key":"","lower_bound":null,"upper_bound":null,"index_position":1,"key_type":"i64","limit":500,"reverse":false,"show_payer":false}
PARAMS_SIMPLEASSETS_AUTHORS = {"json":true,"code":"simpleassets","scope":"simpleassets","table":"authors","table_key":"","lower_bound":null,"upper_bound":null,"index_position":1,"key_type":"i64","limit":2000,"reverse":false,"show_payer":false}
totcalls = 0
print("Scanning delphioracle stats table.....")
delphistats = retryRPC(PARAMS_DELPHISTATS)
i=0
while i < len(delphistats['rows']):
try:
val_owner = delphistats['rows'][i]['owner']
payload = {"code":"eosio.token","account":val_owner,"symbol":"WAX"}
response = requests.post( url = RPCNODE+"/v1/chain/get_currency_balance" , timeout=10, headers=headers, data = json.dumps(payload)).json()
#print(" %s has %s"%(val_owner,response))
totcalls+=1
except:
pass # Do Nothing
i+=1
print("grabing simple assets authors.....")
simpleass = retryRPC(PARAMS_SIMPLEASSETS_AUTHORS)
totcalls+=1
i=0
categories = {}
while i < len(simpleass['rows']):
try:
val_author = simpleass['rows'][i]['author']
payload = {"code":"eosio.token","account":val_owner,"symbol":"WAX"}
response = requests.post( url = RPCNODE+"/v1/chain/get_currency_balance" , timeout=10, headers=headers, data = json.dumps(payload)).json()
#print("AUTHOR: %s has %s"%(val_author,response))
totcalls+=1
PARAMS = {"json":true,"code":"simpleassets","scope":val_author,"table":"sassets","table_key":"","lower_bound":null,"upper_bound":null,"index_position":1,"key_type":"i64","limit":2000,"reverse":false,"show_payer":false}
assets = retryRPC(PARAMS)
totcalls+=1
j=0
while j < len(assets['rows']):
if (len(assets['rows'][j]) > 0):
if ( assets['rows'][j]['category'] in categories ):
categories[assets['rows'][j]['category']] += 1
else:
categories[assets['rows'][j]['category']] = 1
j+=1
except:
pass # Do nothing
i+=1
#print("We found the following categories: %s "%(json.dumps(categories, indent=2, sort_keys=True)))
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( '\0stresswax_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()