main
nix 36 lines 1.13 KB
Raw
1 { config, pkgs, ... }:
2
3 {
4 systemd.services.pull-nixos-metrics = {
5 description = "Pull nixos metrics from github:NixOS/nixos-metrics and push to local VictoriaMetrics";
6 script =
7 let
8 inherit (config.services.victoriametrics) listenAddress;
9 importURL = "http://localhost${listenAddress}/api/v1/import";
10 resetURL = "http://localhost${listenAddress}/internal/resetRollupResultCache";
11 dataURL = "https://raw.githubusercontent.com/NixOS/nixos-metrics/data/victoriametrics.jsonl";
12 curl = "${pkgs.curl}/bin/curl";
13 in
14 ''
15 ${curl} ${dataURL} | ${curl} -X POST --data-binary @- ${importURL}
16 ${curl} -G ${resetURL}
17 '';
18 serviceConfig = {
19 Type = "oneshot";
20 User = "nobody";
21 };
22 };
23
24 systemd.timers.pull-nixos-metrics = {
25 description = "Pull nixos metrics, timed for after they're done updating each day.";
26 wantedBy = [ "timers.target" ];
27 timerConfig.OnCalendar = "12:00:00";
28 };
29
30 services.backup.includesZfsDatasets = [ "/var/lib/victoriametrics" ];
31
32 services.victoriametrics = {
33 enable = true;
34 retentionPeriod = "1200w"; # 100 years
35 };
36 }