20 interessante Sysstat Befehle zum Performance Monitoring

by

Heute werden ich ein paar praktisch interessante Beispiele zu den Linux Tools mpstat, pidstat, iostat und sar zeigen, welche einem z.B. helfen können einen Fehler zu finden. Es gibt verschiedene Optionen um diese Werkzeuge zu verwenden. Damit will ich sagen, das man Kommandos manuell mit verschiedenen Optionen für viele verschiedene Tätigkeiten verwenden kann. Oder man baut sich je nach Anforderungen ein angepasstes shell script. Es ist ja bekannt, dass Sysadmins meist ein wenig faul sind, weswegen Sie ständig nach einfacheren Wegen suchen um die Dinge möglichst einfach und unkompliziert zu lösen.

 

 

mpstat – Processor Statistiken

1.)

Verwendet man den mpstat Befehl ohne Option, so wird der globale Durchschnitt aller CPU Aktivitäten angezeigt.

 

2.)
Verwendet man mpstat mit der Option „-P“ (Prozessornummer) und „ALL“ so werden Statistiken über alle CPUs angezeigt. Die Anzeige startet dabei bei 0. 0 Ist damit der erste Wert


 

3.)
Um die Statistiken für N Anzahl der Iterationen nach n Sekunden-Intervall-Anzeige mit durchschnittlich jeder CPU anzuzeigen geben Sie den folgenden Befehl ein.


 

4.)
Die Option „I“ gibt die Gesamtzahl der Interrupt-Statistiken pro Prozessor aus.


 

5.)
Mit dem folgenden Befehl holen Sie sich alle oben genannten Informationen in einem einzigen Kommando –  d.h. äquivalent zu „-u -I ALL -p ALL“.


 

pidstat – Process and Kernel Threads Statistics

This is used for process monitoring and current threads, which are being managed by kernel. pidstat can also check the status about child processes and threads.

Syntax

6.) Using pidstat command without any argument, will display all active tasks.


 

7.) To print all active and non-active tasks use the option ‘-p‘ (processes).


 

8.) Using pidstat command with-d 2 option, we can get I/O statistics and 2 is interval in seconds to get refreshed statistics.

This option can be handy in situation, where your system is undergoing heavy I/O and you want to get clues about the processes consuming high resources.


 

9.) To know the cpu statistics along with all threads about the process id 4164 at interval of 2 sec for 3 times use the following command with option ‘-t
(display statistics of selected process).


 

10.) Use the ‘-rh‘ option, to know the about memory utilization of processes which are frequently varying their utilization in 2 second interval.


 

11.) To print all the process of containing string “VB“, use ‘-t‘ option to see threads as well.


 

12.) To get realtime priority and scheduling information use option ‘-R‘ .

Here, I am not going to cover about Iostat utility, as we are already covered it.

 

sar – System Activity Reporter

Using “sar” command, we can get the reports about whole system’s performance. This can help us to locate the system bottleneck and provide the help to find out the solutions to these annoying performance issues.

The Linux Kernel maintains some counter internally, which keeps track of all requests, their completion time and I/O block counts etc. From all these information, sar calculates rates and ratio of these request to find out about bottleneck areas.

The main thing about the sar is that, it reports all activities over a period if time. So, make sure that sar collect data on appropriate time (not on Lunch time or on weekend.:)


 

 

13.) Following is a basic command to invoke sar. It will create one file named “sarfile” in your current directory.

The options ‘-u‘ is for CPU details and will collect 5 reports at an interval of 2 seconds.


 

14.) In the above example, we have invoked sar interactively.

We also have an option to invoke it non-interactively via cron using scripts /usr/local/lib/sa1 and /usr/local/lib/sa2 (If you have used /usr/local as prefix during installation time).

  1. /usr/local/lib/sa1 is a shell script that we can use for scheduling cron which will create daily binary log file.
  2. /usr/local/lib/sa2 is a shell script will change binary log file to human-readable form.

Use the following Cron entries for making this non-interactive:

At the back-end sa1 script will call sadc (System Activity Data Collector) utility for fetching the data at a particular interval. sa2 will call sar for changing binary log file to human readable form.


 

 

15. Check run queue length, total number of processes and load average using ‘-q‘ option.


 

 

16.) Check statistics about the mounted file systems using ‘-F‘.


 

17.) View network statistics using ‘-n DEV‘.


 

18.) View block device statistics like iostat using ‘-d‘.

 

19.) To print memory statistics use ‘-r‘ option.


 

20.) Using ‘sadf -d‘, we can extract data in format which can be processed using databases.

You can also save this to a csv and then can draw chart for presentation kind of stuff as below.
That’s it for now, you can refer man pages for more information about each option and don’t forget to tell about article with your valuable comments.