1{ config, lib, pkgs, options }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.bitcoin;
7in
8{
9 port = 9332;
10 extraOpts = {
11 rpcUser = mkOption {
12 type = types.str;
13 default = "bitcoinrpc";
14 description = lib.mdDoc ''
15 RPC user name.
16 '';
17 };
18
19 rpcPasswordFile = mkOption {
20 type = types.path;
21 description = lib.mdDoc ''
22 File containing RPC password.
23 '';
24 };
25
26 rpcScheme = mkOption {
27 type = types.enum [ "http" "https" ];
28 default = "http";
29 description = lib.mdDoc ''
30 Whether to connect to bitcoind over http or https.
31 '';
32 };
33
34 rpcHost = mkOption {
35 type = types.str;
36 default = "localhost";
37 description = lib.mdDoc ''
38 RPC host.
39 '';
40 };
41
42 rpcPort = mkOption {
43 type = types.port;
44 default = 8332;
45 description = lib.mdDoc ''
46 RPC port number.
47 '';
48 };
49
50 refreshSeconds = mkOption {
51 type = types.ints.unsigned;
52 default = 300;
53 description = lib.mdDoc ''
54 How often to ask bitcoind for metrics.
55 '';
56 };
57
58 extraEnv = mkOption {
59 type = types.attrsOf types.str;
60 default = {};
61 description = lib.mdDoc ''
62 Extra environment variables for the exporter.
63 '';
64 };
65 };
66 serviceOpts = {
67 script = ''
68 export BITCOIN_RPC_PASSWORD=$(cat ${cfg.rpcPasswordFile})
69 exec ${pkgs.prometheus-bitcoin-exporter}/bin/bitcoind-monitor.py
70 '';
71
72 environment = {
73 BITCOIN_RPC_USER = cfg.rpcUser;
74 BITCOIN_RPC_SCHEME = cfg.rpcScheme;
75 BITCOIN_RPC_HOST = cfg.rpcHost;
76 BITCOIN_RPC_PORT = toString cfg.rpcPort;
77 METRICS_ADDR = cfg.listenAddress;
78 METRICS_PORT = toString cfg.port;
79 REFRESH_SECONDS = toString cfg.refreshSeconds;
80 } // cfg.extraEnv;
81 };
82}