2024-07-07 15:23:28 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.bagel.monitoring.grafana-agent;
|
|
|
|
inherit (lib) mkEnableOption mkOption mkIf types;
|
|
|
|
passwordAsCredential = "\${CREDENTIALS_DIRECTORY}/password";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.bagel.monitoring.grafana-agent = {
|
|
|
|
enable = (mkEnableOption "Grafana Agent") // { default = true; };
|
|
|
|
|
|
|
|
exporters = mkOption {
|
2024-07-07 22:34:30 +00:00
|
|
|
description = ''
|
|
|
|
Set of additional exporters to scrape.
|
|
|
|
|
|
|
|
The attribute name will be used as `job_name`
|
|
|
|
internally, which ends up exported as `job` label
|
|
|
|
on all metrics of that exporter.
|
|
|
|
'';
|
|
|
|
type = types.attrsOf (types.submodule {
|
2024-07-07 15:23:28 +00:00
|
|
|
options.port = mkOption {
|
|
|
|
description = "Exporter port";
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
});
|
2024-07-07 22:34:30 +00:00
|
|
|
default = {};
|
2024-07-07 15:23:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
age.secrets.grafana-agent-password.file = ../../secrets/metrics-push-password.age;
|
|
|
|
|
|
|
|
services.grafana-agent = {
|
|
|
|
enable = true;
|
|
|
|
credentials.password = config.age.secrets.grafana-agent-password.path;
|
|
|
|
settings = {
|
|
|
|
metrics = {
|
|
|
|
global.remote_write = [
|
|
|
|
{
|
|
|
|
url = "https://mimir.forkos.org/api/v1/push";
|
|
|
|
basic_auth = {
|
|
|
|
username = "promtail";
|
|
|
|
password_file = passwordAsCredential;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2024-07-07 22:30:17 +00:00
|
|
|
global.external_labels.hostname = config.networking.hostName;
|
2024-07-07 15:23:28 +00:00
|
|
|
configs = [
|
|
|
|
{
|
|
|
|
name = config.networking.hostName;
|
2024-07-07 22:34:30 +00:00
|
|
|
scrape_configs = lib.mapAttrsToList (name: value: {
|
|
|
|
job_name = name;
|
|
|
|
static_configs = [
|
|
|
|
{ targets = "localhost:" + (toString value.port); }
|
|
|
|
];
|
|
|
|
}) config.bagel.monitoring.grafana-agent.exporters;
|
2024-07-07 15:23:28 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
logs = {
|
|
|
|
global.clients = [
|
|
|
|
{
|
|
|
|
url = "https://loki.forkos.org/loki/api/v1/push";
|
|
|
|
basic_auth = {
|
|
|
|
username = "promtail";
|
|
|
|
password_file = passwordAsCredential;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
configs = [
|
|
|
|
{
|
|
|
|
name = "journald";
|
|
|
|
scrape_configs = [
|
|
|
|
{
|
|
|
|
job_name = "system";
|
|
|
|
journal = {
|
|
|
|
max_age = "12h";
|
|
|
|
labels = {
|
|
|
|
job = "systemd-journal";
|
|
|
|
host = config.networking.hostName;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
relabel_configs = [
|
|
|
|
{
|
|
|
|
source_labels = [ "__journal__systemd_unit" ];
|
|
|
|
target_label = "unit";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
positions_directory = "\${STATE_DIRECTORY}/positions";
|
|
|
|
};
|
|
|
|
integrations.node_exporter.enable_collectors = [
|
|
|
|
"processes"
|
|
|
|
"systemd"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|