Commit 595c1f19 authored by wolfsack's avatar wolfsack
Browse files

..

parent aa7749ad
......@@ -10,9 +10,9 @@ def hello_world():
return 'Hello World!'
@app.route('/metrics')
def metrics():
response = make_response(generate_metrics(), 200)
@app.route('/node/<path:node>/metrics')
def metrics(node):
response = make_response(generate_metrics(node), 200)
response.mimetype = "text/plain"
return response
......
......@@ -5,7 +5,7 @@ import psutil
from metric import Metric
def metrics():
def metrics(node: int):
cpu = psutil.cpu_percent()
cores = psutil.cpu_count()
cores_physical = psutil.cpu_count(logical=False)
......@@ -18,32 +18,43 @@ def metrics():
metric_type="gauge",
comment="CPU Usage in Percent",
value=cpu,
params=None
params={
"node": f"{node}"
}
), Metric(
metric_name="cpu_cores",
metric_type="gauge",
comment="Total CPU Cores",
value=cores,
params={"type": "all"}
params={
"type": "all",
"node": f"{node}"
}
), Metric(
metric_name="cpu_cores",
metric_type="gauge",
comment="Total CPU Cores",
value=cores_physical,
params={"type": "physical"}
params={
"type": "physical",
"node": f"{node}"
}
), Metric(
metric_name="boot_time",
metric_type="gauge",
comment="Time in ms",
value=boot_time,
params=None
params={
"node": f"{node}"
}
), Metric(
metric_name="memory_usage",
metric_type="gauge",
comment="Memory Usage Data",
value=memory[0],
params={
"type": "total"
"type": "total",
"node": f"{node}"
}
), Metric(
metric_name="memory_usage",
......@@ -51,7 +62,8 @@ def metrics():
comment="Memory Usage Data",
value=memory[1],
params={
"type": "available"
"type": "available",
"node": f"{node}"
}
), Metric(
metric_name="memory_usage",
......@@ -59,7 +71,8 @@ def metrics():
comment="Memory Usage Data",
value=memory[3],
params={
"type": "used"
"type": "used",
"node": f"{node}"
}
), Metric(
metric_name="memory_usage",
......@@ -67,7 +80,8 @@ def metrics():
comment="Memory Usage Data",
value=memory[4],
params={
"type": "free"
"type": "free",
"node": f"{node}"
}
)]
......@@ -81,7 +95,9 @@ def metrics():
metric_type="gauge",
comment="CPU Temperature",
value=temp,
params=None
params={
"node": f"{node}"
}
))
for partition in partitions:
......@@ -94,7 +110,8 @@ def metrics():
value=disk[0],
params={
"mount": partition[1],
"type": "total"
"type": "total",
"node": f"{node}"
}
))
metrics_list.append(
......@@ -105,7 +122,8 @@ def metrics():
value=disk[1],
params={
"mount": partition[1],
"type": "used"
"type": "used",
"node": f"{node}"
}
))
......@@ -117,17 +135,18 @@ def metrics():
value=disk[2],
params={
"mount": partition[1],
"type": "free"
"type": "free",
"node": f"{node}"
}
))
return metrics_list
def generate_metrics():
def generate_metrics(node: int):
output = ""
for metric in metrics():
for metric in metrics(node):
output += metric.to_string() + "\r\n" + "\r\n"
return output
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment