-
Notifications
You must be signed in to change notification settings - Fork 11
/
Nodes.pm.patch
104 lines (98 loc) · 2.68 KB
/
Nodes.pm.patch
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
diff --git a/usr/share/perl5/PVE/API2/Nodes.pm b/../Nodes.pm
index bfe5c40..22fc451 100644
--- a/usr/share/perl5/PVE/API2/Nodes.pm
+++ b/../Nodes.pm
@@ -396,40 +396,99 @@ __PACKAGE__->register_method({
};
$res->{swap} = {
free => $meminfo->{swapfree},
total => $meminfo->{swaptotal},
used => $meminfo->{swapused},
};
$res->{pveversion} = PVE::pvecfg::package() . "/" .
PVE::pvecfg::version_text();
my $dinfo = df('/', 1); # output is bytes
$res->{rootfs} = {
total => $dinfo->{blocks},
avail => $dinfo->{bavail},
used => $dinfo->{used},
free => $dinfo->{blocks} - $dinfo->{used},
};
+ my %sensors_config = (
+ cputemp => {
+ jsonpath => ['coretemp-isa-0000', 'Package id 0'],
+ valkey => 'temp1_input',
+ critkey => 'temp1_crit',
+ },
+ pchtemp => {
+ jsonpath => ['pch_cannonlake-virtual-0', 'temp1'],
+ valkey => 'temp1_input',
+ },
+ nvmetemp => {
+ jsonpath => ['nvme-pci-0100', 'Composite'],
+ valkey => 'temp1_input',
+ critkey => 'temp1_crit',
+ },
+ hd1temp => {
+ jsonpath => ['drivetemp-scsi-0-0', 'temp1'],
+ valkey => 'temp1_input',
+ critkey => 'temp1_crit',
+ },
+ hd2temp => {
+ jsonpath => ['drivetemp-scsi-1-0', 'temp1'],
+ valkey => 'temp1_input',
+ critkey => 'temp1_crit',
+ },
+ hd3temp => {
+ jsonpath => ['drivetemp-scsi-2-0', 'temp1'],
+ valkey => 'temp1_input',
+ critkey => 'temp1_crit',
+ },
+ );
+ my $temp_default_val = 0;
+ my $temp_default_crit = 80;
+
+ my $sensors = eval { decode_json(`sensors -j`); };
+ if (defined($sensors)) {
+ keys %sensors_config;
+ while (my ($k, $v) = each %sensors_config) {
+ if (!defined($v->{jsonpath})) { next; }
+ my $currref = $sensors;
+ my $pathdefined = 1;
+ for my $pathseg (@{$v->{jsonpath}}) {
+ if (defined($currref->{$pathseg})) {
+ $currref = $currref->{$pathseg}
+ } else {
+ $pathdefined = 0;
+ last;
+ }
+ }
+ if (!$pathdefined) { next; }
+ $res->{$k} = {
+ used => defined($v->{valkey}) && defined($currref->{$v->{valkey}})
+ ? $currref->{$v->{valkey}} : $temp_default_val,
+ total => defined($v->{critkey}) && defined($currref->{$v->{critkey}})
+ ? $currref->{$v->{critkey}} : $temp_default_crit,
+ };
+ }
+ }
+
return $res;
}});
__PACKAGE__->register_method({
name => 'netstat',
path => 'netstat',
method => 'GET',
permissions => {
check => ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
},
description => "Read tap/vm network device interface counters",
proxyto => 'node',
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
},
},
returns => {
type => "array",