yfinance-exporter 1.0.0__tar.gz → 1.0.2__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
@@ -9,12 +9,13 @@ from the_conf import TheConf
|
|
9
9
|
from yfinance import Ticker
|
10
10
|
|
11
11
|
metaconf = {
|
12
|
-
"source_order": ["files"],
|
12
|
+
"source_order": ["env", "files"],
|
13
13
|
"config_files": [
|
14
14
|
"~/.config/yfinance-exporter.json",
|
15
15
|
"/etc/yfinance-exporter/yfinance-exporter.json",
|
16
16
|
],
|
17
17
|
"parameters": [
|
18
|
+
{"name": {"default": "yfinance-exporter"}},
|
18
19
|
{
|
19
20
|
"type": "list",
|
20
21
|
"stocks": [
|
@@ -23,11 +24,7 @@ metaconf = {
|
|
23
24
|
{"ycode": {"type": str}},
|
24
25
|
],
|
25
26
|
},
|
26
|
-
{
|
27
|
-
"loop": [
|
28
|
-
{"interval": {"type": int, "default": 240}},
|
29
|
-
]
|
30
|
-
},
|
27
|
+
{"loop": [{"interval": {"type": int, "default": 240}}]},
|
31
28
|
{
|
32
29
|
"prometheus": [
|
33
30
|
{"port": {"type": int, "default": 9100}},
|
@@ -48,12 +45,7 @@ except AttributeError as error:
|
|
48
45
|
"ERROR and FATAL are accepted"
|
49
46
|
) from error
|
50
47
|
|
51
|
-
|
52
|
-
"yfinance_exporter",
|
53
|
-
"",
|
54
|
-
["status"],
|
55
|
-
namespace=conf.prometheus.namespace,
|
56
|
-
)
|
48
|
+
DAEMON = Gauge("daemon", "", ["name", "section", "status"])
|
57
49
|
STOCK = Gauge(
|
58
50
|
"financial_positions",
|
59
51
|
"",
|
@@ -97,23 +89,25 @@ def collect(stock):
|
|
97
89
|
|
98
90
|
|
99
91
|
def main():
|
100
|
-
|
92
|
+
labels = {"name": conf.name, "section": "config"}
|
93
|
+
DAEMON.labels(status="loop-period", **labels).set(conf.loop.interval)
|
94
|
+
DAEMON.labels(status="item-count", **labels).set(len(conf.stocks))
|
95
|
+
|
96
|
+
labels["section"] = "exec"
|
101
97
|
while True:
|
102
98
|
start = datetime.now()
|
99
|
+
DAEMON.labels(status="items-ok", **labels).set(0)
|
100
|
+
DAEMON.labels(status="items-ko", **labels).set(0)
|
103
101
|
|
104
|
-
results = {"ok-stock": 0, "ko-stock": 0}
|
105
102
|
for stock in conf.stocks:
|
106
103
|
if collect(stock):
|
107
|
-
|
104
|
+
DAEMON.labels(status="items-ok", **labels).inc()
|
108
105
|
else:
|
109
|
-
|
106
|
+
DAEMON.labels(status="items-ko", **labels).inc()
|
110
107
|
|
111
108
|
exec_interval = (datetime.now() - start).total_seconds()
|
112
|
-
|
113
|
-
|
114
|
-
for result, count in results.items():
|
115
|
-
YFINANCE_EXPORTER.labels(result).set(count)
|
116
|
-
|
109
|
+
DAEMON.labels(status="exec-time", **labels).set(exec_interval)
|
110
|
+
DAEMON.labels(status="loop-count", **labels).inc()
|
117
111
|
interval = conf.loop.interval - exec_interval
|
118
112
|
if interval > 0:
|
119
113
|
time.sleep(interval)
|
File without changes
|