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