about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/bitcoin.nix
blob: 330d541264488fbbb85e70ec973057503fc585d9 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{ config, lib, pkgs, options }:

with lib;

let
  cfg = config.services.prometheus.exporters.bitcoin;
in
{
  port = 9332;
  extraOpts = {
    rpcUser = mkOption {
      type = types.str;
      default = "bitcoinrpc";
      description = lib.mdDoc ''
        RPC user name.
      '';
    };

    rpcPasswordFile = mkOption {
      type = types.path;
      description = lib.mdDoc ''
        File containing RPC password.
      '';
    };

    rpcScheme = mkOption {
      type = types.enum [ "http" "https" ];
      default = "http";
      description = lib.mdDoc ''
        Whether to connect to bitcoind over http or https.
      '';
    };

    rpcHost = mkOption {
      type = types.str;
      default = "localhost";
      description = lib.mdDoc ''
        RPC host.
      '';
    };

    rpcPort = mkOption {
      type = types.port;
      default = 8332;
      description = lib.mdDoc ''
        RPC port number.
      '';
    };

    refreshSeconds = mkOption {
      type = types.ints.unsigned;
      default = 300;
      description = lib.mdDoc ''
        How often to ask bitcoind for metrics.
      '';
    };

    extraEnv = mkOption {
      type = types.attrsOf types.str;
      default = {};
      description = lib.mdDoc ''
        Extra environment variables for the exporter.
      '';
    };
  };
  serviceOpts = {
    script = ''
      export BITCOIN_RPC_PASSWORD=$(cat ${cfg.rpcPasswordFile})
      exec ${pkgs.prometheus-bitcoin-exporter}/bin/bitcoind-monitor.py
    '';

    environment = {
      BITCOIN_RPC_USER = cfg.rpcUser;
      BITCOIN_RPC_SCHEME = cfg.rpcScheme;
      BITCOIN_RPC_HOST = cfg.rpcHost;
      BITCOIN_RPC_PORT = toString cfg.rpcPort;
      METRICS_ADDR = cfg.listenAddress;
      METRICS_PORT = toString cfg.port;
      REFRESH_SECONDS = toString cfg.refreshSeconds;
    } // cfg.extraEnv;
  };
}