Newer
Older
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
# Prometheus server
#
# Scope: Pull data from our cluster machines into TSDB
# See https://christine.website/blog/prometheus-grafana-loki-nixos-2020-11-20
{ config, lib, ... }:
let
exportersCfg = config.services.prometheus.exporters;
cfg = config.services.private-storage.monitoring.prometheus;
in {
options.services.private-storage.monitoring.prometheus = {
nodeExporterTargets = lib.mkOption {
type = with lib.types; listOf str;
example = lib.literalExample "[ node1 node2 ]";
description = "List of nodes (hostnames or IPs) to scrape.";
};
nginxExporterTargets = lib.mkOption {
type = with lib.types; listOf str;
example = lib.literalExample "[ node1 node2 ]";
description = "List of nodes (hostnames or IPs) to scrape.";
};
};
config = rec {
networking.firewall.allowedTCPPorts = [ services.prometheus.port ];
services.prometheus = {
enable = true;
port = 9090; # Option only in recent (20.09?) nixpkgs, 9090 default
scrapeConfigs = [
{
job_name = "node-exporters";
static_configs = [{
targets = map (x: x + ":" + (toString exportersCfg.node.port)) cfg.nodeExporterTargets;
}];
}
{
job_name = "nginx-exporters";
static_configs = [{
targets = map (x: x + ":" + (toString exportersCfg.nginx.port)) cfg.nginxExporterTargets;
}];
}
];
};
};
}