Merge pull request #98025 from Mic92/telegraf
This commit is contained in:
commit
e2289a5f18
@ -5,14 +5,8 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.services.telegraf;
|
cfg = config.services.telegraf;
|
||||||
|
|
||||||
configFile = pkgs.runCommand "config.toml" {
|
settingsFormat = pkgs.formats.toml {};
|
||||||
buildInputs = [ pkgs.remarshal ];
|
configFile = settingsFormat.generate "config.toml" cfg.extraConfig;
|
||||||
preferLocalBuild = true;
|
|
||||||
} ''
|
|
||||||
remarshal -if json -of toml \
|
|
||||||
< ${pkgs.writeText "config.json" (builtins.toJSON cfg.extraConfig)} \
|
|
||||||
> $out
|
|
||||||
'';
|
|
||||||
in {
|
in {
|
||||||
###### interface
|
###### interface
|
||||||
options = {
|
options = {
|
||||||
@ -26,10 +20,23 @@ in {
|
|||||||
type = types.package;
|
type = types.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
environmentFiles = mkOption {
|
||||||
|
type = types.nullOr (types.listOf types.path);
|
||||||
|
default = [];
|
||||||
|
example = "/run/keys/telegraf.env";
|
||||||
|
description = ''
|
||||||
|
File to load as environment file. Environment variables
|
||||||
|
from this file will be interpolated into the config file
|
||||||
|
using envsubst with this syntax:
|
||||||
|
<literal>$ENVIRONMENT ''${VARIABLE}</literal>
|
||||||
|
This is useful to avoid putting secrets into the nix store.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
extraConfig = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
description = "Extra configuration options for telegraf";
|
description = "Extra configuration options for telegraf";
|
||||||
type = types.attrs;
|
type = settingsFormat.type;
|
||||||
example = {
|
example = {
|
||||||
outputs = {
|
outputs = {
|
||||||
influxdb = {
|
influxdb = {
|
||||||
@ -51,15 +58,28 @@ in {
|
|||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
config = mkIf config.services.telegraf.enable {
|
config = mkIf config.services.telegraf.enable {
|
||||||
systemd.services.telegraf = {
|
systemd.services.telegraf = let
|
||||||
|
finalConfigFile = if config.services.telegraf.environmentFiles == []
|
||||||
|
then configFile
|
||||||
|
else "/var/run/telegraf/config.toml";
|
||||||
|
in {
|
||||||
description = "Telegraf Agent";
|
description = "Telegraf Agent";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart=''${cfg.package}/bin/telegraf -config "${configFile}"'';
|
EnvironmentFile = config.services.telegraf.environmentFiles;
|
||||||
|
ExecStartPre = lib.optional (config.services.telegraf.environmentFiles != [])
|
||||||
|
(pkgs.writeShellScript "pre-start" ''
|
||||||
|
umask 077
|
||||||
|
${pkgs.envsubst}/bin/envsubst -i "${configFile}" > /var/run/telegraf/config.toml
|
||||||
|
'');
|
||||||
|
ExecStart=''${cfg.package}/bin/telegraf -config ${finalConfigFile}'';
|
||||||
ExecReload="${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
ExecReload="${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
|
RuntimeDirectory = "telegraf";
|
||||||
User = "telegraf";
|
User = "telegraf";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
|
# for ping probes
|
||||||
|
AmbientCapabilities = [ "CAP_NET_RAW" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,12 +6,15 @@ import ./make-test-python.nix ({ pkgs, ...} : {
|
|||||||
|
|
||||||
machine = { ... }: {
|
machine = { ... }: {
|
||||||
services.telegraf.enable = true;
|
services.telegraf.enable = true;
|
||||||
|
services.telegraf.environmentFiles = [pkgs.writeText "secrets" ''
|
||||||
|
SECRET=example
|
||||||
|
''];
|
||||||
services.telegraf.extraConfig = {
|
services.telegraf.extraConfig = {
|
||||||
agent.interval = "1s";
|
agent.interval = "1s";
|
||||||
agent.flush_interval = "1s";
|
agent.flush_interval = "1s";
|
||||||
inputs.exec = {
|
inputs.exec = {
|
||||||
commands = [
|
commands = [
|
||||||
"${pkgs.runtimeShell} -c 'echo example,tag=a i=42i'"
|
"${pkgs.runtimeShell} -c 'echo $SECRET,tag=a i=42i'"
|
||||||
];
|
];
|
||||||
timeout = "5s";
|
timeout = "5s";
|
||||||
data_format = "influx";
|
data_format = "influx";
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
buildGoModule rec {
|
buildGoModule rec {
|
||||||
pname = "telegraf";
|
pname = "telegraf";
|
||||||
version = "1.15.2";
|
version = "1.16.2";
|
||||||
|
|
||||||
excludedPackages = "test";
|
excludedPackages = "test";
|
||||||
|
|
||||||
@ -12,19 +12,10 @@ buildGoModule rec {
|
|||||||
owner = "influxdata";
|
owner = "influxdata";
|
||||||
repo = "telegraf";
|
repo = "telegraf";
|
||||||
rev = "v${version}";
|
rev = "v${version}";
|
||||||
sha256 = "045wjpq29dr0s48ns3a4p8pw1j0ssfcw6m91iim4pkrppj7bm2di";
|
sha256 = "sha256-XdlXUwGn2isGn7SqCGaAjntposBEd6WbbdfN6dEycDI=";
|
||||||
};
|
};
|
||||||
|
|
||||||
patches = [
|
vendorSha256 = "02fqx817w6f9grfc69ri06a6qygbr5chan6w9waq2y0mxvmypz28";
|
||||||
# https://github.com/influxdata/telegraf/pull/7988
|
|
||||||
# fix broken cgo vendoring
|
|
||||||
(fetchpatch {
|
|
||||||
url = "https://github.com/influxdata/telegraf/commit/63e1f41d8ff246d191d008ff7f69d69cc34b4fae.patch";
|
|
||||||
sha256 = "0ikifc4414bid3g6hhxz18cw71z63s5g805klx98vrndjlpbqkzw";
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
vendorSha256 = "0f95xigpkindd7dmci8kqpqq5dlirimbqh8ai73142asbrd5h4yr";
|
|
||||||
|
|
||||||
buildFlagsArray = [ ''-ldflags=
|
buildFlagsArray = [ ''-ldflags=
|
||||||
-w -s -X main.version=${version}
|
-w -s -X main.version=${version}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user