Embedded if with Monit - monit

I am looking for a service that monitors the CPU of a Unix computer (and that can react according to the load) and thought that Monit could do the job but I am in a difficult situation:
I need, according to the CPU load level (>50% / >75% / >95%), different actions. I wrote those lines:
check system $HOST
if cpu > 50% then exec "one.sh"
if cpu > 75% then exec "two.sh"
if cpu > 95% then exec "three.sh"
But when the CPU load is higher than 95%, monit launches the 3 scripts. I want to monit to launches one the 3 scripts, according to the CPU load.
I looked for embedded if with monit but it does not seem to exist. Otherwise it would have been simple.
Do you have any idea how to make it work?
Have a nice day!
Bibio

What about something like this?
check system $HOST
if cpu > 95% then exec "three.sh"
if cpu > 75% then
if cpu < 95% then exec "two.sh"
if cpu > 50% then
if cpu < 75% then exec "two.sh"

If CPU usage more than 95%, it will always execute all the three scripts.
Better you can prioritize the status in your scripts.
But I am sure, if your CPU usage is between 50-70% for longer run, then it will execute the first scripts (one.sh) alone.

Related

Java daemon process performance testing not getting consistent results

I am trying to test cpu consumption of an agent / daemon process written in Java. To avoid getting skewed by garbage collection, I keep trying longer periods for each profiling run. In the beginning I tried 15 minutes, then later arrived at 2 hours. Yet I just found out that, even with 2 hour runs, I can get very inconsistent results. - One run of 2 hours gave me cpu of 6%, another of 2 hours gave me cpu of 12%.
Any suggestions to get consistent results?
Are you controlling for CPU frequency? If there isn't much work to do, the OS (or CPU itself) might reduce the clock frequency to save power. With an aggressive power-management strategy, the CPU will always run at max when it's running at all, so looking CPU% can be meaningful.
On Linux on a Skylake or later CPU, you might set the EPP for each core to performance, to get it to run at max speed whenever it's running at all.
sudo sh -c 'for i in /sys/devices/system/cpu/cpufreq/policy[0-9]*/energy_performance_preference;do echo performance > "$i";done'
Otherwise maybe measure in core clock cycles (like Linux perf stat java ...) instead of CPU %, or at least look at average clock speed while it was running. (Lower clock speed relative to DRAM can skew things, since a cache miss stall for fewer cycles.)

How to allocate more CPU and RAM to SUMO (Simulation of Urban Mobility)

I have downloaded and unzipped sumo-win64-0.32.0 and running sumo.exe this on a powerful machine (64GB ram, Xeon CPU E5-1650 v4 3.6GHz) for about 140k trips, 108k edges, and 25k vehicles types which are departed in the first 30 min of simulation. I have noticed that my CPU is utilized only 30% and Memory only 38%, Is there any way to increase the speed by forcing sumo to use more CPU and ram, or possibly run in parallel? From "Can SUMO be run in parallel (on multiple cores or computers)?
The simulation itself always runs on a single core."
it appears that parallel processing is not possible t, but what about dedicating more CPU and ram?
Windows usually shows the CPU utilization such that 100% means all cores are used, so 30% is probably already more than one core and there is no way of increasing that with a single threaded application as sumo. Also if your scenario fits within RAM completely there is no point of increasing that. You might want to try one of the several parallelization approaches SUMO has but none of them got further than some toy examples (and none is in the official distribution) and the speed improvements are sometimes only marginal. Probably the best you can do is to do some profiling and find the performance bottlenecks and/or send your results to the developers.

How can I judge cpu load from Redis "INFO CPU"

I know INFO CPU call getrusage to get cpu resource usage.
but the number accumulated since the launch of the Redis instance,see this.
so, I think even if this number is large (eg, used_cpu_user:203.56),but it does not reflect the current cpu load.
I wonder what information should I get from it? or how can i judge cpu load from the command?
Thank you very much.

The "VM Periodic Task Thread" is run every 50 milliseconds, can I tune this?

On a normal hardware today this likely does not hurt ever, but on a Raspberry PI it is a bit annoying that the CPU is woken up every 50 milliseconds even for a java application which currently does absolutely nothing.
I verify with strace, that the "VM Periodic Task Thread" is active every 50 milliseconds. A rough answer of what it does is given here, but can I tune the 50 milliseconds somehow?
try setting -XX:PerfDataSamplingInterval=xxx, the default is 50 and performance sampling matches the description you linked, so that might be it.

Process utilizes more than one core?

Having a dual-core CPU, I notice (on the Windows Task Manager) that some processes can take more than 50% CPU utilization. Knowing that each process can be executed in one cpu core at any given time, I'm expecting that it will utilize maximum 1/n of my n-core cpu. Note that my CPU is not HT capable. Do I misinterpret the value of CPU column?
If a process has multiple threads running, then you can use 100% of your CPU.
Each thread can use 100% of a single core, so you need N running threads in your process to use 100% of a N-core CPU.