Article 6FFT5 Unable to Identify Process Causing Server Failure

Unable to Identify Process Causing Server Failure

by
LinuxRSA
from LinuxQuestions.org on (#6FFT5)
Hi All

We running various versions of ubuntu and often experience Linux servers freezing & going into a hung state. After the hard reset is completed the server is back online. The issue we having is identifying what processes or applications has utilized high system resources. Our monitoring tool is limited in terms of identifying Process ID's, it however provides the overall CPU MEM Load usage via graphs.

I need to develop a bash script that records Process id's breaching a certain threshold and write the output to /home/monuser/perfstats.txt to identify the PIDS post server crash.

CPU is 95% +
MEM is 95% +
Load is 25 +


The below command is easy and provides the output we need.

Code:monuser@monitor01:~$ ps -ax -o pid,pcpu,pmem,user --sort -pcpu --no-headers | head
2033 31.1 3.7 process-name
4147 21.1 1.0 root
11512 16.0 3.5 process-name
2481 9.2 0.5 root
1718 6.7 0.5 root
13285 3.1 29.7 process-name
1910 0.9 0.2 root
10869 0.8 0.2 root
3452 0.7 0.1 root
3185 0.6 0.2 process-name
monuser@monitor01:~$We know the 2nd Colum is CPU and the 3rd id MEM

The script below is continuous in running and gathering the information throughout the day however we dont require the entries below 95% for CPU and Mem and Load usage.

Code:#!/bin/bash
# This script monitors CPU Memory and Load.

while :
do
# Check the current PID and usage of CPU and memory and Load.
cpuandmemUsage=$(ps -ax -o pid,pcpu,pmem,user --sort -pcpu --no-headers | head)
loadUsage=$(cat /proc/loadavg)

# Print the usage
echo "CPU and Mem Usage: $cpuandmemUsage%" >> /home/monuser/perfstats.txt
echo "SysLoad Usage: $loadUsage MB" >> /home/monuser/perfstats.txt

# Sleep for 1 second
sleep 1
done1. Is there a mechanism OR script we can configure to write to a file when that 2 columns value exceeds 95% and activate the script to start recording the data ?

Is this possible.

TIA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments