Skip to content
Snippets Groups Projects
Commit 8b570d49 authored by Florian Sesser's avatar Florian Sesser
Browse files

Use mkIf cfg.enable pattern

Should be pure refactoring
parent e348c991
No related branches found
No related tags found
2 merge requests!264merge develop into production,!251Loki/Promtail: Towards centralized logging
Pipeline #1775 passed
...@@ -62,6 +62,8 @@ ...@@ -62,6 +62,8 @@
"172.23.23.1" = [ "monitoring" "monitoring.monitoringvpn" ]; "172.23.23.1" = [ "monitoring" "monitoring.monitoringvpn" ];
}; };
services.private-storage.monitoring.exporters.promtail.enable = true;
assertions = [ assertions = [
# This is a check to save somebody in the future trying to debug why # This is a check to save somebody in the future trying to debug why
# setting `nixpkgs.config` is not having an effect. # setting `nixpkgs.config` is not having an effect.
......
...@@ -8,7 +8,6 @@ in { ...@@ -8,7 +8,6 @@ in {
imports = [ imports = [
../../nixos/modules/monitoring/vpn/client.nix ../../nixos/modules/monitoring/vpn/client.nix
../../nixos/modules/monitoring/exporters/node.nix ../../nixos/modules/monitoring/exporters/node.nix
../../nixos/modules/monitoring/exporters/promtail.nix
]; ];
options.grid.issuer = { options.grid.issuer = {
......
...@@ -33,7 +33,6 @@ in { ...@@ -33,7 +33,6 @@ in {
../../nixos/modules/monitoring/server/loki.nix ../../nixos/modules/monitoring/server/loki.nix
../../nixos/modules/monitoring/exporters/node.nix ../../nixos/modules/monitoring/exporters/node.nix
../../nixos/modules/monitoring/exporters/blackbox.nix ../../nixos/modules/monitoring/exporters/blackbox.nix
../../nixos/modules/monitoring/exporters/promtail.nix
]; ];
options.grid.monitoring = { options.grid.monitoring = {
......
...@@ -15,8 +15,6 @@ in { ...@@ -15,8 +15,6 @@ in {
../../nixos/modules/monitoring/exporters/node.nix ../../nixos/modules/monitoring/exporters/node.nix
# Collect Tahoe OpenMetrics statistics. # Collect Tahoe OpenMetrics statistics.
../../nixos/modules/monitoring/exporters/tahoe.nix ../../nixos/modules/monitoring/exporters/tahoe.nix
# Send logs to central logging server.
../../nixos/modules/monitoring/exporters/promtail.nix
]; ];
options.grid.storage = { options.grid.storage = {
......
...@@ -12,5 +12,6 @@ ...@@ -12,5 +12,6 @@
imports = [ imports = [
./packages.nix ./packages.nix
./issuer.nix ./issuer.nix
./monitoring/exporters/promtail.nix
]; ];
} }
...@@ -6,37 +6,44 @@ ...@@ -6,37 +6,44 @@
# exporters, but it is very similar in what it is doing - # exporters, but it is very similar in what it is doing -
# preparing local data and sending it off to a TSDB. # preparing local data and sending it off to a TSDB.
{ config, ... }: { config, options, lib, ... }:
let let
cfg = config.services.private-storage.monitoring.exporters.promtail;
hostName = config.networking.hostName; hostName = config.networking.hostName;
in { in {
config.services.promtail.enable = true; options.services.private-storage.monitoring.exporters.promtail = {
config.networking.firewall.interfaces.monitoringvpn.allowedTCPPorts = [ 9080 ]; enable = lib.mkEnableOption "Promtail log exporter service";
config.services.promtail.configuration = { };
server = {
http_listen_port = 9080; # Using /metrics for health check
grpc_listen_address = "127.0.0.1"; # unused, but no option to turn it off.
grpc_listen_port = 9094; # unused, but no option to turn it off.
};
clients = [{ config = lib.mkIf cfg.enable {
url = "http://monitoring:3100/loki/api/v1/push"; services.promtail.enable = true;
}]; networking.firewall.interfaces.monitoringvpn.allowedTCPPorts = [ 9080 ];
services.promtail.configuration = {
server = {
http_listen_port = 9080; # Using /metrics for health check
grpc_listen_address = "127.0.0.1"; # unused, but no option to turn it off.
grpc_listen_port = 9094; # unused, but no option to turn it off.
};
scrape_configs = [{ clients = [{
job_name = "systemd-journal"; url = "http://monitoring:3100/loki/api/v1/push";
journal = { }];
labels = {
job = "systemd-journal"; scrape_configs = [{
host = hostName; job_name = "systemd-journal";
journal = {
labels = {
job = "systemd-journal";
host = hostName;
};
}; };
}; relabel_configs = [{
relabel_configs = [{ source_labels = [ "__journal__systemd_unit" ];
source_labels = [ "__journal__systemd_unit" ]; target_label = "unit";
target_label = "unit"; }];
}]; }];
}]; };
}; };
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment