-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvzcpucheck
More file actions
executable file
·138 lines (130 loc) · 2.8 KB
/
vzcpucheck
File metadata and controls
executable file
·138 lines (130 loc) · 2.8 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# Copyright (c) 1999-2017, Parallels International GmbH. All rights reserved.
# Copyright (c) 2017-2019 Virtuozzo International GmbH. All rights reserved.
#
# This file is part of OpenVZ. OpenVZ is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Our contact details: Virtuozzo International GmbH, Vordergasse 59, 8200
# Schaffhausen, Switzerland.
#
# Script that prints cpu utilization information
# Usage: vzcpucheck [-v]
# See also vzcpucheck(8) man page
VERBOSE=0
XML=0
CPUINFO=/proc/cpuinfo
VEINFO=/proc/vz/veinfo
FRSHD=/proc/fairsched
function usage()
{
echo "Usage: vzcpucheck [-v]"
exit 2
}
if [ $# -eq 1 ]; then
case $1 in
"-v")
VERBOSE=1
;;
"-x")
XML=1
;;
*)
usage
;;
esac
elif [ $# -gt 1 ]; then
usage
fi
if [ ! -r $FRSHD ]; then
echo "Can't read $FRSHD: Permission denied" 1>&2
exit 1;
fi
if [ ! -r $CPUINFO ]; then
echo "Can't read $CPUINFO: Permission denied" 1>&2
exit 1;
fi
CPUUTL=`cat ${CPUINFO} | awk '
{
if ($1 == "bogomips" || $1 == "BogoMIPS") {
sum += $3;
}
}
END {
print(sum * 25);
}'`
cat ${FRSHD} | awk -v totunits="$CPUUTL" -v verbose="$VERBOSE" -v xml="$XML" '
BEGIN {
sum = 0;
fail = 0;
weight=-1
id=-1
getline
if ($1 == "Version:"){
getline;
}
for (i = 0; i < NF; i++) {
if ($i == "weight") {
weight = i;
}
if ($i == "id") {
id = i;
}
}
if (weight == -1) {
print("ERROR: Unknown format of '$FRSHD' column: weight not found");
fail = 1
exit
}
if (id == -1) {
print("ERROR: Unknown format of '$FRSHD' column: id not found");
fail = 1;
exit
}
if (verbose) {
print("veid\t\tunits");
print("-----------------------");
}
}
{
if ($1 == 0 && $id != 0) {
if ($weight){
units = int(500000/$weight);
} else {
units = 500000;
}
if (verbose) {
if ($id == 2147483647) {
print("0\t\t" units);
} else {
print($id "\t\t" units);
}
}
sum += units;
}
}
END {
if (fail)
exit 1
if (xml) {
print("<cpu><utilization>" sum / totunits "</utilization></cpu>");
exit 0;
}
print("Current CPU utilization: " sum);
print("Power of the node: " int(totunits));
if (sum > totunits) {
print("Warning: hardware node is overcommited");
}
}'