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