Skip to content
Closed
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 @@
gocd-server = 252;
terraria = 253;
mattermost = 254;
telegraf = 255;

# 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 @@
gocd-server = 252;
terraria = 253;
mattermost = 254;
telegraf = 255;

# 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 @@ -293,6 +293,7 @@
./services/monitoring/smartd.nix
./services/monitoring/statsd.nix
./services/monitoring/systemhealth.nix
./services/monitoring/telegraf.nix
./services/monitoring/teamviewer.nix
./services/monitoring/ups.nix
./services/monitoring/uptime.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;
};
};

};


###### implementation

config = mkIf config.services.telegraf.enable {

systemd.services.telegraf = {
description = "Telegraf Agent";
wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you set this to network-interfaces.target instead of networking.target?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groxxda good point. This target is actually used by quite a few services ... From the looks of it, network-interfaces is akin to an implementation detail and shouldn't be referenced directly by ordinary services (which are probably best served by using special targets for ordering and whatnot).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joachifm a follow up to #18319 is on my to-do to get rid of network-interfaces.target since so many targets tend to confuse everyone. upstream network targets should really be enough for ordinary services.
feel free to assist 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groxxda it's a fairly mechanical translation, so needs a bit of sanity checking

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joachifm sorry for not notifying you, I also started the work on this https://github.com/groxxda/nixpkgs/commits/network-interfaces
As you said, most is mechanical translation, but there are one or two exceptions.
Also I did a batch of changes to scripted-interfaces because I think ordering is broken there. But this needs more review and was blocking me from a pr. I'll push the current wip state soon
I'll have a look at your changes now

serviceConfig = {
ExecStart = ''${cfg.package}/bin/telegraf -config "${configFile}"'';
User = "telegraf";
Group = "telegraf";
};
};

users.extraUsers = [{
name = "telegraf";
uid = config.ids.uids.telegraf;
description = "telegraf daemon user";
}];

users.extraGroups = [{
name = "telegraf";
gid = config.ids.gids.telegraf;
}];
};

}

27 changes: 27 additions & 0 deletions pkgs/tools/system/telegraf/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ lib, buildGoPackage, fetchFromGitHub }:

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

src = fetchFromGitHub {
owner = "influxdata";
repo = "telegraf";
rev = "${version}";
sha256 = "1zdb85wkx5q7c799sn695ckzym6avqz05xlvw0d1p919c2ilba9f";
};

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

# Generated with the `gdm2nix.rb` script and the `Godeps` file from the
# influxdb repo root.
goDeps = ./deps.json;

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