blob: 3c8cc16757ffac454f519beefea0f0c739dbb114 (
plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
{ config, lib, pkgs, ... }:
let
cfg = config.orbekk.monitoring-server;
aliases = import ../data/aliases.nix;
in
{
options = {
orbekk.monitoring-server = {
enable = lib.mkEnableOption "Enable monitoring server";
grafana-port = lib.mkOption {
type = lib.types.int;
default = aliases.services.grafana.port;
};
textFileDir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/prometheus-node-exporter-text-files";
};
grafana-domain = lib.mkOption {
type = lib.types.str;
default = "grafana.orbekk.com";
};
prometheus-port = lib.mkOption {
type = lib.types.int;
default = aliases.services.prometheus.port;
};
prometheus-exporter-port = lib.mkOption {
type = lib.types.int;
default = aliases.services.prometheus-exporter.port;
};
prometheus-snmp-exporter-port = lib.mkOption {
type = lib.types.int;
default = aliases.services.prometheus-snmp-exporter.port;
};
prometheus-pms7003-exporter = lib.mkOption {
type = lib.types.str;
default = with aliases.services.prometheus-pms7003-exporter;
"${host}:${toString port}";
};
snmp-targets = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ aliases.ip.ap2 ];
};
};
};
config = lib.mkIf cfg.enable {
services.grafana = {
enable = true;
settings = {
smtp = lib.mkIf config.orbekk.postfix.enable {
enable = true;
host = "localhost:25";
fromAddress = "root@orbekk.com";
};
server.root_url = "https://grafana.orbekk.com/";
server.domain = cfg.grafana-domain;
server.http_port = cfg.grafana-port;
server.http_addr = "127.0.0.1";
};
provision = {
enable = true;
datasources.settings.datasources = [
{
name = "Prometheus";
type = "prometheus";
access = "proxy";
orgId = 1;
editable = false;
url = "http://127.0.0.1:${toString cfg.prometheus-port}";
isDefault = true;
}
];
};
};
services.prometheus = {
enable = true;
port = cfg.prometheus-port;
retentionTime = "730d";
scrapeConfigs = [
{
job_name = "self";
static_configs = [
{ targets = ["127.0.0.1:${toString cfg.prometheus-exporter-port}"]; }
];
}
];
exporters = {
node = {
enable = true;
enabledCollectors = [ "systemd" ];
port = cfg.prometheus-exporter-port;
extraFlags = ["--collector.textfile.directory=${cfg.textFileDir}"];
};
};
};
system.activationScripts.node-exporter-directory.text =
''
# Needed for Prometheus node exporter.
mkdir -pm 0775 ${cfg.textFileDir}
'';
services.nginx.virtualHosts.${cfg.grafana-domain} = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.grafana-port}";
proxyWebsockets = true;
};
};
};
}
|