A
Ashish Kumar
Hello,
I'm developing a plugin for nagios to get CPU usage on Red Hat Linux
machines. Below is a snippet:
-------------------- 8< --------------------
$get_cpu_util=`vmstat 1 2 | tail -n 1`;
# procs -----------memory---------- ---swap-- -----io---- --system--
----cpu----
# r b swpd free buff cache si so bi bo in cs
us sy id wa
# 2 0 0 4424156 181780 2505320 0 0 0 7 1
1 0 0 100 0
# 0 0 0 4426332 181780 2505320 0 0 0 48 1121
3762 0 0 100 0
if($get_cpu_util =~ /^.*\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/){
$us=$1;
$sy=$2;
$id=$3;
$wa=$4;
}
-------------------- 8< --------------------
The code runs fine on RHEL4 hosts and shows the correct values. But
in RHEL5 they have added one more value namely "st" in cpu section:
-------------------- 8< --------------------
procs -----------memory---------- ---swap-- -----io---- --system--
-----cpu------
r b swpd free buff cache si so bi bo in cs us
sy id wa st
0 0 33184 10028 66208 68396 0 0 737 276 15 12 34
9 51 7 0
0 0 33184 10028 66208 68396 0 0 0 32 1104 140 0
0 100 0 0
-------------------- 8< --------------------
So, I was just wondering if there is any way to run the same code run
on both hosts with some regex wizardry?
Thanks.
I'm developing a plugin for nagios to get CPU usage on Red Hat Linux
machines. Below is a snippet:
-------------------- 8< --------------------
$get_cpu_util=`vmstat 1 2 | tail -n 1`;
# procs -----------memory---------- ---swap-- -----io---- --system--
----cpu----
# r b swpd free buff cache si so bi bo in cs
us sy id wa
# 2 0 0 4424156 181780 2505320 0 0 0 7 1
1 0 0 100 0
# 0 0 0 4426332 181780 2505320 0 0 0 48 1121
3762 0 0 100 0
if($get_cpu_util =~ /^.*\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/){
$us=$1;
$sy=$2;
$id=$3;
$wa=$4;
}
-------------------- 8< --------------------
The code runs fine on RHEL4 hosts and shows the correct values. But
in RHEL5 they have added one more value namely "st" in cpu section:
-------------------- 8< --------------------
procs -----------memory---------- ---swap-- -----io---- --system--
-----cpu------
r b swpd free buff cache si so bi bo in cs us
sy id wa st
0 0 33184 10028 66208 68396 0 0 737 276 15 12 34
9 51 7 0
0 0 33184 10028 66208 68396 0 0 0 32 1104 140 0
0 100 0 0
-------------------- 8< --------------------
So, I was just wondering if there is any way to run the same code run
on both hosts with some regex wizardry?
Thanks.