about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/ping.nix
blob: bda5038a0c64ab60547af14e079afbca264abbbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{ config, lib, pkgs, options, ... }:

with lib;

let
  cfg = config.services.prometheus.exporters.ping;

  settingsFormat = pkgs.formats.yaml {};
  configFile = settingsFormat.generate "config.yml" cfg.settings;
in
{
  port = 9427;
  extraOpts = {
    telemetryPath = mkOption {
      type = types.str;
      default = "/metrics";
      description = ''
        Path under which to expose metrics.
      '';
    };

    settings = mkOption {
      type = settingsFormat.type;
      default = {};

      description = lib.mdDoc ''
        Configuration for ping_exporter, see
        <https://github.com/czerwonk/ping_exporter>
        for supported values.
      '';
    };
  };

  serviceOpts = {
    serviceConfig = {
      # ping-exporter needs `CAP_NET_RAW` to run as non root https://github.com/czerwonk/ping_exporter#running-as-non-root-user
      CapabilityBoundingSet = [ "CAP_NET_RAW" ];
      AmbientCapabilities = [ "CAP_NET_RAW" ];
      ExecStart = ''
        ${pkgs.prometheus-ping-exporter}/bin/ping_exporter \
          --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
          --web.telemetry-path ${cfg.telemetryPath} \
          --config.path="${configFile}" \
          ${concatStringsSep " \\\n  " cfg.extraFlags}
      '';
    };
  };
}