dotfiles/nix/base-system/modules/darwin-monitor.nix
2024-02-23 12:09:00 -05:00

129 lines
4.6 KiB
Nix

{ pkgs, lib, config, ...}:
with lib;
{
options.services.node-exporter = {
enable = mkEnableOption "Enable the prometheus node_exporter";
listen = mkOption {
description = "[host]:port to listen on for the node_exporter";
default = "localhost:9100";
defaultText = "localhost:9100";
};
};
options.services.heracles = {
enable = mkEnableOption "Enable the heracles server";
listen = mkOption {
description = "[host]:port to listen on for the heracles server";
default = "localhost:9001";
defaultText = "localhost:9001";
};
settings = mkOption {
description = "Settings for the heracles dashboards";
default = [];
defaultText = "[]";
};
};
options.services.prometheus = {
enable = lib.mkEnableOption "Enable the prometheus server";
listen = mkOption {
description = "[host]:port to listen on for the prometheus server";
default = "localhost:9000";
defaultText = "localhost:9000";
};
settings = mkOption {
description = "The yaml configuration file settings for prometheus";
default = {
scrape_configs = [
{
job_name = "node_exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
targets = [
"${config.services.node-exporter.listen}"
];
}
];
}
];
};
defaultText = ''{
scrape_configs = [
{
job_name = "nodestats";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
targets = [
"${config.services.node-exporter.listen}"
];
}
];
}
];
}'';
};
dataPath = mkOption {
description = "Storage path for the tsdb";
default = "/Users/zaphar/opt/prometheus";
defaultText = "~/opt/prometheus";
};
};
config = {
launchd.user.agents.node-exporter = mkIf config.services.node-exporter.enable {
serviceConfig = {
ProgramArguments = [
"${pkgs.prometheus-node-exporter}/bin/node_exporter"
"--web.listen-address=${config.services.node-exporter.listen}"
];
KeepAlive = true;
RunAtLoad = true;
};
};
environment.etc."prometheus.yaml" = mkIf config.services.prometheus.enable {
text = (generators.toYAML {} config.services.prometheus.settings);
};
environment.etc."heracles.yaml" = mkIf config.services.heracles.enable {
text = (generators.toYAML {} config.services.heracles.settings);
};
launchd.user.agents.heracles = mkIf config.services.heracles.enable {
serviceConfig = {
ProgramArguments = [
"${pkgs.heracles}/bin/heracles"
"--listen=${config.services.heracles.listen}"
"--config=/etc/${config.environment.etc."heracles.yaml".target}"
];
KeepAlive = true;
RunAtLoad = true;
};
};
launchd.user.agents.prometheus = mkIf config.services.prometheus.enable {
serviceConfig = {
ProgramArguments = [
"${pkgs.prometheus}/bin/prometheus"
"--web.listen-address=${config.services.prometheus.listen}"
"--config.file=/etc/${config.environment.etc."prometheus.yaml".target}"
#"--storage.tsdb.path=${config.services.prometheus.dataPath}"
];
StandardOutPath = "${config.services.prometheus.dataPath}/prometheus-out.log";
StandardErrorPath = "${config.services.prometheus.dataPath}/prometheus-err.log";
WorkingDirectory=config.services.prometheus.dataPath;
KeepAlive = true;
RunAtLoad = true;
};
};
};
}