Chapter 7, Prometheus Query Language - PromQL

  1. The comparison operators are < (less than), > (greater than), == (equals), != (differs), => (greater than or equal to), and <= (less than or equal to).
  2. When the time series you want to enrich are on the right-hand side of the PromQL expression.
  3. topk already sorts its results.
  4. While the rate() function provides the per-second average rate of change over the specified interval by using the first and last values in the range scaled to fit the range window, the irate() function uses the last two values in the range for the calculation, which produces the instant rate of change.
  5. Metrics of type info have their names ending in _info and are regular gauges with one possible value, 1. This special kind of metric was designed to be a place where labels whose values might change over time are stored, such as versions (for example, exporter version, language version, and kernel version), assigned roles, or VM metadata information.
  6. The rate function expects a counter, but a sum of counters is actually a gauge, as it can go down when one of the counters resets; this would translate into seemingly random spikes when graphed, because rate would consider any decrease a counter reset, but the total sum of the other counters would be considered a huge delta between zero and the current value.
  7. When a CPU core is being used 100%, it uses 1 CPU second. Conversely, when it's idle, it will use 0 CPU seconds. This makes it easy to calculate the percentage of usage, as we can utilize the CPU seconds directly. A virtual machine might have more than one core, which means that it might use more than 1 CPU second per second. The following expression calculates how many CPU seconds per second each core was idling in the last 5 minutes:
rate(node_cpu_seconds_total{job="node",mode="idle"}[5m])

A simple way to calculate the average CPU idle seconds per second for the last five minutes is to average the value for each core:

avg without (cpu, mode) (rate(node_cpu_seconds_total{job="node",mode="idle"}[5m]))

As CPU seconds used, plus CPU seconds idle, should total 1 CPU second per second per core, to get the CPU usage, we do the following:

avg without (cpu, mode) (1 - rate(node_cpu_seconds_total{job="node",mode="idle"}[5m]))

To get a percentage, we just need to multiply by 100:

avg without (cpu, mode) (1 - rate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) * 100
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.131.72