Prometheus: Difference between revisions
first version with link to manual |
Additional examples |
||
Line 4: | Line 4: | ||
It is documented in the [https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters NixOS manual]. | It is documented in the [https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters NixOS manual]. | ||
== Client example == | |||
Example of [https://prometheus.io/docs/guides/node-exporter/ prometheus node_exporter] with additional collectors enabled:<syntaxhighlight lang="nix"> | |||
{ config, pkgs, ... }: | |||
{ | |||
# https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters | |||
services.prometheus.exporters.node = { | |||
enable = true; | |||
port = 9000; | |||
# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/monitoring/prometheus/exporters.nix | |||
enabledCollectors = [ "systemd" ]; | |||
# /nix/store/zgsw0yx18v10xa58psanfabmg95nl2bb-node_exporter-1.8.1/bin/node_exporter --help | |||
extraFlags = [ "--collector.ethtool" "--collector.softirqs" "--collector.tcpstat" "--collector.wifi" ]; | |||
}; | |||
} | |||
</syntaxhighlight> | |||
== Server == | == Server == | ||
The Prometheus service daemon can be enabled and configured by further options.<syntaxhighlight lang="nix"> | The Prometheus service daemon can be enabled and configured by further options.<syntaxhighlight lang="nix"> | ||
services.prometheus.enable = true; | services.prometheus.enable = true; | ||
</syntaxhighlight>Another example:<syntaxhighlight lang="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}" ]; | |||
}]; | |||
} | |||
]; | |||
}; | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||