Prometheus: Difference between revisions

From NixOS Wiki
Klinger (talk | contribs)
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>



Latest revision as of 20:59, 5 June 2024

Prometheus is a free software application used for event monitoring and alerting. It records metrics in a time series database built using an HTTP pull model, with flexible queries and real-time alerting.

Client/Agent: Prometheus exporter

It is documented in the NixOS manual.

Client example

Example of prometheus node_exporter with additional collectors enabled:

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

Server

The Prometheus service daemon can be enabled and configured by further options.

services.prometheus.enable = true;

Another example:

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