Πώς να χρησιμοποιήσει dstat για να ελέγξει τον κεντρικό υπολογιστή Linux/UNIX σας

από Sukrit Dhandhania [[on]] 13 Νοεμβρίου 2008

Linux

Εάν έχετε έναν κεντρικό υπολογιστή Linux που τρέχει στο γραφείο σας ή σε ένα κέντρο στοιχείων για το οποίο είστε αρμόδιοι, θέλετε να διατηρήσετε ένα uptime όπως κοντά σε εκατό τοις εκατό. Σε αυτή την περίπτωση θέλετε να σιγουρευτείτε ότι παρακολουθείτε τον τρόπο με τον οποίο το σύστημα τρέχει. Για να είστε ακριβείς θέλετε να ελέγξετε όλους τους πόρους συστημάτων που συμβάλλουν στο τρέχοντας πρόστιμο συστημάτων που οδηγεί έπειτα σε ένα υψηλό uptime. Η μνήμη, ΚΜΕ, χρήση δίσκων… είναι μερικά από τα πράγματα που θέλετε να παρατηρήσετε. Θα χρησιμοποιούσαμε συνήθως έναν συνδυασμό των εργαλείων που έρχονται με μια εγκατάσταση Linux ή Unix, όπως «ελεύθερος», «κορυφή», «vmstat»… Θα σας εισαγάγω σε ένα εργαλείο που σας δίνει ακριβώς για όλες τις πληροφορίες ότι τα άλλα εργαλεία που συνδυάζονται σας δίνουν, όλοι κάτω από μια στέγη - Dstat. Ο υπεύθυνος για την ανάπτυξη αυτού του εργαλείου γραμμών εντολής, Dag Wieers, προσκλήσεις αυτό «μια ευπροσάρμοστη αντικατάσταση για το vmstat, iostat, netstat και ifstat». Προσθέτει ότι «Dstat υπερνικά μερικοί από τους περιορισμούς τους και προσθέτει μερικά πρόσθετα χαρακτηριστικά γνωρίσματα…» Σε με Dstat είναι η μητέρα όλων των εργαλείων ελέγχου συστημάτων γραμμών εντολής. Είναι απλό να εγκατασταθεί, εύχρηστος, μπορεί να είναι με την ευκολία, και παράγει τις εκθέσεις που μπορείτε να σχεδιάσετε ως γραφική παράσταση για να εντυπωσιάσετε τον προϊστάμενό σας.

Εγκατάσταση Dstat

Έναρξη με τη μεταφόρτωση του εφαρμοστή Dstat. Δείξτε τη μηχανή αναζήτησης Ιστού σας την αρχική σελίδα του προγράμματος Dstat - http://dag.wieers.com/home-made/dstat/. Ο κύλινδρος κάτω στο τμήμα της σελίδας όπου μεταφορτώνει παρατίθεται. Επιλέξτε τη γεύση Linux στην οποία θέλετε να εγκαταστήσετε την εφαρμογή και να χτυπήσετε μεταφορτώνετε τη σύνδεση. Τώρα μεταφορτώστε την πιό πρόσφατη έκδοση Dstat για την έκδοση της διανομής Linux που τρέχετε. Θα σας παρουσιάσω πώς να το κάνω για μια κόκκινη έκδοση 4 επιχειρηματικού Linux καπέλων μηχανή:

# wget http://dag.wieers.com/rpm/packages/dstat/dstat-0.6.6-1.el4.rf.noarch.rpm

Τώρα εγκαταστήστε Dstat:

# περιστροφή/λεπτό - Uvh dstat-0.6.6-1.el4.rf.noarch.rpm

Εάν η εγκατάσταση πήγε εν τούτοις χωρίς λάθη, αυτό είναι αυτή, έχετε Dstat που εγκαθίσταται και έτοιμο για τη χρήση. Εάν υπεάρξε μερικές εξαρτήσεις που εμφανίστηκαν κατά τη διάρκεια της εγκατάστασης εγκαθιστούν ακριβώς τις απαραίτητες συσκευασίες και προσπαθούν πάλι. Δεν σκέφτομαι ότι Dstat έχει πάρα πολλές εξαρτήσεις, έτσι δεν πρέπει να αντιμετωπίσετε οποιαδήποτε προβλήματα.

Χρησιμοποίηση Dstat

Με Dstat που εγκαθίσταται στο σύστημά σας πρέπει να είστε καλοί να πάτε. Αρχίστε με την προώθηση της εντολής από ένα τερματικό:

# dstat

Η παραγωγή θα ήταν κάτι σαν τον ακόλουθο. Χτυπήστε το βασικό συνδυασμό ctrl+c στην έξοδο.

# dstat
—-total-cpu-usage—- -disk/total -net/total- —paging– —system–
usr sys idl wai hiq siq|_read write|_recv _send|__in_ _out_|_int_ _csw_
7 1 91 1 0 0| 0 0 | 0 0 | 0 0 | 0 0
1 0 99 0 0 0| 0 0 | 0 0 | 0 0 |1051 1945
0 0 100 0 0 0| 0 12k|2269B 11.2k| 0 0 |1031 1923
1 0 99 0 0 0| 0 40k| 0 0 | 0 0 |1078 2235
0 0 100 0 0 0| 0 16k|6027B 21.5k| 0 0 |1008 2219

There are a number of options available for Dstat. As I mentioned earlier Dstat is quite easy to tweak. So if you want to limit the data reading to the CPU, disk, and network, run the following command:

# dstat -CDN
-disk/total -net/total- —paging– —system–
_read write|_recv _send|__in_ _out_|_int_ _csw_
0 0 | 0 0 | 0 0 | 0 0
0 12k|2295B 9603B| 0 0 |1053 1957
0 0 | 594B 0 | 0 0 |1002 1893
0 960k| 292B 3346B| 0 0 |1072 2012
0 4096B| 64B 0 | 0 0 |1031 1939

You can find more options in the application’s help document which you can access by entering the following:

# dstat -h

Play with the options a little so you get comfortable with them. The default interval between data reads is two seconds. You can change that interval if you need to. To increase the interval to ten seconds enter the following:

# dstat 10

Another useful feature is to get aggregated updates for each entry. So you can have Dstat give you an update every ten seconds in a new line, but as the data changes your line itself gets updated every second.

You might optionally want Dstat to give you five updates with a frequency of three seconds. Here’s how you would go about doing that:

# dstat 3 5
—-total-cpu-usage—- -disk/total -net/total- —paging– —system–
usr sys idl wai hiq siq|_read write|_recv _send|__in_ _out_|_int_ _csw_
3 1 95 2 0 0| 0 0 | 0 0 | 0 0 | 0 0
2 11 87 1 0 0| 0 180k|2581B 3239B| 0 0 |1136 697
7 8 85 0 0 0| 0 0 | 115k 106k| 0 0 |1603 3985
2 1 98 0 0 0| 0 0 |77.5k 170k| 0 0 |1744 3856
1 0 100 0 0 0| 0 0 |3451B 9993B| 0 0 |1045 149
2 1 94 4 0 0| 0 276k|20.4k 31.1k| 0 0 |1219 804

The feature that I find most useful is the output. Dstat allows you to have the output of a session written into a comma separated file which can later be imported into a spreadsheet application such as Microsoft Excel and the data can be plotted into a graph. Here is how it can be used.

# dstat –output /tmp/dstat_data.csv -CDN

Let the above command run while you run your applications or do your testing on this machine. Hit the key combination of ctrl+c when you are done. Open the file dstat_data.csv with a spreadsheet application such as Microsoft Excel or Open Office. You can then select the columns you want plotted into a graph and let your spreadsheet application do the magic.

Get a Report by Mail

There may be cases wherein you want to observe how your server is performing over a period of time. You can setup a background process in Linux that will give you a reading with a certain interval, generate a report, and mail out the file to you. This can be especially useful during a stress-test. Here’s how you could do that. The following script will run Dstat for three hours, reading the data every 30 seconds, and will mail out the report to me@myemailid.com.

#!/bin/bash
dstat –output /tmp/dstat_data_mail.csv -CDN 30 360
mutt -a /tmp/dstat_data_mail.csv -s “Dstat Report for 3 hour run” me@myemailid.com

Save the above script in a file called dstat_script.sh on your server, give it executable permission and then run it as a background process:

# chmod +x dstat_script.sh
# nohup ./dstat_script.sh &

Done. Yes, it’s that simple. You will now be mailed this report after it’s done running. You can optionally schedule this script as a daily cron job so that you can receive this data every day.

As you may already have realized Dstat is a wonderful tool when applied to performance monitoring and debugging. The granularity, frequency, and nature of the data collected are completely up to you. Dstat empowers you to know what is going on on your server. Used wisely this power can result in a lot less sleepless nights for you.

If this post helped you, I would be extremely grateful if you could take 3 minutes (I timed it) to complete this survey. If you enter your email address at the end of the survey, you'll be entered into a contest to win a $25 USD Amazon Gift Certificate. You do not need to enter your name or email address (though you won't be entered into the contest) to complete the survey. No personally identifiable information is gathered. If you do opt to enter the contest, your email address will not be sold or used for any kind of communication, other than to notify you if you won the contest. After the contest ends all email addresses will be deleted. Thanks very much in advance!!
Related Posts:
  • How to monitor your Mac laptop’s battery health
  • How to monitor your Internet bandwidth usage in OS X
  • How to monitor your Internet bandwidth usage in OS X, redux
  • How to share a keyboard and mouse with multiple computers
  • How to use the DD-WRT firmware to monitor your bandwidth
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.

    { 2 comments… read them below or add one }

    1 perfector 12.12.08 at 12:59 am

    Nice article.

    2 oberf?rster 01.21.09 at 8:15 am

    I’ve just found a little discrepancy between dstat and dd regarding the I/O:

    ifx@ids:/opt/informix/devices$ dd if=file_20GB of=/dev/null bs=2048 count=10000000
    10000000+0 Datens?tze ein
    10000000+0 Datens?tze aus
    20480000000 Bytes (20 GB) kopiert, 261,738 s, 78,2 MB/s

    A shell running dstat at the same time showed me:

    -dsk/total—-dsk/hdc—–dsk/hdd–
    read writ: read writ: read writ
    140M 104k: 62M 24k:7960k 28k
    150M 0 : 64M 0 : 12M 0
    160M 0 : 0 0 : 80M 0
    154M 0 : 43M 0 : 34M 0
    150M 0 : 75M 0 : 0 0
    153M 56k:8384k 20k: 68M 8192B

    So it looks like we all should use dstat if we want to impress people with big numbers.

    Looks also like you shouldn’t compare dstat to something else than dstat if you really want to compare systems, I doubt I’ll use it any more for this kind of stuff any more.

    Leave a Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>