channel exporter: export 'current' status
Graham Christensen committed
Dec 26, 2019 at 03:56 UTC
188f39622990604c65c85ed807404658b546f65b
2 files changed
+14
-4
delft/eris/channel-exporter.py
+11
-1
@@ -6,6 +6,7 @@ from prometheus_client import Counter, Histogram, Gauge, start_http_server
6
import time
7
import sys
8
from pprint import pprint
9
+import json
10
11
CHANNEL_REQUEST_TIME = Histogram(
12
"channel_request_time", "Time spent requesting channel data"
@@ -15,6 +16,11 @@ CHANNEL_UPDATE_TIME = Gauge(
16
"Total number of failures to fetch spot market prices",
17
["channel"],
18
)
19
+CHANNEL_CURRENT = Gauge(
20
+ "channel_current",
21
+ "If a channel is expected to be current",
22
+ ["channel"],
23
+)
24
CHANNEL_REQUEST_FAILURES = Counter(
25
"channel_request_failures_total",
26
"Number of channel status requests which have failed",
@@ -34,9 +40,13 @@ def measure_channel(name):
40
if __name__ == "__main__":
41
start_http_server(9402)
42
43
+ with open(sys.argv[1]) as channel_data:
44
+ channels = json.load(channel_data)
45
+
46
while True:
38
- for channel in sys.argv[1:]:
47
+ for (channel, about) in channels.items():
48
measurement = measure_channel(channel)
49
if measurement is not None:
50
CHANNEL_UPDATE_TIME.labels(channel=channel).set(measurement)
51
+ CHANNEL_CURRENT.labels(channel=channel).set(int(about['current']))
52
time.sleep(60)
delft/eris/channel-monitor.nix
+3
-3
@@ -1,6 +1,6 @@
1
-{ lib, pkgs, ... }:
1
+{ pkgs, ... }:
2
let
3
- channels = builtins.attrNames (import ../../channels.nix).channels;
3
+ channels = pkgs.writeText "channels.json" (builtins.toJSON (import ../../channels.nix).channels);
4
in {
5
systemd.services.channel-update-exporter = {
6
description = "Check all active channels' last-update times";
@@ -8,7 +8,7 @@ in {
8
wantedBy = [ "multi-user.target" ];
9
serviceConfig = {
10
DynamicUser = true;
11
- ExecStart = "${./channel-exporter.py} ${lib.concatStringsSep " " channels}";
11
+ ExecStart = "${./channel-exporter.py} ${channels}";
12
};
13
};
14
}
\ No newline at end of file