-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·36 lines (28 loc) · 898 Bytes
/
app.py
File metadata and controls
executable file
·36 lines (28 loc) · 898 Bytes
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
from multiprocessing import Manager, Process
from time import sleep
from flask import Flask
from config import Config
from metrics import Metrics
app = Flask(__name__)
manager = Manager()
metrics = manager.list()
@app.route("/metrics", methods=["GET"])
def metrics_endpoint():
if metrics:
return metrics[0].to_prometheus()
else:
return "GitlabStats has not yet finished collecting statistics..."
@app.before_first_request
def background_job():
def update_metrics():
while True:
print("Fetching stats...")
temp = Metrics()
if len(metrics) > 0:
metrics.pop(0)
metrics.append(temp)
print("Done!")
print(f"Sleeping for {Config.update_freq} seconds...")
sleep(Config.update_freq)
update_process = Process(target=update_metrics)
update_process.start()