Home Explore Blog Models CI



nixpkgs

2nd chunk of `nixos/modules/services/monitoring/prometheus/exporters.md`
e291d95b575e073ccc288c3a0ed354c70c1d35354c193eed00000001000007fe
    `nixpkgs/nixos/modules/services/monitoring/prometheus/exporters.nix`:

      - `enable`
      - `port`
      - `listenAddress`
      - `extraFlags`
      - `openFirewall`
      - `firewallFilter`
      - `firewallRules`
      - `user`
      - `group`
  - As there is already a package available, the module can now be added. This
    is accomplished by adding a new file to the
    `nixos/modules/services/monitoring/prometheus/exporters/`
    directory, which will be called postfix.nix and contains all exporter
    specific options and configuration:
    ```nix
    # nixpkgs/nixos/modules/services/prometheus/exporters/postfix.nix
    {
      config,
      lib,
      pkgs,
      options,
    }:
    let
      # for convenience we define cfg here
      cfg = config.services.prometheus.exporters.postfix;
    in
    {
      port = 9154; # The postfix exporter listens on this port by default

      # `extraOpts` is an attribute set which contains additional options
      # (and optional overrides for default options).
      # Note that this attribute is optional.
      extraOpts = {
        telemetryPath = lib.mkOption {
          type = lib.types.str;
          default = "/metrics";
          description = ''
            Path under which to expose metrics.
          '';
        };
        logfilePath = lib.mkOption {
          type = lib.types.path;
          default = /var/log/postfix_exporter_input.log;
          example = /var/log/mail.log;
          description = ''
            Path where Postfix writes log entries.
            This file will be truncated by this exporter!
          '';
        };
        showqPath = lib.mkOption {
          type = lib.types.path;
          default = /var/spool/postfix/public/showq;
          example = /var/lib/postfix/queue/public/showq;
          description = ''
            Path at which Postfix places its showq socket.
          '';
        };
      };

      # `serviceOpts` is an attribute set which contains configuration
      # for the exporter's systemd service. One of

Title: Defining Custom Prometheus Exporter Modules
Summary
This document details how to define a new Prometheus exporter module within the NixOS framework, building on common default options (e.g., `enable`, `port`, `listenAddress`, `openFirewall`). Using the `postfix.nix` module as an example, it illustrates the process of adding exporter-specific configurations through an `extraOpts` attribute set. This includes defining custom options like `telemetryPath`, `logfilePath`, and `showqPath`, along with their data types, default values, and descriptions. It also mentions the `serviceOpts` attribute for configuring the exporter's systemd service.