Skip to content

Commit 18e01bf

Browse files
committed
prometheus-node-exporter-ucode: add a plugin for go2rtc metrics
- Add a plugin to export go2rtc metrics Requires additional api_url option to enable: ``` uci set prometheus-node-exporter-ucode.go2rtc=collector uci set prometheus-node-exporter-ucode.go2rtc.api_url='http://127.0.0.1:1984' ``` Signed-off-by: Vladimir Ermakov <[email protected]>
1 parent 8efcd79 commit 18e01bf

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

utils/prometheus-node-exporter-ucode/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk
44

55
PKG_NAME:=prometheus-node-exporter-ucode
66
PKG_VERSION:=2024.02.07
7-
PKG_RELEASE:=2
7+
PKG_RELEASE:=3
88

99
PKG_MAINTAINER:=Andre Heider <[email protected]>
1010
PKG_LICENSE:=Apache-2.0
@@ -72,3 +72,4 @@ $(eval $(call Collector,snmp6,snmp6 collector,))
7272
$(eval $(call Collector,uci_dhcp_host,UCI DHCP host collector,))
7373
$(eval $(call Collector,wifi,Wi-Fi collector,+ucode-mod-nl80211))
7474
$(eval $(call Collector,wireguard,Wireguard collector,+rpcd-mod-wireguard))
75+
$(eval $(call Collector,go2rtc,go2rtc collector,+uclient-fetch go2rtc))
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as log from "log";
2+
3+
const api_url = config["api_url"];
4+
if (!api_url)
5+
return false;
6+
7+
let m_up = gauge("go2rtc_up");
8+
let m_producer_info = gauge("go2rtc_producer_info");
9+
let m_consumer_info = gauge("go2rtc_consumer_info");
10+
let m_producer_rx = counter("go2rtc_producer_received_bytes_total");
11+
let m_consumer_tx = counter("go2rtc_consumer_sent_bytes_total");
12+
13+
14+
function get_streams_info(api_url) {
15+
16+
const url = `${api_url}/api/streams`;
17+
18+
// NOTE: ucode-mod-uclient not so easy to use, also it brings problems with ujail library mount.
19+
let ret = ubus.call("file", "exec", {command: "uclient-fetch", params: ["-T", "5", "-O", "-", url]});
20+
if (ret?.code != 0) {
21+
log.ERR("failed to fetch url: %s rc: %d: err: %s", url, ret?.code, ret?.stderr);
22+
return null;
23+
}
24+
25+
return json(ret.stdout);
26+
}
27+
28+
const x = get_streams_info(api_url);
29+
30+
if (!x) {
31+
m_up({url: api_url}, 0);
32+
return false;
33+
}
34+
35+
m_up({url: api_url}, 1);
36+
37+
for (let stream, info in x) {
38+
39+
for (let producer in info.producers) {
40+
m_producer_info({
41+
stream: stream,
42+
format_name: producer.format_name,
43+
protocol: producer.protocol,
44+
remote_addr: producer.remote_addr,
45+
user_agent: producer.user_agent,
46+
}, (!producer.remote_addr) ? 0 : 1);
47+
m_producer_rx({
48+
stream: stream,
49+
remote_addr: producer.remote_addr,
50+
}, producer.bytes_recv);
51+
}
52+
53+
for (let consumer in info.consumers) {
54+
m_consumer_info({
55+
stream: stream,
56+
format_name: consumer.format_name,
57+
protocol: consumer.protocol,
58+
remote_addr: consumer.remote_addr,
59+
user_agent: consumer.user_agent,
60+
}, 1);
61+
m_consumer_tx({
62+
stream: stream,
63+
remote_addr: consumer.remote_addr,
64+
}, consumer.bytes_send);
65+
}
66+
67+
}

0 commit comments

Comments
 (0)