modules/shared/telegraf: add /etc/flake-inputs.prom
allows the flake inputs to be changed without restarting telegraf
This commit is contained in:
parent
21c49c5357
commit
06b72a6b95
4 changed files with 25 additions and 30 deletions
modules
|
@ -2,7 +2,6 @@
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./apfs-cleanup.nix
|
./apfs-cleanup.nix
|
||||||
./flake-inputs.nix
|
|
||||||
./reboot.nix
|
./reboot.nix
|
||||||
./telegraf.nix
|
./telegraf.nix
|
||||||
./upgrade-diff.nix
|
./upgrade-diff.nix
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
{ inputs, lib, pkgs, ... }:
|
|
||||||
|
|
||||||
{
|
|
||||||
services.telegraf.extraConfig.inputs.file =
|
|
||||||
let
|
|
||||||
inputsWithDate = lib.filterAttrs (_: input: input ? lastModified) inputs.self.inputs;
|
|
||||||
flakeAttrs = input: (lib.mapAttrsToList (n: v: ''${n}="${v}"'')
|
|
||||||
(lib.filterAttrs (_: v: (builtins.typeOf v) == "string") input));
|
|
||||||
lastModified = name: input: ''
|
|
||||||
flake_input_last_modified{input="${name}",${lib.concatStringsSep "," (flakeAttrs input)}} ${toString input.lastModified}'';
|
|
||||||
|
|
||||||
# avoid adding store path references on flakes which me not need at runtime.
|
|
||||||
promText = builtins.unsafeDiscardStringContext ''
|
|
||||||
# HELP flake_registry_last_modified Last modification date of flake input in unixtime
|
|
||||||
# TYPE flake_input_last_modified gauge
|
|
||||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList lastModified inputsWithDate)}
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
[
|
|
||||||
{
|
|
||||||
data_format = "prometheus";
|
|
||||||
files = [
|
|
||||||
(pkgs.writeText "flake-inputs.prom" promText)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -24,8 +24,6 @@
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
};
|
};
|
||||||
|
|
||||||
srvos.flake = inputs.self;
|
|
||||||
|
|
||||||
boot.kernelPackages = pkgs.lib.mkIf (!config.boot.supportedFilesystems.zfs or false) pkgs.linuxPackages_latest;
|
boot.kernelPackages = pkgs.lib.mkIf (!config.boot.supportedFilesystems.zfs or false) pkgs.linuxPackages_latest;
|
||||||
|
|
||||||
zramSwap.enable = true;
|
zramSwap.enable = true;
|
||||||
|
|
|
@ -1,5 +1,30 @@
|
||||||
|
{ inputs, lib, ... }:
|
||||||
{
|
{
|
||||||
|
environment.etc =
|
||||||
|
let
|
||||||
|
inputsWithDate = lib.filterAttrs (_: input: input ? lastModified) inputs.self.inputs;
|
||||||
|
flakeAttrs = input: (lib.mapAttrsToList (n: v: ''${n}="${v}"'')
|
||||||
|
(lib.filterAttrs (_: v: (builtins.typeOf v) == "string") input));
|
||||||
|
lastModified = name: input: ''
|
||||||
|
flake_input_last_modified{input="${name}",${lib.concatStringsSep "," (flakeAttrs input)}} ${toString input.lastModified}'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
"flake-inputs.prom" = {
|
||||||
|
text = builtins.unsafeDiscardStringContext ''
|
||||||
|
# HELP flake_registry_last_modified Last modification date of flake input in unixtime
|
||||||
|
# TYPE flake_input_last_modified gauge
|
||||||
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList lastModified inputsWithDate)}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
services.telegraf.extraConfig.inputs = {
|
services.telegraf.extraConfig.inputs = {
|
||||||
|
file = [
|
||||||
|
{
|
||||||
|
data_format = "prometheus";
|
||||||
|
files = [ "/etc/flake-inputs.prom" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
prometheus = {
|
prometheus = {
|
||||||
metric_version = 2;
|
metric_version = 2;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue