Merge in Splunk Add-On for Unix and Linux version 10.1.0
This commit is contained in:
parent
847f4ab742
commit
13b1e503ea
20 changed files with 429 additions and 167 deletions
69
bin/cpu.sh
69
bin/cpu.sh
|
@ -42,17 +42,64 @@ if [ "$KERNEL" = "Linux" ] ; then
|
|||
echo "Cmd = [$CMD]; | $AWK '$FILTER $FORMAT $PRINTF' header=\"$HEADER\"" >> "$TEE_DEST"
|
||||
exit
|
||||
elif [ "$KERNEL" = "SunOS" ] ; then
|
||||
formatted_date=$(date +"%m/%d/%y_%H:%M:%S_%Z")
|
||||
if [ "$SOLARIS_8" = "true" ] || [ "$SOLARIS_9" = "true" ] ; then
|
||||
CMD='eval mpstat -a -p 1 2 | tail -1 | sed "s/^[ ]*0/all/"; mpstat -p 1 2 | tail -r'
|
||||
else
|
||||
CMD='eval mpstat -aq -p 1 2 | tail -1 | sed "s/^[ ]*0/all/"; mpstat -q -p 1 2 | tail -r'
|
||||
fi
|
||||
assertHaveCommand "$CMD"
|
||||
# shellcheck disable=SC2016
|
||||
FILTER='($1=="CPU") {exit 1}'
|
||||
# shellcheck disable=SC2016
|
||||
FORMAT='{datetime="'"$formatted_date"'"; cpu=$1; pctUser=$(NF-4); pctNice="0"; pctSystem=$(NF-3); pctIowait=$(NF-2); pctIdle=$(NF-1)}'
|
||||
CMD='mpstat -p 2 5'
|
||||
FORMAT='
|
||||
|
||||
function get_cpu_count(){
|
||||
command = "psrinfo -p"; # Use this for Solaris
|
||||
command | getline cpu_count;
|
||||
close(command);
|
||||
return cpu_count;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
cpu_processed = 0;
|
||||
user_sum = system_sum = iowait_sum = idle_sum = 0;
|
||||
# Dynamically set CPU count
|
||||
cpu_count = get_cpu_count();
|
||||
last_cpu = cpu_count-1;
|
||||
}
|
||||
|
||||
function get_current_time() {
|
||||
command = "date +\"%m/%d/%y_%H:%M:%S_%Z\"";
|
||||
command | getline datetime;
|
||||
close(command);
|
||||
return datetime;
|
||||
}{
|
||||
datetime=get_current_time();
|
||||
cpu=$1;
|
||||
pctUser=$(NF-4);
|
||||
pctNice="0";
|
||||
pctSystem=$(NF-3);
|
||||
pctIowait=$(NF-2);
|
||||
pctIdle=$(NF-1);
|
||||
|
||||
user_sum += pctUser;
|
||||
system_sum += pctSystem;
|
||||
iowait_sum += pctIowait;
|
||||
idle_sum += pctIdle;
|
||||
cpu_processed++;
|
||||
}
|
||||
'
|
||||
FILTER='($0 ~ /CPU/) { if($(NF-1) ~ /gnice/){ NFIELDS=NF; } else {NFIELDS=NF+1;} next} /Average|Linux|^$|%/ {next}'
|
||||
PRINTF='
|
||||
{
|
||||
if (cpu ~ /0/) {
|
||||
print header;
|
||||
printf "%-28s %-3s %9s %9s %9s %9s %9s\n", datetime, cpu, pctUser, pctNice, pctSystem, pctIowait, pctIdle;
|
||||
} else if (cpu ~ last_cpu) {
|
||||
printf "%-28s %-3s %9s %9s %9s %9s %9s\n", datetime, cpu, pctUser, pctNice, pctSystem, pctIowait, pctIdle;
|
||||
printf "%-28s %-3s %9s %9s %9s %9s %9s\n", datetime, "all", user_sum / cpu_count, pctNice, system_sum / cpu_count, iowait_sum / cpu_count, idle_sum / cpu_count;
|
||||
cpu_processed = 0;
|
||||
user_sum = system_sum = iowait_sum = idle_sum = 0;
|
||||
}else{
|
||||
printf "%-28s %-3s %9s %9s %9s %9s %9s\n", datetime, cpu, pctUser, pctNice, pctSystem, pctIowait, pctIdle;
|
||||
}
|
||||
}'
|
||||
$CMD | tee "$TEE_DEST" | $AWK "$FILTER $FORMAT $PRINTF" header="$HEADER"
|
||||
echo "Cmd = [$CMD]; | $AWK '$FILTER $FORMAT $PRINTF' header=\"$HEADER\"" >> "$TEE_DEST"
|
||||
exit
|
||||
|
||||
elif [ "$KERNEL" = "AIX" ] ; then
|
||||
queryHaveCommand mpstat
|
||||
queryHaveCommand lparstat
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue