2023-03-07 15:48:46 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
psCfg = config.pub-solar;
|
|
|
|
cfg = config.pub-solar.monitoring-server;
|
|
|
|
in {
|
|
|
|
options.pub-solar.monitoring-server = {
|
|
|
|
enable = mkEnableOption "Install a monitoring server node";
|
2023-10-01 20:45:21 +00:00
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
};
|
|
|
|
grafana = {
|
|
|
|
enable = mkEnableOption "Run grafana";
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 2342;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
node_exporter = {
|
|
|
|
enable = mkEnableOption "prometheus node-exporter support";
|
|
|
|
hosts = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
snmp = {
|
|
|
|
enable = mkEnableOption "prometheus snmp export support";
|
|
|
|
hosts = mkOption {
|
|
|
|
#type = types.Or (types.AttrSet types.listOf types.str);
|
|
|
|
};
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.NullOr types.AttrSet;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
smokeping = {
|
|
|
|
enable = mkEnableOption "prometheus smokeping support";
|
|
|
|
hosts = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
};
|
2023-03-07 15:48:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-10-01 20:45:21 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [cfg.grafana.port 9001 9374];
|
2023-03-07 15:48:46 +00:00
|
|
|
|
|
|
|
pub-solar.monitoring-client = {
|
|
|
|
enable = true;
|
2023-10-01 20:45:21 +00:00
|
|
|
listenAddress = cfg.listenAddress;
|
2023-03-07 15:48:46 +00:00
|
|
|
};
|
|
|
|
|
2023-10-01 20:45:21 +00:00
|
|
|
services.grafana = mkIf cfg.grafana.enable {
|
2023-03-07 15:48:46 +00:00
|
|
|
enable = true;
|
2023-10-01 20:45:21 +00:00
|
|
|
settings = {
|
|
|
|
server = {
|
|
|
|
http_addr = cfg.listenAddress;
|
|
|
|
http_port = cfg.grafana.port;
|
|
|
|
};
|
|
|
|
};
|
2023-03-07 15:48:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.prometheus = {
|
|
|
|
enable = true;
|
2023-10-01 20:45:21 +00:00
|
|
|
listenAddress = cfg.listenAddress;
|
2023-03-07 15:48:46 +00:00
|
|
|
port = 9001;
|
|
|
|
scrapeConfigs = [
|
|
|
|
{
|
2023-10-01 20:45:21 +00:00
|
|
|
job_name = "node_exporters";
|
2023-03-07 15:48:46 +00:00
|
|
|
static_configs = [
|
|
|
|
{
|
2023-10-01 20:45:21 +00:00
|
|
|
targets =
|
|
|
|
["${cfg.listenAddress}:9002"]
|
|
|
|
++ cfg.node_exporter.hosts;
|
2023-03-07 15:48:46 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
{
|
2023-10-01 20:45:21 +00:00
|
|
|
job_name = "snmp_wohnung_aachen_mikrotik";
|
|
|
|
scrape_interval = "15s";
|
2023-03-07 15:48:46 +00:00
|
|
|
static_configs = [
|
|
|
|
{
|
2023-10-01 20:45:21 +00:00
|
|
|
targets = cfg.snmp.hosts;
|
2023-03-07 15:48:46 +00:00
|
|
|
}
|
|
|
|
];
|
2023-10-01 20:45:21 +00:00
|
|
|
metrics_path = "/snmp";
|
|
|
|
params = {
|
|
|
|
auth = ["public_v2"];
|
|
|
|
module = ["if_mib"];
|
|
|
|
};
|
|
|
|
relabel_configs = [
|
|
|
|
{
|
|
|
|
source_labels = ["__address__"];
|
|
|
|
target_label = "__param_target";
|
|
|
|
}
|
2023-03-07 15:48:46 +00:00
|
|
|
{
|
2023-10-01 20:45:21 +00:00
|
|
|
source_labels = ["__param_target"];
|
|
|
|
target_label = "instance";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
target_label = "__address__";
|
|
|
|
replacement = "10.0.1.254:9116";
|
2023-03-07 15:48:46 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
{
|
2023-10-01 20:45:21 +00:00
|
|
|
job_name = "smokeping";
|
|
|
|
scrape_interval = "15s";
|
2023-03-07 15:48:46 +00:00
|
|
|
static_configs = [
|
|
|
|
{
|
2023-10-01 20:45:21 +00:00
|
|
|
targets = [
|
|
|
|
"${cfg.listenAddress}:9374"
|
|
|
|
];
|
2023-03-07 15:48:46 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2023-10-01 20:45:21 +00:00
|
|
|
|
|
|
|
exporters.smokeping = mkIf cfg.smokeping.enable {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = cfg.listenAddress;
|
|
|
|
hosts = cfg.smokeping.hosts;
|
|
|
|
};
|
2023-03-07 15:48:46 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|