Prometheus: Difference between revisions
Appearance
Additional examples |
m Shorten comments slightly (prevent line wrap) |
||
| (5 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
[https://prometheus.io/ Prometheus] is | '''[https://prometheus.io/ Prometheus]''' is an open-source event monitoring and alerting application. It records metrics in a time series database built by pulling (also known as ''scraping'') metrics from different services, with flexible queries and real-time alerting. | ||
== | {{infobox application | ||
|name=Prometheus | |||
|image=Prometheus software logo.svg | |||
|type=Metrics aggregation system | |||
|status=Active | |||
|license=Apache License 2.0 | |||
|programmingLanguage=Go | |||
|github=prometheus/prometheus | |||
|documentation=https://prometheus.io/docs/introduction/overview/ | |||
}} | |||
== | == Prometheus exporters == | ||
Prometheus works by scraping from HTTP endpoints, which are often provided by '''Prometheus exporters'''. | |||
=== <code>node_exporter</code> === | |||
Below is an example of [https://prometheus.io/docs/guides/node-exporter/ prometheus node_exporter] with additional collectors enabled. [https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters <code>node_exporter</code> is documented in the NixOS manual]. | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
{ | { | ||
# https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters | # https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters | ||
# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/monitoring/prometheus/exporters.nix | |||
services.prometheus.exporters.node = { | services.prometheus.exporters.node = { | ||
enable = true; | enable = true; | ||
port = 9000; | port = 9000; | ||
# | # For the list of available collectors, run, depending on your install: | ||
enabledCollectors = [ "systemd" ]; | # - Flake-based: nix run nixpkgs#prometheus-node-exporter -- --help | ||
# | # - Classic: nix-shell -p prometheus-node-exporter --run "node_exporter --help" | ||
extraFlags = [ "--collector. | enabledCollectors = [ | ||
"ethtool" | |||
"softirqs" | |||
"systemd" | |||
"tcpstat" | |||
"wifi" | |||
]; | |||
# You can pass extra options to the exporter using `extraFlags`, e.g. | |||
# to configure collectors or disable those enabled by default. | |||
# Enabling a collector is also possible using "--collector.[name]", | |||
# but is otherwise equivalent to using `enabledCollectors` above. | |||
extraFlags = [ "--collector.ntp.protocol-version=4" "--no-collector.mdadm" ]; | |||
}; | }; | ||
} | } | ||
</ | </nowiki>}} | ||
== | |||
The Prometheus service daemon can be enabled and configured by further options.< | == Usage == | ||
services.prometheus.enable = true; | |||
</ | The Prometheus service daemon can be enabled and configured by further options. | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ | |||
services.prometheus.enable = true; | |||
} | |||
</nowiki>}} | |||
Another example: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
{ | { | ||
| Line 32: | Line 67: | ||
globalConfig.scrape_interval = "10s"; # "1m" | globalConfig.scrape_interval = "10s"; # "1m" | ||
scrapeConfigs = [ | scrapeConfigs = [ | ||
{ | |||
job_name = "node"; | |||
static_configs = [{ | |||
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; | |||
}]; | |||
} | |||
]; | ]; | ||
}; | }; | ||
} | } | ||
</ | </nowiki>}} | ||
== See also == | |||
* [[Grafana]], the dashboarding tool often used with Prometheus. | |||
* [[Grafana Loki|Loki]], the equivalent of Prometheus for logs. | |||
[[Category:Server]] | [[Category:Server]] | ||
[[Category:NixOS Manual]] | [[Category:NixOS Manual]] | ||
Latest revision as of 16:36, 7 December 2025
Prometheus is an open-source event monitoring and alerting application. It records metrics in a time series database built by pulling (also known as scraping) metrics from different services, with flexible queries and real-time alerting.
Prometheus exporters
Prometheus works by scraping from HTTP endpoints, which are often provided by Prometheus exporters.
node_exporter
Below is an example of prometheus node_exporter with additional collectors enabled. node_exporter is documented in the NixOS manual.
❄︎ /etc/nixos/configuration.nix
{ config, pkgs, ... }:
{
# https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters
# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/monitoring/prometheus/exporters.nix
services.prometheus.exporters.node = {
enable = true;
port = 9000;
# For the list of available collectors, run, depending on your install:
# - Flake-based: nix run nixpkgs#prometheus-node-exporter -- --help
# - Classic: nix-shell -p prometheus-node-exporter --run "node_exporter --help"
enabledCollectors = [
"ethtool"
"softirqs"
"systemd"
"tcpstat"
"wifi"
];
# You can pass extra options to the exporter using `extraFlags`, e.g.
# to configure collectors or disable those enabled by default.
# Enabling a collector is also possible using "--collector.[name]",
# but is otherwise equivalent to using `enabledCollectors` above.
extraFlags = [ "--collector.ntp.protocol-version=4" "--no-collector.mdadm" ];
};
}
Usage
The Prometheus service daemon can be enabled and configured by further options.
❄︎ /etc/nixos/configuration.nix
{
services.prometheus.enable = true;
}
Another example:
❄︎ /etc/nixos/configuration.nix
{ config, pkgs, ... }:
{
# https://wiki.nixos.org/wiki/Prometheus
# https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters-configuration
# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/monitoring/prometheus/default.nix
services.prometheus = {
enable = true;
globalConfig.scrape_interval = "10s"; # "1m"
scrapeConfigs = [
{
job_name = "node";
static_configs = [{
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ];
}];
}
];
};
}