-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathis_network_up.py
55 lines (48 loc) · 1.59 KB
/
is_network_up.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
import yaml
import requests
def get_targets():
with open("./prometheus/prometheus.yml") as file:
data = yaml.safe_load(file)
targets = data["scrape_configs"][1]["static_configs"][0]['targets']
return targets
def hit_target(target):
url = f"http://{target}/metrics"
response = requests.get(url)
if response.status_code == 200:
json_data = response.json()
format_and_print(json_data, target)
else:
print("Request unsuccessful, node exporter probably not running")
def hit_target_return_answer(target):
url = f"http://{target}/metrics"
response = requests.get(url)
if response.status_code == 200:
data = response.text
return data
else:
print("Request unsuccessful, node exporter probably not running")
return None
test_data = """ipfs_up 1 1711185189389
ipfs_blocks_size 46011967 1711185189389
ipfs_clus_up 0 1711185189389
bartering_bootstrap_running 0 1711185189389
ipfs_pinned QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn recursive
1711185189389
bartering_running 1 1711185189389"""
def format_and_print(data, target):
states = []
for metric in ["ipfs_up","bartering_bootstrap_running","bartering_running"]:
if data[metric]==1:
states.append("\033[92mup\033[0m")
else:
states.append("\033[91mdown\033[0m")
print(f"""
On node {target}
IPFS is {states[0]}
Bartering bootstrap is {states[1]}
Bartering is {states[2]}
""")
if __name__=="__main__":
targets = get_targets()
for target in targets:
hit_target(target)