@cryptotaxi247 / infra-1 / commits / 98524344

prometheus-nixos-exporter: reformat

Reformat the file using `ruff format`.

Martin Weinelt committed Feb 3, 2024 at 19:47 UTC 985243448b2d886f8a4fba48ce2a2240bfc0c3e6
1 file changed +14 -9
modules/prometheus/nixos-exporter.py
+14 -9
@@ -33,24 +33,29 @@ class NixosSystemCollector:
33 current_system = GaugeMetricFamily(
34 "nixos_current_system_time_seconds",
35 "The time the system's current generation was registered in the Nix database.",
36 - labels=["version_id"]
36 + labels=["version_id"],
37 + )
38 + current_system.add_metric(
39 + [self.get_version_id("/run/current-system")],
40 + self.get_time("/run/current-system"),
41 )
38 - current_system.add_metric([self.get_version_id("/run/current-system")],
39 - self.get_time("/run/current-system"))
42 yield current_system
43
44 booted_system = GaugeMetricFamily(
45 "nixos_booted_system_time_seconds",
46 "The time the system's booted generation was registered in the Nix database.",
45 - labels=["version_id"]
47 + labels=["version_id"],
48 + )
49 + booted_system.add_metric(
50 + [self.get_version_id("/run/booted-system")],
51 + self.get_time("/run/booted-system"),
52 )
47 - booted_system.add_metric([self.get_version_id("/run/booted-system")], self.get_time("/run/booted-system"))
53 yield booted_system
54
55 def get_version_id(self, path):
56 result = subprocess.run(
52 - [ "bash", "-c", f"source {path}/etc/os-release; echo $VERSION_ID" ],
53 - stdout=subprocess.PIPE
57 + ["bash", "-c", f"source {path}/etc/os-release; echo $VERSION_ID"],
58 + stdout=subprocess.PIPE,
59 )
60 if result.returncode == 0:
61 return result.stdout.decode("utf-8").strip()
@@ -74,13 +79,13 @@ class NixosSystemCollector:
79
80 return 0
81
82 +
83 registry = CollectorRegistry()
84 registry.register(NixosSystemCollector())
85
80 -if __name__ == '__main__':
86 +if __name__ == "__main__":
87 # Start up the server to expose the metrics.
88 start_http_server(9300, registry=registry)
89
90 while True:
91 time.sleep(100000)
86 -