SAR – Reporter attività di sistema

()

sar – Reporter attività di sistema

Usando il comando ” sar “, possiamo ottenere i rapporti sulle prestazioni dell’intero sistema. Questo può aiutarci a individuare il collo di bottiglia del sistema e fornire l’aiuto per trovare le soluzioni a questi fastidiosi problemi di prestazioni.

Il kernel Linux mantiene un contatore interno, che tiene traccia di tutte le richieste, il loro tempo di completamento e il conteggio dei blocchi I/O, ecc. Da tutte queste informazioni, sar calcola i tassi e il rapporto di queste richieste per scoprire le aree di collo di bottiglia.

La cosa principale del sar è che riporta tutte le attività in un determinato periodo di tempo. Quindi, assicurati che sar raccogliere i dati al momento opportuno (non all’ora di pranzo o nel fine settimana. :)

1 Di seguito è riportato un comando di base per invocare sar. Creerà un file chiamato ” sarfile ” nella directory corrente. Le opzioni ‘ -u ‘ sono per i dettagli della CPU e raccoglieranno 5 rapporti ad un intervallo di 2 secondi.

tecmint@tecmint  ~ $ sar -u -o sarfile 2 5

Linux 3.11.0-23-generic (tecmint.com) giovedì 04 settembre 2014 _i686_ (2 CPU)

01:42:28 CPU IST %user %nice %system %iowait %steal %idle
01:42:30 IST tutti 36.52 0.00 3.02 0.00 0.00 60.45
01:42:32 IST tutti 43,32 0,00 5,04 0,00 0,00 51,64
01:42:34 IST tutti 56.46 0.00 4.05 0.00 0.00 39.49
01:42:36 IST tutti 44.44 0.00 3.79 0.00 0.00 51.77
01:42:38 IST tutti 50.75 0.00 3.75 0.00 0.00 45.50
Media: tutti 46,30 0,00 3,93 0,00 0,00 49,77

2. Nell’esempio sopra, abbiamo invocato sar in modo interattivo. Abbiamo anche un’opzione per invocarlo in modo non interattivo tramite cron usando gli script /usr/local/lib/sa1 e /usr/local/lib/sa2 (se hai usato /usr/local come prefisso durante l’installazione).

  1. /usr/local/lib/sa1 è uno script di shell che possiamo usare per programmare cron che creerà un file di registro binario giornaliero.
  2. /usr/local/lib/sa2 è uno script di shell che cambierà il file di registro binario in un formato leggibile dall’uomo.

Usa le seguenti voci Cron per renderlo non interattivo:

# Esegui lo script shell sa1 ogni 10 minuti per raccogliere dati
*/2 * * * * /usr/local/lib/sa/sa1 2 10

# Genera un rapporto giornaliero in formato leggibile alle 23:53
53 23 * * * /usr/local/lib/sa/sa2 -A

Nel back-end lo script sa1 chiamerà l’ utilità sadc (System Activity Data Collector) per recuperare i dati a un intervallo particolare. sa2 chiamerà sar per modificare il file di registro binario in un formato leggibile dall’uomo.

3. Controllare la lunghezza della coda di esecuzione, il numero totale di processi e la media del carico utilizzando l’opzione ‘ -q ‘.

tecmint@tecmint  ~ $ sar -q 2 5

Linux 3.11.0-23-generic (tecmint.com) giovedì 04 settembre 2014 _i686_ (2 CPU)

02:00:44 IST runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 bloccato
02:00:46 IST 1 431 1,67 1,22 0,97 0
02:00:48 IST 4 431 1,70 1,23 0,97 0
02:00:50 IST 2 431 1,70 1,23 0,97 0
02:00:52 IST 2 431 1,70 1,23 0,97 0
02:00:54 IST 0 431 1,64 1,23 0,97 0
Media: 2 431 1,68 1,23 0,97 0

16. Controllare le statistiche sui file system montati usando ‘ -F ‘.

tecmint@tecmint  ~ $ sar -F 2 4

Linux 3.11.0-23-generic (tecmint.com) giovedì 04 settembre 2014 _i686_ (2 CPU)

02:02:31 IST MBfsfree MBfsused %fsused %fsused Ifree Iused %Iused FILESYSTEM
02:02:33 IST 1001 449 30.95 1213790475088.85 18919505 364463 1.89 /dev/sda1

02:02:33 IST MBfsfree MBfsused %fsused %fsused Ifree Iused %Iused FILESYSTEM
02:02:35 IST 1001 449 30.95 1213790475088.85 18919505 364463 1.89 /dev/sda1

02:02:35 IST MBfsfree MBfsused %fsused %fsused Ifree Iused %Iused FILESYSTEM
02:02:37 IST 1001 449 30.95 1213790475088.85 18919505 364463 1.89 /dev/sda1

02:02:37 IST MBfsfree MBfsused %fsused %fsused Ifree Iused %Iused FILESYSTEM
02:02:39 IST 1001 449 30.95 1213790475088.86 18919505 364463 1.89 /dev/sda1

Riepilogo MBfsfree MBfsused %fsused %ufsused Ifree Iused %Iused FILESYSTEM
Sommario 1001 449 30,95 1213790475088,86 18919505 364463 1,89 /dev/sda1

4. Visualizza le statistiche di rete usando ‘ -n DEV ‘.

tecmint@tecmint  ~ $ sar -n DEV 1 3 | egrep -v lo

Linux 3.11.0-23-generic (tecmint.com) giovedì 04 settembre 2014 _i686_ (2 CPU)

02:11:59 IST IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
02:12:00 IST wlan0 8.00 10.00 1.23 0.92 0.00 0.00 0.00
02:12:00 IST vmnet8 0,00 0,00 0,00 0,00 0,00 0,00 0,00
02:12:00 IST eth0 0,00 0,00 0,00 0,00 0,00 0,00 0,00 0,00
02:12:00 IST vmnet1 0,00 0,00 0,00 0,00 0,00 0,00 0,00

18. Visualizza le statistiche del dispositivo a blocchi come iostat usando ‘ -d ‘.

tecmint@tecmint  ~ $ sar -d 1 3

Linux 3.11.0-23-generic (tecmint.com) giovedì 04 settembre 2014 _i686_ (2 CPU)

02:13:17 IST DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz attendono svctm %util
02:13:18 IST dev8-0 0,00 0,00 0,00 0,00 0,00 0,00 0,00 0,00

02:13:18 IST DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz attendono svctm %util
02:13:19 IST dev8-0 0,00 0,00 0,00 0,00 0,00 0,00 0,00 0,00

02:13:19 IST DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz attendono svctm %util
02:13:20 IST dev8-0 7,00 32,00 80,00 16,00 0,11 15,43 15,43 10,80

5. Per stampare le statistiche della memoria utilizzare l’opzione ‘ -r ‘.

tecmint@tecmint  ~ $ sar -r 1 3

Linux 3.11.0-23-generic (tecmint.com) giovedì 04 settembre 2014 _i686_ (2 CPU)

02:14:29 IST kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
02:14:30 CST 1465660 2594840 63,90 133052 1549644 3710800 45,35 1133148 1359792 392
02:14:31 IST 1472724 2587776 63,73 133060 1549792 3715504 45,40 1125816 1360000 836
02:14:32 IST 1469112 2591388 63,82 133060 1550036 3705288 45,28 1130252 1360168 804
Media: 1469165 2591335 63,82 133057 1549824 3710531 45,34 1129739 1359987 677

6. Utilizzando ‘ safd -d ‘, possiamo estrarre i dati in un formato che può essere elaborato utilizzando i database.

tecmint@tecmint  ~ $ safd -d /var/log/sa/sa20140903 -- -n DEV | grep -v lo

 # hostname;intervallo;timestamp;IFACE;rxpck/s;txpck/s;rxkB/s;txkB/s;rxcmp/s;txcmp/s;rxmcst/s;%ifutil
tecmint;2;2014-09-03 07:53:29 UTC;eth0;1.50;0.00;0.13;0.00;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 07:53:31 UTC;eth0;2.00;0.00;0.18;0.00;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 07:53:33 UTC;eth0;1.00;0.00;0.09;0.00;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 07:53:35 UTC;eth0;2.00;0.00;0.18;0.00;0.00;0.00;0.00;0.00
tecmint;14778;2014-09-03 11:59:54 UTC;eth0;1.78;1.17;1.10;0.18;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 11:59:56 UTC;eth0;3.50;3.00;0.60;0.77;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 11:59:58 UTC;eth0;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 12:00:00 UTC;eth0;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 12:00:02 UTC;eth0;0.50;0.50;0.48;0.03;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 12:00:04 UTC;eth0;2.50;3.50;0.21;2.05;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 12:00:06 UTC;eth0;1.49;1.00;0.62;0.06;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 12:00:08 UTC;eth0;0.50;0.00;0.03;0.00;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 12:00:10 UTC;eth0;0.50;0.50;0.03;0.04;0.00;0.00;0.00;0.00
tecmint;2;2014-09-03 12:00:12 UTC;eth0;1.00;0.50;0.12;0.04;0.00;0.00;0.00;0.00

Puoi anche salvarlo in un CSV e quindi disegnare un grafico per il tipo di presentazione come di seguito.

comando safe
Grafico di rete

Questo è tutto per ora, puoi fare riferimento alle pagine man per ulteriori informazioni su ciascuna opzione e non dimenticare di raccontare l’articolo con i tuoi preziosi commenti.

/ 5
Grazie per aver votato!

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?