Skip to content

Commit 2b4e0fa

Browse files
vooondhewg
andcommitted
prometheus-node-exporter-ucode: add a plugin for go2rtc
- 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' ``` Co-authored-by: Andre Heider <[email protected]> Signed-off-by: Vladimir Ermakov <[email protected]>
1 parent fd191c9 commit 2b4e0fa

File tree

3 files changed

+110
-3
lines changed

3 files changed

+110
-3
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,+ucode-mod-uclient +ucode-mod-uloop go2rtc))
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
let uloop = require("uloop");
2+
let uclient = require("uclient");
3+
4+
const api_url = config["api_url"];
5+
if (!api_url)
6+
return false;
7+
8+
let m_up = gauge("go2rtc_up");
9+
let m_producer_info = gauge("go2rtc_producer_info");
10+
let m_consumer_info = gauge("go2rtc_consumer_info");
11+
let m_producer_rx = counter("go2rtc_producer_received_bytes_total");
12+
let m_consumer_tx = counter("go2rtc_consumer_sent_bytes_total");
13+
14+
15+
function get_streams_info(api_url) {
16+
let data = '';
17+
18+
const url = `${api_url}/api/streams`;
19+
20+
uloop.init();
21+
uc = uclient.new(url, null, {
22+
data_read: (cb) => {
23+
let chunk;
24+
while (length(chunk = uc.read()) > 0)
25+
data += chunk;
26+
},
27+
data_eof: (cb) => {
28+
uloop.end();
29+
},
30+
error: (cb, code) => {
31+
warn(`failed to get url: ${url}: ${code}\n`);
32+
data = null;
33+
uloop.end();
34+
}
35+
});
36+
37+
if (!uc.set_timeout(5000)) {
38+
warn("failed to set timeout\n");
39+
return null;
40+
}
41+
42+
if (!uc.ssl_init({verify: false})) {
43+
warn("failed to initialize SSL\n");
44+
return null;
45+
}
46+
47+
if (!uc.connect()) {
48+
warn("failed to connect\n");
49+
return null;
50+
}
51+
52+
if (!uc.request("GET", {headers: {"User-Agent": "prometheus-node-exporter-ucode/1.0"}})) {
53+
warn("failed to send request\n");
54+
return null;
55+
}
56+
57+
uloop.run();
58+
59+
if (data == null) {
60+
return null;
61+
}
62+
63+
return json(data);
64+
}
65+
66+
const x = get_streams_info(api_url);
67+
68+
if (!x) {
69+
m_up({url: api_url}, 0);
70+
return false;
71+
}
72+
73+
m_up({url: api_url}, 1);
74+
75+
for (let stream, info in x) {
76+
77+
for (let producer in info.producers) {
78+
m_producer_info({
79+
stream: stream,
80+
format_name: producer.format_name,
81+
protocol: producer.protocol,
82+
remote_addr: producer.remote_addr,
83+
user_agent: producer.user_agent,
84+
}, (!producer.remote_addr) ? 0 : 1);
85+
m_producer_rx({
86+
stream: stream,
87+
remote_addr: producer.remote_addr,
88+
}, producer.bytes_recv);
89+
}
90+
91+
for (let consumer in info.consumers) {
92+
m_consumer_info({
93+
stream: stream,
94+
format_name: consumer.format_name,
95+
protocol: consumer.protocol,
96+
remote_addr: consumer.remote_addr,
97+
user_agent: consumer.user_agent,
98+
}, 1);
99+
m_consumer_tx({
100+
stream: stream,
101+
remote_addr: consumer.remote_addr,
102+
}, consumer.bytes_send);
103+
}
104+
105+
}

utils/prometheus-node-exporter-ucode/files/init

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ start_service() {
4040
[ $keepalive -gt 0 ] && procd_append_param command -k $keepalive
4141

4242
procd_add_jail prometheus-node-exporter-ucode log procfs sysfs ubus
43-
procd_add_jail_mount "/usr/lib/uhttpd_ucode.so"
4443
procd_add_jail_mount "/lib/libubus.so*"
4544
procd_add_jail_mount "/lib/libuci.so*"
46-
procd_add_jail_mount "/usr/lib/ucode"
45+
procd_add_jail_mount "/lib/libustream-ssl.so"
46+
procd_add_jail_mount "/usr/lib/uhttpd_ucode.so"
47+
procd_add_jail_mount "/usr/lib/ucode/*.so"
4748
procd_add_jail_mount "/usr/lib/libnl*.so*"
4849
procd_add_jail_mount "/usr/share/ucode/node-exporter"
4950
procd_add_jail_mount "/etc/config"

0 commit comments

Comments
 (0)