working prometheus setup with processes

This commit is contained in:
Noah Masur 2023-07-16 01:04:52 +00:00
parent 9d4bf082c7
commit 76a7480a1d
3 changed files with 50 additions and 1 deletions

View File

@ -10,6 +10,12 @@
config.boot.zfs.package.latestCompatibleLinuxPackages; config.boot.zfs.package.latestCompatibleLinuxPackages;
boot.kernelParams = [ "nohibernate" ]; boot.kernelParams = [ "nohibernate" ];
boot.supportedFilesystems = [ "zfs" ]; boot.supportedFilesystems = [ "zfs" ];
services.prometheus.exporters.zfs.enable = true;
scrapeTargets = [
"127.0.0.1:${
builtins.toString config.services.prometheus.exporters.zfs.port
}"
];
}; };

View File

@ -11,6 +11,7 @@
config = { config = {
adminpassFile = config.secrets.nextcloud.dest; adminpassFile = config.secrets.nextcloud.dest;
extraTrustedDomains = [ config.hostnames.content ]; extraTrustedDomains = [ config.hostnames.content ];
trustedProxies = [ "127.0.0.1" ];
}; };
}; };
@ -74,6 +75,21 @@
requires = [ "phpfpm-nextcloud.service" ]; requires = [ "phpfpm-nextcloud.service" ];
}; };
# Log metrics to prometheus
services.prometheus.exporters.nextcloud = {
enable = true;
username = config.services.nextcloud.config.adminuser;
url = "http://localhost:8080";
passwordFile = config.services.nextcloud.config.adminpassFile;
};
scrapeTargets = [
"127.0.0.1:${
builtins.toString config.services.prometheus.exporters.nextcloud.port
}"
];
# Allows nextcloud-exporter to read passwordFile
users.users.nextcloud-exporter.extraGroups = [ "nextcloud" ];
}; };
} }

View File

@ -1,5 +1,11 @@
{ config, pkgs, lib, ... }: { { config, pkgs, lib, ... }: {
options.scrapeTargets = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "Prometheus scrape targets";
default = [ ];
};
config = let config = let
# If hosting Grafana, host local Prometheus and listen for inbound jobs. If # If hosting Grafana, host local Prometheus and listen for inbound jobs. If
@ -8,12 +14,33 @@
in lib.mkIf config.services.prometheus.enable { in lib.mkIf config.services.prometheus.enable {
scrapeTargets = [
"127.0.0.1:${
builtins.toString config.services.prometheus.exporters.node.port
}"
"127.0.0.1:${
builtins.toString config.services.prometheus.exporters.systemd.port
}"
"127.0.0.1:${
builtins.toString config.services.prometheus.exporters.process.port
}"
];
services.prometheus = { services.prometheus = {
exporters.node.enable = true; exporters.node.enable = true;
exporters.systemd.enable = true;
exporters.process.enable = true;
exporters.process.settings.process_names = [
# Remove nix store path from process name
{
name = "{{.Matches.Wrapped}} {{ .Matches.Args }}";
cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ];
}
];
extraFlags = lib.mkIf isServer [ "--web.enable-remote-write-receiver" ]; extraFlags = lib.mkIf isServer [ "--web.enable-remote-write-receiver" ];
scrapeConfigs = [{ scrapeConfigs = [{
job_name = config.networking.hostName; job_name = config.networking.hostName;
static_configs = [{ targets = [ "127.0.0.1:9100" ]; }]; static_configs = [{ targets = config.scrapeTargets; }];
}]; }];
webExternalUrl = webExternalUrl =
lib.mkIf isServer "https://${config.hostnames.prometheus}"; lib.mkIf isServer "https://${config.hostnames.prometheus}";