Jump to content

Prometheus

From NixOS Wiki

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

Metrics aggregation system Application

100%
StatusActive
Language(s)Go
LicenseApache License 2.0
External links
GitHubprometheus/prometheus
Documentationhttps://prometheus.io/docs/introduction/overview/

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
  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" ];
  };
}

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}" ];
        }];
      }
    ];
  };
}

See also

  • Grafana, the dashboarding tool often used with Prometheus.
  • Loki, the equivalent of Prometheus for logs.