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