Debian Codegraph @

pkg/networkmanager/helpers.js

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 import cockpit from "cockpit";
3
4 export class UsageMonitor {
5 constructor() {
6 this.channel = cockpit.metrics(
7 1000,
8 [
9 {
10 source: "direct",
11 metrics: [
12 {
13 name: "network.interface.in.bytes",
14 units: "bytes",
15 derive: "rate"
16 },
17 {
18 name: "network.interface.out.bytes",
19 units: "bytes",
20 derive: "rate"
21 },
22 ],
23 metrics_path_names: ["rx", "tx"]
24 },
25 {
26 source: "internal",
27 metrics: [
28 {
29 name: "network.interface.rx",
30 units: "bytes",
31 derive: "rate"
32 },
33 {
34 name: "network.interface.tx",
35 units: "bytes",
36 derive: "rate"
37 },
38 ],
39 metrics_path_names: ["rx", "tx"]
40 }
41 ]
42 );
43
44 this.grid = cockpit.grid(1000, -1, -0);
45 this.samples = { };
46
47 this.channel.follow();
48 this.grid.walk();
49 }
50
51 add(iface) {
52 if (!this.samples[iface]) {
53 this.samples[iface] = [
54 this.grid.add(this.channel, ["rx", iface]),
55 this.grid.add(this.channel, ["tx", iface])
56 ];
57 }
58 }
59 }