Skip to content

Commit

Permalink
Add Smartctl-exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
peterablehmann committed Jan 30, 2025
1 parent db12d6a commit 17c7274
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
./acme.nix
./backup.nix
./boot.nix
./exporters.nix
./exporters
./fail2ban.nix
./nginx.nix
./nix.nix
Expand Down
6 changes: 6 additions & 0 deletions modules/common/exporters/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
imports = [
./node-exporter.nix
./smartctl-exporter.nix
];
}
File renamed without changes.
43 changes: 43 additions & 0 deletions modules/common/exporters/smartctl-exporter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{ pkgs
, config
, ...
}:
let
domain = "smartctl-exporter.${config.networking.fqdn}";
tls-dir = config.security.acme.certs.${domain}.directory;
webConfig = pkgs.writeTextFile {
name = "web-config.yml";
text = ''
tls_server_config:
cert_file: ${tls-dir}/fullchain.pem
key_file: ${tls-dir}/key.pem
basic_auth_users:
prometheus: $2y$10$XnqpKDYhGVLgQaKzv8Lm9.0hZagMN7UB9Q/mIDU3t4tE4nBwYXnYC
'';
};
in
{
networking.domains.subDomains.${domain} = { };
security.acme.certs."${domain}" = { };
services.nginx.virtualHosts."${domain}" = {
useACMEHost = domain;
forceSSL = true;
kTLS = true;
locations."/" = {
proxyPass = "https://${config.services.prometheus.exporters.smartctl.listenAddress}:${builtins.toString config.services.prometheus.exporters.smartctl.port }";
};
};

services.prometheus.exporters.smartctl = {
enable = true;
listenAddress = "[::1]";
port = 9633;
extraFlags = [
"--web.config.file=${webConfig}"
];
};
systemd.services.prometheus-smartctl-exporter.serviceConfig = {
SupplementaryGroups = [ config.security.acme.certs.${domain}.group ];
BindReadOnlyPaths = [ tls-dir ];
};
}
14 changes: 14 additions & 0 deletions modules/monitoring/prometheus.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
);
}];
}
{
job_name = "node-exporter";
scrape_interval = "5m";
scheme = "https";
basic_auth = {
username = "prometheus";
password_file = config.sops.secrets."prometheus/basic_auth".path;
};
static_configs = [{
targets = lib.mapAttrsToList (name: host: "smartctl-exporter.${host.config.networking.fqdn}") (
lib.filterAttrs (name: host: host.config.services.prometheus.exporters.smartctl.enable) inputs.self.nixosConfigurations
);
}];
}
{
job_name = "zfs-exporter";
scrape_interval = "30s";
Expand Down

0 comments on commit 17c7274

Please sign in to comment.