![]() ![]() Note that the output.txt will grow, so if you want to reset it daily or weekly, you can "rm" it with another crontab entry. (and a grep + head -1 in the command above if you're only intestered in a single process data). I have much bigger scripts that stay well below 1 CPU usage. 0-59/5 * * * * root top -b -n1 >/tmp/output.txt I want to diplay the Memory usage, Disk Usage and CPU Load in the following format: Memory Usage: 33/512MB (6) Disk usage: 4.2/20GB (23) CPU Load: 0. The script works very well but, for some reason, it has a 10 constant CPU usage (and we are talking about a new generation quad-core Xeon processor. You can start by simply running top -b -n 1 > file.txt (-b for batch mode, -n 1 for running a single iteration of top) and store the output (appended) in the file.txt. Or, with a single execution of top: read CPU MEM > /tmp/file.txt in your /etc/crontab file, by running top every 5 minutes (or any other time interval if you replace the /5 below). The answer to this question can range from a simple command, to complex monitoring tools, depending on your needs. ![]() You can filter also "top" output like top -b -n 1 | grep init to see only the data for the "init" process or top -b -n 1 | grep "init" | head -1 |awk '') ![]() This value is of type float, but cutting off the decimal part will not be a problem.Īnd last, comparing the obtained value with a constant, we determine the need for restarting the process.The answer to this question can range from a simple command, to complex monitoring tools, depending on your needs. Using the formatted '-o pmem=' output, you can get memory consumption in percentage terms. The 'ps' utility is well suited for this, which can take a command name with the option '-C' or the process id with '-p' option. Second, getting value of consumption process memory. For this, I think 'crontab' will work well. If you are ready to make an effort, it is useful to start by breaking the task down into stages.įirst, launching the scheduled task. The script is quite ordinary and writing will take much less time than finding a ready-made solution. In addition,Ĭreation is much more interesting and useful. Therefore, if you have a desire to try to write such a script yourself, then everyone here will readily help you. It's customary to help on this resource, that is, you solve a problem and you don't succeed or you're stuck on something and don't know how to continue. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |