diff options
| author | Oleg Pykhalov <go.wigust@gmail.com> | 2022-02-06 20:43:53 +0300 |
|---|---|---|
| committer | Oleg Pykhalov <go.wigust@gmail.com> | 2022-02-06 20:56:06 +0300 |
| commit | 15a2132472f8c6592ea5ec77ea62a74f4f69e542 (patch) | |
| tree | 365ff14deff842bc95491dc8fbf05b6ce804c651 | |
| parent | Add PROMETHEUS_TP_LINK_EXPORTER_LISTEN_ADDRESS environment variable. (diff) | |
| download | python-prometheus-ssh-exporter-15a2132472f8c6592ea5ec77ea62a74f4f69e542.tar.gz | |
Fix negative numbers error.v1.1.1
This patch fixes the error:
Traceback (most recent call last):
File "/gnu/store/...-prometheus-tp-link-exporter-1.0.0/bin/.prometheus-tp-link-exporter-real", line 33, in <module>
sys.exit(load_entry_point('prometheus-tp-link-exporter==1.0.0', 'console_scripts', 'prometheus-tp-link-exporter')())
File "/gnu/store/...-prometheus-tp-link-exporter-1.0.0/lib/python3.9/site-packages/prometheus_tp_link_exporter/__main__.py", line 63, in main
process_node_network_transmit_bytes_total()
File "/gnu/store/...-prometheus-tp-link-exporter-1.0.0/lib/python3.9/site-packages/prometheus_tp_link_exporter/__main__.py", line 50, in process_node_network_transmit_bytes_total
node_network_transmit_bytes_total.labels(device=device["name"]).inc(
File "/gnu/store/...-python-prometheus-client-0.7.1/lib/python3.9/site-packages/prometheus_client/metrics.py", line 243, in inc
raise ValueError('Counters can only be incremented by non-negative amounts.')
ValueError: Counters can only be incremented by non-negative amounts.
Traceback (most recent call last):
File "/gnu/store/...-prometheus-tp-link-exporter-1.1.0/bin/.prometheus-tp-link-exporter-real", line 33, in <module>
sys.exit(load_entry_point('prometheus-tp-link-exporter==1.0.0', 'console_scripts', 'prometheus-tp-link-exporter')())
File "/gnu/store/...-prometheus-tp-link-exporter-1.1.0/lib/python3.9/site-packages/prometheus_tp_link_exporter/__main__.py", line 66, in main
process_node_network_receive_bytes_total()
File "/gnu/store/...-prometheus-tp-link-exporter-1.1.0/lib/python3.9/site-packages/prometheus_tp_link_exporter/__main__.py", line 36, in process_node_network_receive_bytes_total
node_network_receive_bytes_total.labels(device=device["name"]).inc(
File "/gnu/store/...-python-prometheus-client-0.7.1/lib/python3.9/site-packages/prometheus_client/metrics.py", line 243, in inc
raise ValueError('Counters can only be incremented by non-negative amounts.')
ValueError: Counters can only be incremented by non-negative amounts.
| -rw-r--r-- | prometheus_tp_link_exporter/__main__.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/prometheus_tp_link_exporter/__main__.py b/prometheus_tp_link_exporter/__main__.py index 27472d0..049578b 100644 --- a/prometheus_tp_link_exporter/__main__.py +++ b/prometheus_tp_link_exporter/__main__.py @@ -33,10 +33,14 @@ node_network_receive_bytes_total = Counter( def process_node_network_receive_bytes_total(): """Process request.""" for device in ifconfig_devices(): - node_network_receive_bytes_total.labels(device=device["name"]).inc( - device["rx_bytes"] - - node_network_receive_bytes_total._metrics[(device["name"],)]._value._value - ) + 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"]: + node_network_receive_bytes_total.labels(device=device["name"]).inc( + device["rx_bytes"] - previos_value + ) + else: + node_network_receive_bytes_total.labels(device=device["name"]).inc(device["rx_bytes"]) node_network_transmit_bytes_total = Counter( @@ -49,12 +53,16 @@ node_network_transmit_bytes_total = Counter( def process_node_network_transmit_bytes_total(): """Process request.""" for device in ifconfig_devices(): - node_network_transmit_bytes_total.labels(device=device["name"]).inc( - device["tx_bytes"] - - node_network_transmit_bytes_total._metrics[ + if (device["name"],) in node_network_transmit_bytes_total._metrics: + previos_value = node_network_transmit_bytes_total._metrics[ (device["name"],) ]._value._value - ) + if previos_value < device["tx_bytes"]: + node_network_transmit_bytes_total.labels(device=device["name"]).inc( + device["tx_bytes"] - previos_value + ) + else: + node_network_transmit_bytes_total.labels(device=device["name"]).inc(device["tx_bytes"]) def main(): |
