blob: 12ae56af9127dd71c2a83ce16095230a99db4416 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001import { cursor } from "uci";
2
3const x = ubus.call("wireguard", "status");
4if (!x)
5 return false;
6
7const uci = cursor();
8uci.load("network");
9
10let m_wg_iface_info = gauge("wireguard_interface_info");
11let m_wg_peer_info = gauge("wireguard_peer_info");
12let m_wg_handshake = gauge ("wireguard_latest_handshake_seconds");
13let m_wg_rx = gauge ("wireguard_received_bytes_total");
14let m_wg_tx = gauge ("wireguard_sent_bytes_total");
15
16for (let iface in x) {
17 const wc = x[iface];
18
19 m_wg_iface_info({
20 name: iface,
21 public_key: wc["public_key"],
22 listen_port: wc["listen_port"],
23 fwmark: wc["fwmark"] || NaN,
24 }, 1);
25
26 for (let peer in wc["peers"]) {
27 let description;
28 uci.foreach('network', `wireguard_${iface}`, (s) => {
29 if (s.public_key == peer)
30 description = s.description;
31 });
32
33 const pc = wc["peers"][peer];
34
35 m_wg_peer_info({
36 interface: iface,
37 public_key: peer,
38 description,
39 endpoint: pc["endpoint"],
40 persistent_keepalive_interval: pc["persistent_keepalive_interval"] || NaN,
41 }, 1);
42
43 const labels = { public_key: peer };
44
45 m_wg_handshake(labels, pc["last_handshake"]);
46 m_wg_rx(labels, pc["rx_bytes"]);
47 m_wg_tx(labels, pc["tx_bytes"]);
48 }
49}