G
G
giggigi2013-08-12 16:14:55
linux
giggigi, 2013-08-12 16:14:55

Human-readable logging of cron jobs?

Hello. There was one problem - once a day the load on the server is greatly increased.
Because this is repeated at the same time - suspicion falls naturally on tasks launched by cron. The task is to track what exactly creates a large load in order to optimize it.
Because We have a lot of tasks in the crown, different scripts are launched, it will take quite a long time to add some kind of logging system of our own, I want to add something within a couple of hours in order to track it today and start fixing it tomorrow.
Perhaps there is some kind of logging system that can at least log everything that is launched by cron and, ideally, somehow combine this with displaying the load by tasks? Or maybe someone has other ideas?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
@
@sledopit, 2013-08-12
_

Wait, so you know the time this is happening? Why can't you just see what exactly was running at that moment?
Cron writes everything to syslog. grep CRON /var/log/syslog and find the right time.
Or do you have such a large kroner that a hundred tasks per minute are launched there?

R
rozhik, 2013-08-12
@rozhik

want to add something in a couple of hours

Replace in cron
1 2 3 4 5 /bin/task1
with
1 2 3 4 5 /bin/taskRun.sh
In taskRun.sh
#!/bin/bash
date 2>&1 >> /var/log/task1
time /bin/task1 2>&1 >> /var/log/task1
cat /proc/meminfo >> /var/log/task1
cat /proc/loadavg >> /var/log/task1

Many lines of statistics will be displayed at the end of the script +
Mon Aug 12 14:21:21 UTC 2013
real 1m8.818s
user 0m35.090s
sys 0m1.332s
Although it would be more correct to do the same through logger. But as above, it's faster, you don't need to worry about the syslog config

M
mrstrictly, 2013-08-12
@mrstrictly

1. For processes run by cron, the parent process is called CRON and its ppid corresponds to the cron process. Example:

root 514 1 0 Aug 10 ? 00:00:00 cron
...
root 21227 514 0 17:30 ? 00:00:00 CRON
root 21228 21227 0 17:30 ? 00:00:00 /bin/sh -c sleep 1

2. The CPU load of a specific process can be obtained with the command
ps u -p <pid>

Thus, your task is to ensure that in your cron logger:
1. Calculate all processes whose parent process name is CRON.
2. For these processes, collect the load on the CPU.
3. Beautifully output to a file.
Hope this helps.

1
1x1, 2013-08-12
@1x1

you can write a script on your knee that calls all the cron commands, like this:

#!/bin/sh
/bin/date >> /var/log/smth
"[email protected]"
/bin/date >> /var/log/smth
/usr/bin/uptime >> /var/log/smth
/usr/bin/iostat -x 1 1 >> /var/log/smth

R
rozhik, 2013-08-12
@rozhik

Choose what you want. There are many options ;)man time
The solution is to write to the same file, and not output : [ -o FILE ] [ --append ] that is,
time -o /var/log/log --append command
Sorry, I wrote from memory, now I'm out time outputs to the console and not to stder ;)

P
Puma Thailand, 2013-08-12
@opium

And what prevents you from entering the server at this time and seeing the top?

B
bestia, 2013-08-13
@bestia

atop (/usr/ports/sysutils/atop ) can act as a daemon and write stateful files. Then you can view the saved states at any specified point in time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question