Skip to content

Instantly share code, notes, and snippets.

@RusAlex
Last active August 7, 2016 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RusAlex/2c3ccb9e4ef5068a2b880d8f293975e9 to your computer and use it in GitHub Desktop.
Save RusAlex/2c3ccb9e4ef5068a2b880d8f293975e9 to your computer and use it in GitHub Desktop.

Simple load monitoring

First time I met task to monitor the server load. It is time when I started to think about how long I wont need new server? or Will I know when my users will start suffering from site load latency?.

I wanted to know precisely answers to my questions. Therefore started with few simple steps: log server avg load data every minute and visualize this data.

  1. We need a a script to log the load data. It's now very simple.
#!/bin/bash
r=$(cat /proc/loadavg | awk -F' ' '{print $1}')
dt=$(date '+%s')

echo $dt $r >> load.log
  1. Then add line to your crontab
* * * * * load.sh

This will log your load data every minute.

  1. We need visuale our data. The simpliest way is to use gnuplot util with just few commands:
gnuplot -e "set terminal dumb; set xdata time;set timefmt '%s';set
format x '%M';plot 'load.log' using 1:2 with lp;"

This command will give you console visualisation. Like next

  0.7 +-++--+--+---+--+--+--+--+--+--+---+--+--+--+--+--+--+--+---+--+--++-+
      A     +      +     +     +     +      +     +     +     +      +     +
      |                                       'load.log' using 1:2 +--A--+ |
  0.6 +-+                   A                                        A-- +-+
      ||              A     ||                                      +   A  |
      |A             + |   |  |                                    +       |
  0.5 +-+           +  |   |  |                                   A      +-+
      |A           A    | |    A                                  |        |
      | +        --     | |     +                -A              |         |
  0.4 +-+A--    -        A       +       A     A- |              |       +-+
      |       -A                  A     | |    |   |            |          |
      |     A-                     |   |  |   |    |            |          |
      |                             |  |   |  |     |          A           |
  0.3 +-+                           | |    | |      |   A     |          +-+
      |                              A      ||      |  + |    |            |
      |                                     A        |+  |   |             |
  0.2 +-+                                            A    | |            +-+
      |                                                   | |              |
      +     +      +     +     +     +      +     +     +  A  +      +     +
  0.1 +-++--+--+---+--+--+--+--+--+--+---+--+--+--+--+--+--+--+---+--+--++-+
     00    02     04    06    08    10     12    14    16    18     20    22

For me it's enough on start. I do not need any picture generated. I just need to know the dynamic of changing my server load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment