Skip to content

Commit

Permalink
added more details, based on TheChrisTech
Browse files Browse the repository at this point in the history
  • Loading branch information
mboisson committed Oct 20, 2022
1 parent 2368c9c commit d9348fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import requests
import time
import re

from flask import render_template, Flask, make_response, Response

Expand Down Expand Up @@ -70,13 +71,20 @@ def metrics():
else:
attrib["currentValue"] = attrib["currentValue"]

# Sanitise the device name as it will appear in the label
device_name = device_details['label'].lower().replace(' ','_').replace('-','_')
# Sanitise the metric name
metric_name = attrib['name'].lower().replace(' ','_').replace('-','_')
# Sanitize to allow Prometheus Ingestion
device_name = sanitize(device_details['name'])
device_label = sanitize(device_details['label'])
device_human_label = device_details['label']
device_type = sanitize(device_details['type'])
device_id = sanitize(device_details['id'])
metric_name = sanitize(attrib['name'])
# Create the dict that holds the data
device_attributes.append({
"device_name": f"{device_name}",
"device_label": f"{device_label}",
"device_human_label": f"{device_human_label}",
"device_type": f"{device_type}",
"device_id": f"{device_id}",
"metric_name": f"{metric_name}",
"metric_value": f"{attrib['currentValue']}",
"metric_timestamp": time.time()})
Expand All @@ -88,5 +96,5 @@ def metrics():
response.mimetype = "text/plain"
return response



def sanitize(inputValue):
return re.sub('[^a-z0-9]+', '_', inputValue.lower())
2 changes: 1 addition & 1 deletion templates/base.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for device in device_details %}
{{ device["metric_name"] }}{device_name="{{device['device_name']}}"} {{ device["metric_value"] }}
{{ device["metric_name"] }}{device_name="{{device['device_name']}}",device_human_label="{{device['device_human_label']}}",device_label="{{device['device_label']}}",device_type="{{device['device_type']}}",device_id="{{device['device_id']}}"} {{ device["metric_value"] }}
{% endfor %}

0 comments on commit d9348fb

Please sign in to comment.