diff options
| -rw-r--r-- | prometheus_tp_link_exporter/__main__.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/prometheus_tp_link_exporter/__main__.py b/prometheus_tp_link_exporter/__main__.py index 06a5bd2..1761079 100644 --- a/prometheus_tp_link_exporter/__main__.py +++ b/prometheus_tp_link_exporter/__main__.py @@ -2,10 +2,12 @@ from prometheus_client import Counter, start_http_server import jc.parsers.ifconfig +import logging import os import subprocess import time +log = logging.getLogger("prometheus-tp-link-exporter") host = os.getenv("PROMETHEUS_TP_LINK_EXPORTER_HOST", "") password = os.getenv("PROMETHEUS_TP_LINK_EXPORTER_PASSWORD", "") interval = int(os.getenv("PROMETHEUS_TP_LINK_EXPORTER_INTERVAL", "10")) @@ -44,7 +46,8 @@ def process_node_network(): previos_value = node_network_transmit_bytes_total._metrics[ (device["name"],) ]._value._value - if previos_value <= device["tx_bytes"]: + if previos_value < device["tx_bytes"]: + log.debug(f"Previous value {previos_value} is bigger than current value {device['rx_bytes']} on device {device['name']}, skipping updating the value.") node_network_transmit_bytes_total.labels(device=device["name"]).inc( device["tx_bytes"] - previos_value ) @@ -53,10 +56,12 @@ def process_node_network(): for device in devices: if (device["name"],) in node_network_receive_bytes_total._metrics: previos_value = node_network_receive_bytes_total._metrics[(device["name"],)]._value._value - if previos_value <= device["rx_bytes"]: + if previos_value < device["rx_bytes"]: node_network_receive_bytes_total.labels(device=device["name"]).inc( device["rx_bytes"] - previos_value ) + else: + log.debug(f"Previous value {previos_value} is bigger than current value {device['rx_bytes']} on device {device['name']}, skipping updating the value.") else: node_network_receive_bytes_total.labels(device=device["name"]).inc(device["rx_bytes"]) |
