diff options
| author | Oleg Pykhalov <go.wigust@gmail.com> | 2024-09-19 03:46:48 +0300 |
|---|---|---|
| committer | Oleg Pykhalov <go.wigust@gmail.com> | 2024-09-19 03:53:33 +0300 |
| commit | e40ef288e23e4993091d0682b8e16a8bf6c4692a (patch) | |
| tree | 07a028bc3432ffce66c40a2d304e638cdd68c1bb /prometheus_tp_link_exporter | |
| parent | Delete ssh arguments. (diff) | |
| download | python-prometheus-ssh-exporter-disable-ssh-arguments.tar.gz | |
Collect packets metrics.HEADdisable-ssh-arguments
Diffstat (limited to 'prometheus_tp_link_exporter')
| -rw-r--r-- | prometheus_tp_link_exporter/__main__.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/prometheus_tp_link_exporter/__main__.py b/prometheus_tp_link_exporter/__main__.py index e938c46..9dd890d 100644 --- a/prometheus_tp_link_exporter/__main__.py +++ b/prometheus_tp_link_exporter/__main__.py @@ -37,6 +37,18 @@ node_network_transmit_bytes_total = Counter( ["device"], ) +node_network_receive_packets_total = Counter( + "node_network_receive_packets_total", + "Network device statistic receive_packets.", + ["device"], +) + +node_network_transmit_packets_total = Counter( + "node_network_transmit_packets_total", + "Network device statistic transmit_packets.", + ["device"], +) + def process_node_network(): """Process request.""" @@ -64,6 +76,29 @@ def process_node_network(): 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"]) + for device in devices: + if (device["name"],) in node_network_transmit_packets_total._metrics: + previos_value = node_network_transmit_packets_total._metrics[ + (device["name"],) + ]._value._value + if previos_value < device["tx_packets"]: + 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_packets_total.labels(device=device["name"]).inc( + device["tx_packets"] - previos_value + ) + else: + node_network_transmit_packets_total.labels(device=device["name"]).inc(device["tx_packets"]) + for device in devices: + if (device["name"],) in node_network_receive_packets_total._metrics: + previos_value = node_network_receive_packets_total._metrics[(device["name"],)]._value._value + if previos_value < device["rx_packets"]: + node_network_receive_packets_total.labels(device=device["name"]).inc( + device["rx_packets"] - previos_value + ) + else: + log.debug(f"Previous value {previos_value} is bigger than current value {device['rx_packets']} on device {device['name']}, skipping updating the value.") + else: + node_network_receive_packets_total.labels(device=device["name"]).inc(device["rx_packets"]) def main(): |
