LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-19-2020, 04:46 AM   #1
Andyofhumbleknowledge
LQ Newbie
 
Registered: Nov 2020
Posts: 2

Rep: Reputation: Disabled
Performance stats and count instances of a process - log it to single line in file


I'm trying to analyse the performance of a file processing setup. Client is given files, sends to server for processing, records result and moves files into two folders depending on whether the file is wanted or not. The server's job is more intensive, so the bottleneck is on the server, but the load profiles look odd. It's multi-stage, so some files need analysing at only level1, some need level1 then level2, and some go all the way to level3. At level3, processing speed is directly related to number of times it's running 'interesting process'. Sometimes during the processing of a batch we see a smaller number of these than we expect.

The aim is to get a combination of cpu statistics, number of times 'interesting process' is running and log this out to a file so that we can a) graph what's going on to get a feel of the thing and b) cross-reference this to the logs on the client to find what the client is up to in the slow bits of the batch cycle.

I've tried
Code:
sar
, and it's great for most of the metrics, but I can't find a way to count the instances of 'interesting process' with it.

Currently I'm running:
Code:
watch "uptime | tee -a /path/logfile.txt; pgrep -c processname | tee -a /path/logfile.txt"
This gives me a nice text file with a row every 2 seconds containing
  • a timestamp for the record
  • load averages
  • number of times the machine is running the process I'm interested in

Load average isn't accurate enough, or rather more specifically, it lags too much. I need to include instantaneous CPU usage. I could do with the something like the output from the top row of
Code:
top
or
Code:
sar -u 1 1
, but just appended to the line in the output file, and unlabeled, so that I can then run analysis on it and x-ref to the client logs.

I've also tried adding
Code:
"mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'"
into the watch, but it doesn't work. On its own the command works fine, but when you wrap it into the watch command, you get idle time for each cpu, on separate lines - not funny with multiple cores.

Ideal output would be Timestamp, Number of times 'interesting process' is running, cpu %usr %sys %ni %idle %wait %hi %si

so the data would be

10:04:42, 16, 58.0 us, 26.0 sy, 0.0 ni, 12.0 id, 0.0 wa, 0.0 hi, 0.0 si
10:04:44, 18, 64.0 us, 29.0 sy, 0.0 ni, 7.0 id, 0.0 wa, 0.0 hi, 0.0 si

As a bonus section, is there a way I can add onto the end of the row "percentage of I/O channel to disk used" to help work out if I'm actually I/O bound?

Am I heading the right way or is there a better way? - any ideas appreciated.
 
Old 11-20-2020, 02:33 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by Andyofhumbleknowledge View Post
Am I heading the right way or is there a better way? - any ideas appreciated.
What do you want to achieve at all? What is your goal?

Quote:
Originally Posted by Andyofhumbleknowledge View Post
I'm trying to analyse the performance of a file processing setup. Client is given files, sends to server for processing, records result and moves files into two folders depending on whether the file is wanted or not. The server's job is more intensive, so the bottleneck is on the server, but the load profiles look odd. It's multi-stage, so some files need analysing at only level1, some need level1 then level2, and some go all the way to level3. At level3, processing speed is directly related to number of times it's running 'interesting process'. Sometimes during the processing of a batch we see a smaller number of these than we expect.
I do not really understand it.
Quote:
Originally Posted by Andyofhumbleknowledge View Post
The aim is to get a combination of cpu statistics, number of times 'interesting process' is running and log this out to a file ......
So I guess the goal is to speed things up and probably you want to find a bottleneck.

sar would be a good tool to see the load of the host and to check if you have enough resources.
To analyze a process you need to use different tools, but it depends on the process itself (which language, libraries and other things. do you have sources...).

The load itself is not accurate and actually I would say that is completely useless.
 
Old 11-20-2020, 04:10 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Hmmm - so many misconceptions.
loadavg is not CPU% - go read this - be warned it will make your eyes water.
As for "instantaneous CPU usage", that has precisely 2 values - 0% and 100%. Either a CPU/core/whatever is active or it ain't. The values you see (and want) are time based averages. Usually averages of averages - can you see where this is heading ?.

Piping commands like that add enormous (in CPU terms) latency into the stream - especially the pointless tee. The only way to get semi-sensible metrics is to use a tool that generates sane historical records that you can parse later. sar is too coarse - have a look at collectl or collectd. The interactive commands might be useful for indicative ideas, but post processing is the real answer.

Last edited by syg00; 11-20-2020 at 04:41 AM. Reason: typo
 
1 members found this post helpful.
Old 11-20-2020, 06:59 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

Cross-posted: https://serverfault.com/questions/10...ll-to-single-l

 
Old 11-20-2020, 09:43 AM   #5
Andyofhumbleknowledge
LQ Newbie
 
Registered: Nov 2020
Posts: 2

Original Poster
Rep: Reputation: Disabled
Reply to syg00

Thanks for the pointers.
I'm aware of the difference between loadavg and current usage, and I accept that at a particular instance in time the CPU is either at 100% or 0%.
Yes, what I need is an average, but over a considerably shorter timescale than 1 minute.
Thanks again, I'll have a look at collectl and collectd.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to count number of executions instances does not work. jose_spain Linux - General 7 06-12-2019 04:12 AM
monitoring network stats and user stats robertkwild CentOS 2 11-22-2017 03:54 AM
Count multiple words instances in each line loloingsoc Linux - General 1 06-18-2014 07:09 PM
sendmail-2: Wrong number of instances of process sendmail:, expected instances equal maxymaxymaxymaxymaxy Linux - Newbie 1 06-15-2011 10:51 AM
Get Process size and Thread count for a particular running process haseit Linux - Newbie 2 01-22-2009 11:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration