-
Notifications
You must be signed in to change notification settings - Fork 2
/
Eth1_StatsMeter.c
92 lines (76 loc) · 2.67 KB
/
Eth1_StatsMeter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
htop - Eth1_StatsMeter.c
(C) 2020 @lex
*/
#include "Eth1_StatsMeter.h"
#include "Platform.h"
#include "CRT.h"
#include "interfaces.h"
/*{
#include "Meter.h"
}*/
int Eth1_StatsMeter_attributes[] = {
ETH1_INTERFACE
};
/* borrowed from slurm */
static void Eth1_StatsMeter_setValues(Meter* this, char* buffer, int len) {
int ret;
float rxspeed;
float txspeed;
Settings* settings = this->pl->settings;
double refreshdelay;
static double old = 0.;
static double now = 0.;
now = get_wall_time();
refreshdelay = now - old;
if (old == 0.)
refreshdelay = 1.;
old = now;
if (settings->eth1_alias[0] != 0) {
ret = Platform_getEth_stats(settings->eth1_alias, 1, 0);
} else {
ret = Platform_getEth_stats("eth1", 1, 0);
}
if (ret) {
if (Platform_Eth1_stats.rx_bytes_comp > Platform_Eth1_stats.rx_bytes)
Platform_Eth1_stats.rx_bytes_comp = 0;
if (Platform_Eth1_stats.tx_bytes_comp > Platform_Eth1_stats.tx_bytes)
Platform_Eth1_stats.tx_bytes_comp = 0;
/* we assume here the refresdelay is 1 sec which sometimes is 1.5, so we have a peak */
rxspeed = (Platform_Eth1_stats.rx_bytes - Platform_Eth1_stats.rx_bytes_comp) / refreshdelay;
txspeed = (Platform_Eth1_stats.tx_bytes - Platform_Eth1_stats.tx_bytes_comp) / refreshdelay;
txspeed = (float) txspeed / 1000.;
rxspeed = (float) rxspeed / 1000.;
if (rxspeed < 1000. && txspeed < 1000.) {
xSnprintf(buffer, len, "%.2f KB/s - %.2f KB/s (RX/TX)", (float) rxspeed, (float) txspeed);
} else {
txspeed = (float) txspeed / 1000.;
rxspeed = (float) rxspeed / 1000.;
if (txspeed < 1000. && rxspeed < 1000.) {
xSnprintf(buffer, len, "%.2f MB/s - %.2f MB/s (RX/TX)", (float) rxspeed, (float) txspeed);
} else {
txspeed = (float) txspeed / 1000.;
rxspeed = (float) rxspeed / 1000.;
xSnprintf(buffer, len, "%.2f GB/s - %.2f GB/s (RX/TX)", (float) rxspeed, (float) txspeed);
}
}
Platform_Eth1_stats.rx_bytes_comp = Platform_Eth1_stats.rx_bytes;
Platform_Eth1_stats.tx_bytes_comp = Platform_Eth1_stats.tx_bytes;
} else {
xSnprintf(buffer, len, "%s", "unavail");
}
}
MeterClass Eth1_StatsMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete
},
.updateValues = Eth1_StatsMeter_setValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 8,
.total = 100.0,
.attributes = Eth1_StatsMeter_attributes,
.name = "Eth1stat",
.uiName = "Eth1 stat",
.caption = "Eth1 stat: ",
};