If you receive a CPU usage error code from Script Monitor, this guide was written to help you.
Approved: Fortect
linuxconfig.org Image: linuxconfig.orgCPU-MEM-monitor is a great simple script to track Linux CPU memory usage over time and generated with a CSV report that can be easily evaluated and generated with Excel or OpenOffice Calc for example. More specifically, this script allows you to track CPU usage for each thread and callback usage by automatically analyzing the output of the TOP or PIDSTAT utilities.
Processor performance is one aspect that only measures system performance, which is literally important for measuring overall system performance.
If the CPU of an ideal Linux system is occupied by different processes, it will not be available for other requests, and the remaining team will have to wait until the CPU is usually free.
When your system is under load it can slow down Make your application work and become a complete bottleneck in the system.
There are many CPU monitoring and display programs available on Linux such as top, htop, look, etc.
In this tutorial, we have added shell scripts to track CPU usage on a Linux system. This is highly recommended if the user only has a few systems to help him control.
These scripts send an email with the correct email id when the technology reaches a certain threshold.
Read the following blog posts to learn more about monitoring storage and disk usage with email notification capability:
- How to track disk usage using shell scripts
- How to find out the most common memory processes in Linux
Method 1: Linux Shell Script To Track CPU Usage With One Email Notification
If you just want to track the percentage of CPU usage (with one noteE-mail) rather than information about the processes when the system reaches a certain threshold, use the scenario below.
This is a simple and straightforward script that sends an email when your system is using 80%
CPU.
* / 5 * * * * / usr / bin / cat / proc / loadavg Awk | 'Print $ 1' Awk | 'if ($ 1> 80) printf ("Current CPU usage:% .2f% n"), $ 0;' | mail -s "CPU Usage Alert" [email is being protected]
Note. Modify the email ID and CPU utilization thresholds according to these requirements.
Result: You will receive an email notification similar to the one below.
Current CPU utilization: 80.40%
Method 2: Write A Linux Shell To Track CPU Usage With Email Alert
If you would like to get detailed information about the CPU utilization processes through email notifications, use the following script.
Approved: Fortect
Fortect is the world's most popular and effective PC repair tool. It is trusted by millions of people to keep their systems running fast, smooth, and error-free. With its simple user interface and powerful scanning engine, Fortect quickly finds and fixes a broad range of Windows problems - from system instability and security issues to memory management and performance bottlenecks.
This requires information on the 10 most CPU-intensive tasks based on the top and p commands. C. Order. p>
This gives you an immediate idea of what’s going on on your system.
An email will be sent when your system reaches 90%
CPU usage please
Note. Change my email ID and CPU usage thresholds as needed.
# vi /opt/scripts/cpu-alert.sh#! / bin / bashcpuuse = $ (cat / proc / loadavg | awk 'print -f $ 3' | cut 1 -g ".")if ["$ cpuuse" -ge]; then ninetySUBJECT = "WARNING: high CPU usage on $ (hostname) since $ (date)"MESSAGE = "/ tmp / Mail.out"To = " [protected by email] " echo "Current CPU usage is usually: $ cpuuse%" >> $ MESSAGE echo "" >> $ MESSAGE echo "+ ----------------------------------------------- ------------ ------------------- + ">> $ MESSAGE present "Top 20 Processes Using an Exceptional Processor" >> $ MESSAGE echo "+ ----------------------------------------------- - ------------ ------------------- + ">> $ MESSAGE echo "$ (top -bn1 | end -20)" >> $ MESSAGE echo "" >> $ MESSAGE echo "+ ----------------------------------------------- - ------------ ------------------- + ">> $ MESSAGE show "Top 10 Processes Using Massive CPU Using ps Command" >> $ MESSAGE echo "+ ----------------------------------------------- - ------------ ------------------- + ">> $ MESSAGE Mirror "$ (ps -eo pcpu, pid, user, args| sort -k 9 -r | head -10) ">> $ MESSAGE send -s "$ SUBJECT" "$ A" <$ MESSAGE rm /tmp/Mail.outanotherecho "Server CPU usage below threshold" fi
Finally, add a cron job to this computer. It will be updated every 5 minutes.
# crontab -e* / 10 * * 5. / bin / bash * /opt/scripts/cpu-alert.sh
Note. Since the script must run every 5 minutes, the user will receive an email notification every 5 minutes.
If your demo system reaches the specified limit after 8.25 minutes, you will receive an email notification during the second cycle, i.e.
Result: you get a sent notification like the one you read:
Current CPU utilization: 80.51%+ ------------------------------------------------- --------------- ----------------- +Higher cpu process with top command+ ------------------------------------------------- --------------- ----------------- +up - 13:23:01 up 1:43, 1 user, two average loads: 0.58, 2.58, 1.51Functions: 306 total or maybe 303 runs, sleeps, 0 stalls, 0 zombies.% Cpu0: 6.2 μs, 6.2 syn, 0.0 ni, 87.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st% Cpu1: 18.8 us, 0.0 sy, 0.0 ni, 81.2 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st% Cpu2: 50.0 μs, 37.5 sync, 0.0 ni, 12.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st% Cpu3 - 5.9 μs, 5.9 syn, 0.0 n , 88.2 id, 0.0 wa, 0.0 hi, 0.0 cuando, 0.St% Cpu4 0: 0.0 us, 5.9 sy, 0.0 national insurance, 94.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st% Cpu5: 29.4 μs, 23.5 si, 0.0 ni, 47.1 id, 0.0 California, 0.0 hi, 0.0 si, 0.0 si% Cpu6: 0.0 du, 5.9 sy, 0.0 ni, 94.1 id, 0.0 wa, 0.0 hiya and welcome, 0.0 si, 0.0 st% Cpu7 (space) 5.9 us, 0.0 sy, 0.0 ni, 94.1 id, 0.0 wa, 0.0 hi, 0.0 suppose 0.0 stKiB Mem: 16248588 maximum, 223436 free, 5816924 spent, 10208228 buff / cashKiB Swap: total, 17873388 17871340 price, 2048 used. 7440884 Display PID USER PR NI VIRT RES SHR S% CPU% MEM TIME + COMMAND 8867 daygeek fifteen 2743884 440420 360952 R 100.0 2.7 1: 07.25 / usr / lib / virtualbox / VirtualBoxVM --comment CentOS7 --startvm 002f47b8-2af2-48f5-be1d-67b67e03514c --no-startvm-errormsgbox 9119 Daygeek 22 36 136 784 R 46.7 0.0 0: 00.07 / usr / bin / CROND -n 1057 daygeek 20 889808 487692 461692 S 13.3 3.0 4: 21.12 / usr / lib / Xorg vt2 -displayfd -auth or maybe more / run / user / 1000 / gdm / Xauthority -nolisten tcp -background none -noreset -keeptty -verbose 3 3098 daygeek 23 1929012 351412 120532 S 13.3 2.2 16: 42.51 / usr / lib / firefox / firefox -contentproc -childID6 -isForBrowser -prefsLen 9236 -prefMapSize 184485 -parentBuildID 20190521202118 -greomni / us + 1 Root 20 188820 10144 7708 S 6.7 0.1 0: 06.92 / sbin / init 818 gdm something like 20 199836 25120 15876 S 6.7 0.2 0: 01.85 / usr / lib / Xorg vt1 -displayfd 3 -auth / run / user / 120 / gdm / Xauthority -nolisten tcp -background none -noreset -keeptty -verbose 3 1170 daygeek 9-11 2676516 16516 12520 S 6.7 0.1 1: 28.30 / usr / bin / pulseaudio --daemonize = no 8271 Root 20 I 6. - 0: 00.21 [kworker / u16: 4-i915] 9117 Daygeek 18 13528 4036 3144 R 6.7 0.0 0: 00.01 top -md1+ ------------------------------------------------- --------------- - -
Speed up your computer's performance now with this simple download.