Skip to content
Merged

Telegraf #18437

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nixos/modules/misc/ids.nix
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
terraria = 253;
mattermost = 254;
prometheus = 255;
telegraf = 256;

# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!

Expand Down Expand Up @@ -520,6 +521,7 @@
terraria = 253;
mattermost = 254;
prometheus = 255;
#telegraf = 256; # unused

# When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
./services/monitoring/statsd.nix
./services/monitoring/systemhealth.nix
./services/monitoring/teamviewer.nix
./services/monitoring/telegraf.nix
./services/monitoring/ups.nix
./services/monitoring/uptime.nix
./services/monitoring/zabbix-agent.nix
Expand Down
71 changes: 71 additions & 0 deletions nixos/modules/services/monitoring/telegraf.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.telegraf;

configFile = pkgs.runCommand "config.toml" {
buildInputs = [ pkgs.remarshal ];
} ''
remarshal -if json -of toml \
< ${pkgs.writeText "config.json" (builtins.toJSON cfg.extraConfig)} \
> $out
'';
in {
###### interface
options = {
services.telegraf = {
enable = mkEnableOption "telegraf server";

package = mkOption {
default = pkgs.telegraf;
defaultText = "pkgs.telegraf";
description = "Which telegraf derivation to use";
type = types.package;
};

extraConfig = mkOption {
default = {};
description = "Extra configuration options for telegraf";
type = types.attrs;
example = {
outputs = {
influxdb = {
urls = ["http://localhost:8086"];
database = "telegraf";
};
};
inputs = {
statsd = {
service_address = ":8125";
delete_timings = true;
};
};
};
};
};
};


###### implementation
config = mkIf config.services.telegraf.enable {
systemd.services.telegraf = {
description = "Telegraf Agent";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
ExecStart=''${cfg.package}/bin/telegraf -config "${configFile}"'';
ExecReload="${pkgs.coreutils}/bin/kill -HUP $MAINPID";
User = "telegraf";
Restart = "on-failure";
};
};

users.extraUsers = [{
name = "telegraf";
uid = config.ids.uids.telegraf;
description = "telegraf daemon user";
}];
};
}
28 changes: 28 additions & 0 deletions pkgs/servers/monitoring/telegraf/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ lib, buildGoPackage, fetchFromGitHub }:

buildGoPackage rec {
name = "telegraf-${version}";
version = "1.0.0";

goPackagePath = "github.com/influxdata/telegraf";

excludedPackages = "test";

src = fetchFromGitHub {
owner = "influxdata";
repo = "telegraf";
rev = "${version}";
sha256 = "0kbh4gba4rrbykdl9wsyijh0xi5ksrch99fn4gj5gbbmd383pdzv";
};

# Generated with the `gdm2nix.rb` script and the `Godeps` file from the influxdb repo root.
goDeps = ./. + builtins.toPath "/deps-${version}.json";

meta = with lib; {
description = "The plugin-driven server agent for collecting & reporting metrics.";
license = licenses.mit;
homepage = https://www.influxdata.com/time-series-platform/telegraf/;
maintainers = with maintainers; [ mic92 roblabla ];
platforms = platforms.linux;
};
}
Loading