operations
# reload prometheus configuration
curl -X POST localhost:9090/-/reload
# validate prometheus config
promtool check config /etc/prometheus/prometheus.yaml
# validate prometheus rules
promtool check rules /etc/prometheus/rules/*
# lint prometheus rules
pint lint /etc/prometheus/rules/*
# reset prometheus data
systemctl stop prometheus.service
rm -r /var/lib/prometheus/*
systemctl start prometheus.service
# reload alertmanager configuration
curl -X POST localhost:9093/-/reload
# validate alertmanager config
amtool check-config /etc/alertmanager/alertmanager.yaml
# retrieve all active alerts
curl http://localhost:9093/api/v2/alerts | jq
amtool alert --alertmanager.url="http://127.0.0.1:9093"
amtool alert -o extended --alertmanager.url="http://127.0.0.1:9093"
# get current epoch time
date +%s.%3N
# get past epoch time - "YYYY-MM-DD HH:MM:SS"
date -d "2025-04-04 22:00:00" +%s.%3N
metrics
# get the values of a metric for all labels for the past 1 minute
node_network_receive_bytes_total[1m]
# get the values of a metric for a specific label for the past 1 minute
node_network_receive_bytes_total{device="enp2s0"}[1m]
# get the values of a metric for the past 1 minute from a specific date and time
node_network_receive_bytes_total{device="enp2s0"}[1m] @ 1743794220.651
# get all the metrics and their current values
{__name__=~".+"}
# get all the metrics and their values for the past 1 minute
{__name__=~".+"}[1m]
# get all the metrics and their values for the past 5 minutes with an 1 minute interval
{__name__=~".+"}[5m:1m]
# get all the metrics that have a specific label and value
{__name__=~".+",device="enp2s0"}
counters
node_network_receive_bytes_total{device="enp2s0"}[1m] @ 1743794220.651
4928424771 @ 1743794174.203
4928427753 @ 1743794189.204
4928428500 @ 1743794204.204
4928430018 @ 1743794219.204
rate()
- uses all samples in the range vector
- calculates the difference between the last and first sample
- divides the difference by the elapsed time between those samples
- handles counter resets
- extrapolates the result to the range boundaries
- returns the average per-second increase
(last_value - first_value) / (last_timestamp - first_timestamp)
(4928430018 - 4928424771) / (1743794219.204 - 1743794174.203)
5247 / 45.001
116.59740895
increase()
- uses all samples in the range vector
- calculates the total counter increase
- handles counter resets
- extrapolates the result to the range boundaries
- effectively calculates rate() * range_vector_duration
- returns the estimated total increase over the requested range
(last_value - first_value) / (last_timestamp - first_timestamp) * range_vector
(4928430018 - 4928424771) / (1743794219.204 - 1743794174.203) * 60
5247 / 45.001 * 60
116.59740895 * 60
6995.84453679
irate()
- uses only the last two samples in the range vector
- calculates the difference between those two samples
- divides the difference by the elapsed time between them
- handles counter resets
- does not extrapolate to the range boundaries
- returns the instantaneous per-second increase based on the last two samples
(last_value - value_before_last_value) / (last_timestamp - timestamp_before_last_timestamp)
(4928430018 - 4928428500) / (1743794219.204 - 1743794204.204)
1518 / 15
101.2