-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixos/prometheus-collectd-exporter: init module (#29212)
* prometheus-collectd-exporter service: init module Supports JSON and binary (optional) protocol of collectd. * nixos/prometheus-collectd-exporter: submodule is not needed for collectdBinary
- Loading branch information
Showing
2 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
nixos/modules/services/monitoring/prometheus/collectd-exporter.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{ config, pkgs, lib, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.prometheus.collectdExporter; | ||
|
||
collectSettingsArgs = if (cfg.collectdBinary.enable) then '' | ||
-collectd.listen-address ${optionalString (cfg.collectdBinary.listenAddress != null) cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \ | ||
-collectd.security-level ${cfg.collectdBinary.securityLevel} \ | ||
'' else ""; | ||
|
||
in { | ||
options = { | ||
services.prometheus.collectdExporter = { | ||
enable = mkEnableOption "prometheus collectd exporter"; | ||
|
||
port = mkOption { | ||
type = types.int; | ||
default = 9103; | ||
description = '' | ||
Port to listen on. | ||
This is used for scraping as well as the to receive collectd data via the write_http plugin. | ||
''; | ||
}; | ||
|
||
listenAddress = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "0.0.0.0"; | ||
description = '' | ||
Address to listen on for web interface, telemetry and collectd JSON data. | ||
''; | ||
}; | ||
|
||
collectdBinary = { | ||
enable = mkEnableOption "collectd binary protocol receiver"; | ||
|
||
authFile = mkOption { | ||
default = null; | ||
type = types.nullOr types.path; | ||
description = "File mapping user names to pre-shared keys (passwords)."; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.int; | ||
default = 25826; | ||
description = ''Network address on which to accept collectd binary network packets.''; | ||
}; | ||
|
||
listenAddress = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "0.0.0.0"; | ||
description = '' | ||
Address to listen on for binary network packets. | ||
''; | ||
}; | ||
|
||
securityLevel = mkOption { | ||
type = types.enum ["None" "Sign" "Encrypt"]; | ||
default = "None"; | ||
description = '' | ||
Minimum required security level for accepted packets. | ||
''; | ||
}; | ||
}; | ||
|
||
extraFlags = mkOption { | ||
type = types.listOf types.str; | ||
default = []; | ||
description = '' | ||
Extra commandline options when launching the collectd exporter. | ||
''; | ||
}; | ||
|
||
logFormat = mkOption { | ||
type = types.str; | ||
default = "logger:stderr"; | ||
example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true"; | ||
description = '' | ||
Set the log target and format. | ||
''; | ||
}; | ||
|
||
logLevel = mkOption { | ||
type = types.enum ["debug" "info" "warn" "error" "fatal"]; | ||
default = "info"; | ||
description = '' | ||
Only log messages with the given severity or above. | ||
''; | ||
}; | ||
|
||
openFirewall = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = '' | ||
Open port in firewall for incoming connections. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
networking.firewall.allowedTCPPorts = (optional cfg.openFirewall cfg.port) ++ | ||
(optional (cfg.openFirewall && cfg.collectdBinary.enable) cfg.collectdBinary.port); | ||
|
||
systemd.services.prometheus-collectd-exporter = { | ||
description = "Prometheus exporter for Collectd metrics"; | ||
unitConfig.Documentation = "https://github.com/prometheus/collectd_exporter"; | ||
wantedBy = [ "multi-user.target" ]; | ||
serviceConfig = { | ||
DynamicUser = true; | ||
Restart = "always"; | ||
PrivateTmp = true; | ||
WorkingDirectory = /tmp; | ||
ExecStart = '' | ||
${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \ | ||
-log.format ${cfg.logFormat} \ | ||
-log.level ${cfg.logLevel} \ | ||
-web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port} \ | ||
${collectSettingsArgs} \ | ||
${concatStringsSep " " cfg.extraFlags} | ||
''; | ||
}; | ||
}; | ||
}; | ||
} |