Official website for Linux User & Developer
FOLLOW US ON:
Dec
8

Monitoring your server with tmux

by Joey Bernard

With tmux, you can create a monitoring system allowing you to check on your server remotely and get the perfect overview of what’s happening. Joey Bernard explains how…

Step 13

Disconnecting tmux

The next powerful feature of tmux is the ability to take your session and detach it from the console that you are currently using. To do this, you can use the shortcut key ‘C-b d’. This puts tmux into the background, allowing you to logout of the server if you wish. The great thing is this also works if your connection simply dies, too.

Step 14

Reconnecting tmux

Now that you have a tmux session set up that is monitoring all of the parts of your server that you are interested in, you may want to check in on it. You can log into your server and simply reattach to the existing tmux session with ‘tmux attach-session’.

Step 15

Byobu

There is an alternative program available called Byobu. This program is actually a wrapper around both tmux and screen. It provides a prettier interface to tmux, including a more detailed, two-line status bar at the bottom of the screen. This improved status bar will give you more information, like battery level, CPU frequency and temperature, and even whether there are updates available for your system. These extras are all configurable, and there is even the option of creating a custom notification. You should consider checking Byobu out as a ‘tmux+’ option for your monitoring setup.

Step 16

Naming windows

Once you have your monitoring windows set up, you will likely want to name them so that they are easier to manage. You can do so with the ‘C-b ,’ shortcut. This will rename the current window, and this new name will appear in the list at the bottom of the screen.

Step 17

Configuration files

All of the commands you have used so far to create your monitoring session manually can be done automatically through the use of a configuration file. Each of the shortcuts has an equivalent long command which can be used in the configuration file.

Step 18

Creating windows

To create a new window, you need to add the line ‘new-window’ to the configuration file. When you create this new window, you can give it a target of a current window whose index is where your new window will be inserted.

Step 19

Starting top

Another important option to the ‘new- window’ command is a shell command to execute upon launching the new window. This is where you would place the command to start up ‘top’ within your new window.

Step 20

Naming windows

Naming windows is done through the option ‘-n NAME’. This is important as it makes managing the windows easier. This name gets used to label the window, and it also gets used when you target a window with some particular command through the ‘-t TARGET’ option.

Step 21

Creating panes

To create a pane, you will need to know which window you want to do so in. You can use the ‘split-window’ command, with either the ‘-h’ option for horizontal splitting or ‘-v’ for vertical splitting. Panes are identified through their 0-based index in the current window.

Step 22

Starting tail in a pane

To start up a program in your new pane, you can add the command to the end of your ‘split-window’ tmux command. You can change this at runtime with the tmux command ‘respawn-pane -k -t TARGET-PANE command’, which will kill the current process and start up your new one.

Step 23

Loading a configuration file

After all of this work, you should have a configuration file that will load your entire monitoring session. To do so, you can save it to the default filename ‘~/.tmux.conf’, or you can save it to another filename and load it with ‘tmux -f filename’.

Step 24

What else can you do?

This has only been a start. You can take this and add your own monitoring programs to your tmux session to help in your system administrator duties. You can now connect to your system on a whim and see what is going on in a matter of moments.

Pages: 1 2
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.
    • Warnaud

      Is there a way to make all this in a single configuration file?

    • sam

      Why didn’t you include the tmux.conf for the displayed screenshot?

    • I just farted

      I farted.

    • tomuchan

      Intresting, but why have you choosen those particular monitoring commands? Could you also provide a configuration for automated startup (Is it possible to define how the windows are proportioned). You could also explain how you reconnect after you closed your ssh connection. Finaly, is there a reason to use tmux instead of screen?

    • Pingback: Links 12/12/2012: Linux 3.7 is Out, OpenMandriva | Techrights

    • Pingback: Monitor your server with tmux « 0ddn1x: tricks with *nix

    • http://storify.com/itreflecti445/rubbish-clearance-get-your-entire-waste-removed Stephaine

      I’m not that much of a online reader to be honest but your blogs really nice, keep
      it up! I’ll go ahead and bookmark your site to come back later. Cheers