@cryptotaxi247 / infra-1 / commits / 6ad4d4fa

for nixos-metrics, use systemd timer not cron

Taeer Bar-Yam committed Jan 9, 2023 at 13:57 UTC 6ad4d4fa4630d83830f93aaac76c7b3544d0a4bb
1 file changed +23 -14
delft/eris.nix
+23 -14
@@ -590,21 +590,30 @@ in
590 (import ../channels.nix).channels;
591 };
592
593 - # pull nixos metrics from github:NixOS/nixos-metrics to local VictoriaMetrics
594 - # every day at 09.00
595 - services.cron = {
596 - enable = true;
597 - systemCronJobs = let
598 - inherit (config.services.victoriametrics) listenAddress;
599 - importURL = "http://localhost:${listenAddress}/api/v1/import";
600 - resetURL = "http://localhost:${listenAddress}/internal/resetRollupResultCache";
601 - dataURL = "https://raw.githubusercontent.com/NixOS/nixos-metrics/data/victoriametrics.jsonl";
602 - pull-mterics = pkgs.writeShellScript "pull-metrics.sh" ''
603 - curl -X POST ${importURL} -T <(curl ${dataURL})
604 - curl -G ${resetURL}
593 + systemd.services.pull-nixos-metrics = {
594 + description = "Pull nixos metrics from github:NixOS/nixos-metrics and push to local VictoriaMetrics";
595 + script =
596 + let
597 + inherit (config.services.victoriametrics) listenAddress;
598 + importURL = "http://localhost${listenAddress}/api/v1/import";
599 + resetURL = "http://localhost${listenAddress}/internal/resetRollupResultCache";
600 + dataURL = "https://raw.githubusercontent.com/NixOS/nixos-metrics/data/victoriametrics.jsonl";
601 + curl = "${pkgs.curl}/bin/curl";
602 + in
603 + ''
604 + ${curl} ${dataURL} | ${curl} -X POST --data-binary @- ${importURL}
605 + ${curl} -G ${resetURL}
606 '';
606 - in
607 - [ "0 9 * * * root ${pull-metrics}" ];
607 + serviceConfig = {
608 + Type = "oneshot";
609 + User = "nobody";
610 + };
611 + };
612 +
613 + systemd.timers.pull-nixos-metrics = {
614 + description = "Pull nixos metrics, timed for after they're done updating each day.";
615 + wantedBy = [ "timers.target" ];
616 + timerConfig.OnCalendar = "12:00:00";
617 };
618
619 services.victoriametrics = {