140 lines
3.3 KiB
Nix
140 lines
3.3 KiB
Nix
{
|
|
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";
|
|
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;
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
networking.firewall.allowedTCPPorts = [cfg.grafana.port 9001 9374];
|
|
|
|
pub-solar.monitoring-client = {
|
|
enable = true;
|
|
listenAddress = cfg.listenAddress;
|
|
};
|
|
|
|
services.grafana = mkIf cfg.grafana.enable {
|
|
enable = true;
|
|
settings = {
|
|
server = {
|
|
http_addr = cfg.listenAddress;
|
|
http_port = cfg.grafana.port;
|
|
};
|
|
};
|
|
};
|
|
|
|
services.prometheus = {
|
|
enable = true;
|
|
listenAddress = cfg.listenAddress;
|
|
port = 9001;
|
|
scrapeConfigs = [
|
|
{
|
|
job_name = "snmp_wohnung_aachen_mikrotik";
|
|
scrape_interval = "15s";
|
|
static_configs = [
|
|
{
|
|
targets = cfg.snmp.hosts;
|
|
}
|
|
];
|
|
metrics_path = "/snmp";
|
|
params = {
|
|
auth = ["public_v2"];
|
|
module = ["if_mib"];
|
|
};
|
|
relabel_configs = [
|
|
{
|
|
source_labels = ["__address__"];
|
|
target_label = "__param_target";
|
|
}
|
|
{
|
|
source_labels = ["__param_target"];
|
|
target_label = "instance";
|
|
}
|
|
{
|
|
target_label = "__address__";
|
|
replacement = "10.0.1.254:9116";
|
|
}
|
|
];
|
|
}
|
|
{
|
|
job_name = "node_exporters";
|
|
static_configs = [
|
|
{
|
|
targets =
|
|
["${cfg.listenAddress}:9002"]
|
|
++ cfg.node_exporter.hosts;
|
|
}
|
|
];
|
|
}
|
|
{
|
|
job_name = "wireguard";
|
|
static_configs = [
|
|
{
|
|
targets =
|
|
["${cfg.listenAddress}:9586"]
|
|
++ cfg.node_exporter.hosts;
|
|
}
|
|
];
|
|
}
|
|
{
|
|
job_name = "smokeping";
|
|
scrape_interval = "15s";
|
|
static_configs = [
|
|
{
|
|
targets = [
|
|
"${cfg.listenAddress}:9374"
|
|
];
|
|
}
|
|
];
|
|
}
|
|
];
|
|
|
|
exporters.smokeping = mkIf cfg.smokeping.enable {
|
|
enable = true;
|
|
listenAddress = cfg.listenAddress;
|
|
hosts = cfg.smokeping.hosts;
|
|
};
|
|
};
|
|
};
|
|
}
|