aboutsummaryrefslogtreecommitdiffstats
path: root/modules/by-name/mo/monitoring/components/prometheus.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/by-name/mo/monitoring/components/prometheus.nix192
1 files changed, 192 insertions, 0 deletions
diff --git a/modules/by-name/mo/monitoring/components/prometheus.nix b/modules/by-name/mo/monitoring/components/prometheus.nix
new file mode 100644
index 0000000..468ece3
--- /dev/null
+++ b/modules/by-name/mo/monitoring/components/prometheus.nix
@@ -0,0 +1,192 @@
+{
+ lib,
+ config,
+ nixLib,
+ ...
+}: let
+ cfg = config.vhack.monitoring.prometheus;
+
+ commonLabels = {
+ hostname = config.networking.hostName;
+ inherit (config.vhack.monitoring.grafana) fqdn;
+ };
+
+ prom_cfg = config.services.prometheus;
+in {
+ options.vhack.monitoring.prometheus = {
+ enable = lib.mkEnableOption "prometheus";
+
+ port = lib.mkOption {
+ type = lib.types.port;
+ description = "Port where Prometheus listens to HTTP requests.";
+ default = 3001;
+ };
+
+ sources = lib.mkOption {
+ type = lib.types.listOf (lib.types.submodule {
+ options = {
+ name = lib.mkOption {
+ type = lib.types.str;
+ };
+ target = lib.mkOption {
+ type = lib.types.str;
+ };
+ extra = lib.mkOption {
+ type = lib.types.attrsOf lib.types.anything;
+ };
+ };
+ });
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ vhack = {
+ nginx.enable = true;
+ monitoring.prometheus.sources = [
+ {
+ name = "node";
+ target = "127.0.0.1:${toString prom_cfg.exporters.node.port}";
+ }
+ {
+ name = "smartctl";
+ target = "127.0.0.1:${toString prom_cfg.exporters.smartctl.port}";
+ }
+ {
+ name = "prometheus_internal";
+ target = "127.0.0.1:${toString prom_cfg.port}";
+ }
+ {
+ name = "systemd";
+ target = "127.0.0.1:${toString prom_cfg.exporters.systemd.port}";
+ }
+ {
+ name = "netdata";
+ target = "127.0.0.1:19999";
+ extra = {
+ metrics_path = "/api/v1/allmetrics";
+ params.format = ["prometheus"];
+ honor_labels = true;
+ };
+ }
+ ];
+ };
+
+ services = {
+ prometheus = {
+ enable = true;
+ inherit (cfg) port;
+
+ globalConfig = {
+ scrape_interval = "15s";
+ };
+
+ scrapeConfigs = builtins.map (attr:
+ nixLib.warnMerge {
+ job_name = attr.name;
+ static_configs = [
+ {
+ targets = [attr.target];
+ labels = commonLabels;
+ }
+ ];
+ }
+ attr.extra "prometheus scrapeConfig")
+ cfg.sources;
+ # ++ (lib.optional (builtins.length (lib.attrNames config.services.redis.servers) > 0) {
+ # job_name = "redis";
+ # static_configs = [
+ # {
+ # targets = ["127.0.0.1:${toString config.services.prometheus.exporters.redis.port}"];
+ # }
+ # ];
+ # }) ++ (lib.optional (builtins.length (lib.attrNames config.services.openvpn.servers) > 0) {
+ # job_name = "openvpn";
+ # static_configs = [
+ # {
+ # targets = ["127.0.0.1:${toString config.services.prometheus.exporters.openvpn.port}"];
+ # }
+ # ];
+ # })
+ # ++ (lib.optional config.services.dnsmasq.enable {
+ # job_name = "dnsmasq";
+ # static_configs = [
+ # {
+ # targets = ["127.0.0.1:${toString config.services.prometheus.exporters.dnsmasq.port}"];
+ # labels = commonLabels;
+ # }
+ # ];
+ # });
+
+ exporters = {
+ node = {
+ enable = true;
+ # https://github.com/prometheus/node_exporter#collectors
+ enabledCollectors = [
+ "arp"
+ "cpu"
+ "cpufreq"
+ "diskstats"
+ "dmi"
+ "edac"
+ "entropy"
+ "filefd"
+ "filesystem"
+ "hwmon"
+ "loadavg"
+ "meminfo"
+ "netclass"
+ "netdev"
+ "netstat"
+ "nvme"
+ "os"
+ "pressure"
+ "rapl"
+ "schedstat"
+ "stat"
+ "thermal_zone"
+ "time"
+ "uname"
+ "vmstat"
+ "zfs"
+
+ # Disabled by default
+ "cgroups"
+ "drm"
+ "ethtool"
+ "logind"
+ "wifi"
+ ];
+ port = 9112;
+ listenAddress = "127.0.0.1";
+ };
+ smartctl = {
+ enable = true;
+ port = 9115;
+ listenAddress = "127.0.0.1";
+ };
+ # services.prometheus.exporters.redis = lib.mkIf (builtins.length (lib.attrNames config.services.redis.servers) > 0) {
+ # enable = true;
+ # port = 9119;
+ # listenAddress = "127.0.0.1";
+ # };
+ # services.prometheus.exporters.openvpn = lib.mkIf (builtins.length (lib.attrNames config.services.openvpn.servers) > 0) {
+ # enable = true;
+ # port = 9121;
+ # listenAddress = "127.0.0.1";
+ # statusPaths = lib.mapAttrsToList (name: _config: "/tmp/openvpn/${name}.status") config.services.openvpn.servers;
+ # };
+ # dnsmasq = lib.mkIf config.services.dnsmasq.enable {
+ # enable = true;
+ # port = 9211;
+ # listenAddress = "127.0.0.1";
+ # };
+ systemd = {
+ enable = true;
+ port = 9116;
+ listenAddress = "127.0.0.1";
+ };
+ };
+ };
+ };
+ };
+}