-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.py
80 lines (74 loc) · 2.69 KB
/
metrics.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
from prometheus_client import Counter, Gauge, Info
import logging
metrics = {
"data_feed": Gauge("data_feed", "Numeric data feed", ["project", "code"]),
"data_feed_response_time_ms": Gauge(
"data_feed_response_time",
"Response time of data feed in milliseconds",
["project", "code"],
),
"data_feed_last_error": Info(
"data_feed_last_error", "Most recent error detected", [
"project", "code"]
),
"data_feed_error_count": Counter(
"data_feed_error_count",
"Number of errors whilst retrieving data feed",
["project", "code"],
),
"data_feed_update_count": Counter(
"data_feed_update_count",
"Number of times data feed retrieved",
["project", "code"],
),
"fluxmon_decimals": Gauge("fluxmon_decimals", "Decimals of reported value", ["project", "code"]),
"fluxmon_allocated_funds": Gauge(
"fluxmon_allocated_funds",
"Allocated funds",
["project", "code"],
),
"fluxmon_available_funds": Gauge(
"fluxmon_available_funds",
"Available funds",
["project", "code"],
),
"fluxmon_latest_answer": Gauge(
"fluxmon_latest_answer",
"Lastest answer",
["project", "code"],
),
"fluxmon_latest_round": Gauge(
"fluxmon_latest_round",
"Lastest round",
["project", "code"],
),
"fluxmon_withdrawable_payment": Gauge(
"fluxmon_withdrawable_payment",
"Withdrawable payment",
["project", "code"],
),
}
def init_metrics(cfg):
for data_feed_source in cfg["data_source_metrics"]:
metrics["data_feed"].labels(
data_feed_source["project"], data_feed_source["code"]
).set(0)
metrics["data_feed_response_time_ms"].labels(
data_feed_source["project"], data_feed_source["code"]
).set(0)
metrics["data_feed_last_error"].labels(
data_feed_source["project"], data_feed_source["code"]
).info({"status": "", "timestamp": "", "error": ""})
logging.info(
f"Initialised metrics for DATAFEED {data_feed_source['project']}" +
f" {data_feed_source['code']}",
)
for fluxmon_contract in cfg["fluxmon_contracts"]:
for metric in ["fluxmon_decimals", "fluxmon_allocated_funds", "fluxmon_available_funds", "fluxmon_latest_answer", "fluxmon_latest_round", "fluxmon_withdrawable_payment"]:
metrics[metric].labels(
fluxmon_contract["project"], fluxmon_contract["code"]
).set(0)
logging.info(
f"Initialised metrics for CONTRACT {fluxmon_contract['project']}" +
f" {fluxmon_contract['code']}",
)