Ok great. I will make sure to do ./cputest.sh in the crontab. Also do you mind providing resources that could help me get better with shell scripting. I want to get better because I feel like I suck right now.
Ok great. I will make sure to do ./cputest.sh in the crontab. Also do you mind providing resources that could help me get better with shell scripting. I want to get better because I feel like I suck right now.
crontab has no notion of relative directory spec as you used in ./cputest.sh.
Use either fully qualified path to a script OR modify your PATH variable include the directory where your script reside.
For the enablement books, everyone has his/her preferences - I'd start by browsing through the FAQ section at these forums.
As long as the let statement will do decimal arithmetic.
It is easier
For one solves the problem of separator. I have a comma separator for float numbers in "top"
x86_64-redhat-linux-gnu
Yes, in pdksh this substitution does not work.
Last edited by nezabudka; 01-03-2019 at 02:54 AM..
This script that monitors when CPU Usage is too high based off the top command.
I am sorry but already this premise is wrong - which is probably not your fault. "Monitoring CPU" has nothing to do at all with looking at how many % of the CPU respourcce is busy at a single moment. It is worthwhile to monitor the CPU usage, mind you, but not in this way. So, here is a (very short and very incomplete) introduction how UNIX (and Linux alike) works:
UNIX is a time-sharing system: that means, when several processes run (seemingly) simultaneous they run in fact one after the other. The first one is given the CPU, runs for a while (microseconds), then it is frozen, the CPU is given the next process, and so on. After a while the first process gets the CPU again and because that happens so fast it seems that all processes run continuously at the same time. You may have noticedthat i spoke about "the CPU" (singular) above. Now modern systems have typically many CPUs (basically a "core" is a CPU, so a 6-core processor is basically 6 processors bonded into one die). In fact UNIX was designed for (with a few restrictions which would lead too far away) any number of processors. If a system has, say, 4 processors and 100 processes to run then 4 processes will run really simultaneous and the "switch" will only happen 25 times on average (the truth is that processes do not always get equal time but for the purpose of this introduction just suppose they do) and everything else works the same.
Also notice that i consequently say "process(es)" and not "programs". A "program" is a file on your disk. When it is loaded into memory, given some necessary resources and is run then this instance is a "process". You could start the same program several times at the same time and it would be one program but different processes (running instances of this program).
Alas, this is not the end of it. There are tasks which can only be done step by step: if i give you a number and tell you to "multiply it by 7, then take the square root of the result, subtract 5 from it, ..." then you could solve that only in the order i presented it to you. Every step needs the result of the last one. But if i give you, say, 50 numbers and ask you to multiply every one by 5 you could hire 50 people, give one number to each of them and the can calculate their number at the same time. In programming there are also tasks that can be "parallelised" and other which can only be done "sequential". Most times a program is a mixture of both types of tasks. For this in programming there is the "thread" model: a thread is a "sort-of" process but without its own environment. Think of it like a shared apartment: each participant has his/her own room but all use the same kitchen and bathroom. So, for things that can be done in parallel a process an create several threads and each one may (given enough resources) use its own CPU thus speeding things up. This is how a process could use more than one CPU and is called "multi-threaded" in opposite to "single-threaded".
After this rather long-winded introduction you probably want to know what that has to do with CPU usage. Well - everything! First, what is "X% CPU usage"? It could be all the processors working at X% capacity on average. It could also be X% of the processors working at 100% and the others doing nothing. Which one it is depends on the nature of the workload: if you have only single-threaded processes then each one will take exactly one processor at a time and chances are some processor does nothing while another works at 100%. If you have only multithreaded processors chances are that all processors are doing something at any point and how much of their capacity is used depends on how many processes and threads are running and/or how much each of them demand.
Systems are built in a way that they meet the demands of the running software but not more - less would hurt the objective of running the software, more would hurt the finances of the company. To determine how much "enough" is is in fact the art of the systems administrator and his/her tuning and monitoring skills. It is natural for a system which is not wildly oversized for its purpose that it sometimes hits the 100% mark, especially with the CPU resource. In itself it only means that every CPU you have assigned to the system serves a purpose. But it doesn't mean there is a shortage on CPU power. At least, just because you hit 90% doesn't mean a shortage in itself. It depends on several other factors if this is indeed a symptom of CPU shortage or not, but simply monitoring average CPU consumption will not tell you at all if this is the case, as i explained above.
My suggestion would be to monitor CPU usage like this: whenever you get a value over some threshhold (say, 90%. IMHO 95% or even 99% would be better suited) you check in intervals of 3 minutes again if it is still the case. If it is for 5 consecutive measurements only then you issue an alarm by e-mail. Everything else will lead to many false alarms as i can tell you because i had once to suffer as the admin of a system "monitored" this way. Every time i was on standby i got 4-5 calls per night - for absolutely no reason at all. Furthermore, a better way to monitor CPU usage is the vmstat command. You may want to read my Little introduction to Performance Tuning about how to interpret its output. There you only have integers from the start so you wouldn't need to convert anything. On the other hand you will not get a "single number" as an answer - which, in fact, is justified. Einstein once said about explanations: "make it as simple as possible but not simpler". The same is true for performance monitoring: instead of a single misleading number you get several values but they will also tell you more about what is going on.
Quote:
Originally Posted by mhannor
The comparison is not working as it should. Its comparing a decimal to a regualar interger. When it send me an email, it send an email and ignores the if statement. I receive an email if its below or above 90.
The reason is that the if-statement (in fact, the test-statement it triggers) is not executed at all. You might want to use the f_Round-function from my ksh-library to create an integer from a float:
Quote:
Originally Posted by vgersh99
ksh doesn't have floating arithmetic
Sorry to correct you but: ksh93 indeed has floats as a data type and can do floating point calculations. It even sports trigonometric functions like sin(x), cos(x), etc.. Floats have to be defined (via typeset) though and ksh88 has no floating point feature, though, but on RHEL the ksh is always a ksh93 (i am rather sure of that as ksh was put under a GPL-like license in 2005).
On top of what bakunin presented eloquently and exhaustively, some comments on your script:
- it doesn't make sense to evaluate one single process from top's output, as several processes can use up considerable CPU power, esp. if you are on a multiuser system, each of whom runs CPU intensive software. And, you seem to rely on the output being sorted by CPU%, which doesn't have to be the case - better control it (-o option).
- why run a handful of commands (head, sed, tail, cat, ...) if using the powerful awk tool anyhow? Use it to do the entire thing!
- top offers the numbers that bakunin alludes to (and that you might want to use) from the shelf, in its output's first line (man top):
Quote:
system load avg over the last 1, 5 and 15 minutes
So, one quite simple approach to your task might look like
To make sure that the locale of the system doesn't interfere, we use the C locale to run top in batch mode for one loop. awk then checks the one minute load average (field 10) - as we saw, the value to check against needs to be carefully chosen - and, depending on the comparison's result, exits with 0 , or 1 , which in turn can be evaluated by the shell to trigger the respective desired action. Be aware that shell and awk have reversed logical meanings of 0 and 1 .
Originally Posted by vgersh99
most likely your High_CPU variable doesn't contain integer value.
Put the script in set -x and debug it from there.
Sorry to correct you but: ksh93 indeed has floats as a data type and can do floating point calculations. It even sports trigonometric functions like sin(x), cos(x), etc.. Floats have to be defined (via typeset) though and ksh88 has no floating point feature, though, but on RHEL the ksh is always a ksh93 (i am rather sure of that as ksh was put under a GPL-like license in 2005).
I hope this helps.
bakunin
Thanks for point that out, bakunin.
Coming from the Solaris world with ksh88 being a default ksh, I always make this mistake assuming the "minimalistic" ksh implementation.
Thanks again.
Hello experts,
we have input files with 700K lines each (one generated for every hour). and we need to convert them as below and move them to another directory once.
Sample INPUT:-
# cat test1
1559205600000,8474,NormalizedPortInfo,PctDiscards,0.0,Interface,BG-CTA-AX1.test.com,Vl111... (7 Replies)
Hi all
I was wondering if its possible to write a script to keep CPU usage at 90%-95%? for a single cpu linux server?
I have a perl script I run on servers with multple cpu's and all I do is max all but one cpu to get into the 90'% utilised area. I now need a script that raises the CPU to... (4 Replies)
Hello Friends,
I am trying to create a shell script which will check the CPU utilization. I use command top to check the %CPU usage. It give s me below output
Cpu states:
CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS
0 0.31 9.6% 0.0% 6.1% 84.3% 0.0% 0.0%... (3 Replies)
Hi All,
I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide
which cpu number (column 2) has maximum value (column 6).
Since the output is displayed/updated every seconds, it's very... (1 Reply)
I am looking for a way to log and graphically display cpu and RAM usage of linux processes over time. Since I couldn't find a simple tool to so (I tried zabbix and munin but installation failed) I started writing a shell script to do so
The script file parses the output of top command through... (2 Replies)
Hi Experts,
I am executing multiple instances(in parallel) of perl script on HP-UX box.
OS is allocating substantial amount of CPU to these perl processes,resulting higher cpu utilization.
Glance always shows perl processes are occupying majority of the CPU resource. It is causing slower... (2 Replies)
Hi all
can any one help me to script monitoring
CPU load avg when reaches threshold value
and disk usage if it exceeds some %
tried using awk but when df -h out put is in two different lines awk doesnt work for the particular output in two different line ( output for df -h is in two... (7 Replies)
I'm writing a bash script to log some selections from a sensors output (core temp, mb temp, etc.) and I would also like to have the current cpu usage as a percentage. I have no idea how to go about getting it in a form that a bash script can use. For example, I would simply look in the output of... (3 Replies)
how can I find cpu usage memory usage swap usage and
I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times
my final destination is monitor process
logical volume usage above X % and number of Logical voluage above
can I not to... (3 Replies)