2
votes

Having a network transmit metric e.g. node_network_transmit_bytes_total from nodeexporter I'd like to get a difference between the transmit rate of an interface (enp3s0 in my case) and a sum of all bridge interface transmit rates.

I have something like this:

irate(node_network_transmit_bytes_total{device="enp3s0"}[1m]) -  irate(node_network_transmit_bytes_total{device=~"br.*"}[1m])

but this gives me no datapoints.

EDIT

I've tried what Prometheus/PromQL subtract two gauge metrics suggests but my case is a bit different because on the right hand side I have more than 1 series.

So this:

node_network_transmit_bytes_total{device="enp3s0"} - ignoring(device) node_network_transmit_bytes_total{device=~"br.*"}

yields:

Error executing query: found duplicate series for the match group {instance="192.168.X.Z:9100", job="nodeexporter"} on the right hand-side of the operation: [{name="node_network_transmit_bytes_total", device="br-XXXX", instance="192.168.X.Z:9100", job="nodeexporter"}, {name="node_network_transmit_bytes_total", device="br-5d6dce95c2b0", instance="192.168.X.Z:9100", job="nodeexporter"}];many-to-many matching not allowed: matching labels must be unique on one side

I've tried using sum():

node_network_transmit_bytes_total{device="enp3s0"} - ignoring(device) sum(node_network_transmit_bytes_total{device=~"br.*"})

but that yields no results again.

EDIT2

I've managed to figure out how to get a difference by

sum(node_network_transmit_bytes_total{device="enp3s0"}) by (instance) - sum (node_network_transmit_bytes_total{device=~"br.*"}) by (instance)

but I cannot use irate on it:

irate(sum(node_network_transmit_bytes_total{device="enp3s0"}) by (instance) - sum (node_network_transmit_bytes_total{device=~"br.*"}) by (instance))[5m]

Error executing query: 1:149: parse error: ranges only allowed for vector selectors

1
Does this answer your question? Prometheus/PromQL subtract two gauge metricsMichael Doubez
@MichaelDoubez The case I have is a bit different. Please check my edit.Patryk

1 Answers

2
votes

OK it seems this was the solution:

(sum(irate(node_network_receive_bytes_total{device="enp3s0"}[1m])) by (instance))
 -
(sum(irate(node_network_receive_bytes_total{device=~"br.*"}[1m])) by (instance))