We currently migrate to MediaWiki from our old installation, but not all content has been migrated yet. Take a look at the Wiki Team page for instructions how to help or browse through our new wiki at wiki.linux-vserver.org to find the information already migrated.

HowTo graph vserver activity with cacti through vserver-stat output

Introduction

[Cacti] is a tool to graph values, based on [RRDTool]. It's a bit like [MRTG] or [cricket].

This document is a HOWTO describing a way to graph vservers activity through the output of the vserver-stat command. This command shows the number of processes, the memory (RSS et VSZ) usage and CPU (system and user) consumption of the vservers hosted on a physical system. We will show only how to graph memory usage.

The network

We assume cacti is already installed, on a host called cacti.dom.tld. This document is based on cacti version 0.8.6g. The machine hosting the vservers is vs-host.dom.tld.

Getting vserver-stat output

To graph values, cacti needs to be able to fetch theses values. The "classical" way to do that is by SNMP. In our case, this is not possible. So we must find a way to get on cacti.dom.tld the output of the vserver-stat command, executed on vs-host.dom.tld.

Many solutions are possible. Here is one possible solution, that is as secure as possible.

  1. On vs-host.dom.tld, create a user account called vs-stat. This account must be unusable : the connexion only show the output of the vserver-stat command
useradd -u 0 -o -s /usr/local/sbin/vserver-stat -m vs-stat
  1. On cacti.dom.tld, create ssh keys pair under the root account, with an empty passphrase
ssh-keygen -t dsa -f ~/.ssh/vs-stat
  1. On vs-host.dom.tld, put the public key in the authorized keys
mkdir ~vs-stat/.ssh
scp root@cacti.dom.tld:.ssh/vs-stat.pub ~vs-stat/.ssh/authorized_keys
  1. On cacti.dom.tld, test the connection (at this point, you should see the output of vserver-stat)
ssh -i vs-stat vs-stat@vs-host.dom.tld
  1. On vs-host.dom.tld, copy the keys in the user account used by your web server, typically apache or httpd
mkdir ~apache/.ssh
cp ~root/.ssh/{vs-stat*,known_keys} ~apache/.ssh/
chown -R apache ~apache/.ssh/

Cacti configuration

Now we can begin the real hard part :-) You must be connected as an administrator on cacti web interface.

Create a new Data Template

Go on Data Template -> New

Click on the Create button. Again, go to the Data Source Item part.

Click on Save

Create a new graph template

Go on Graph Template -> New

Click on the Create button. Go to Graph Template Items -> Add

Click on the Create button. Again, go to Graph Template Items -> Add

Click on the Create button. Again, go to Graph Template Items -> Add

Click on the Create button. Again, go to Graph Template Items -> Add

You can also add items to gprint the average, min or max values.

Click on Save

Create a Data Query

Create the file :

<query>
   <name>VServer stat</name>
   <description>Retrieve vserver-stat output.</description>
   <arg_prepend>|host_hostname|</arg_prepend>
   <script_path>bash |path_cacti|/scripts/vs-stat.sh</script_path>
   <arg_index>index</arg_index>
   <arg_query>query</arg_query>
   <arg_get>get</arg_get>
   <arg_num_indexes>num_indexes</arg_num_indexes>
   <output_delimeter>:</output_delimeter>
   <index_order>vsName</index_order>
   <index_order_type>alphabetic</index_order_type>
   <index_title_format>|chosen_order_field|</index_title_format>

   <fields>
      <vsName>
         <name>vserver name</name>
         <direction>input</direction>
         <query_name>vsName</query_name>
      </vsName>
      <vsCtx>
         <name>Context number</name>
         <direction>input</direction>
         <query_name>vsCtx</query_name>
      </vsCtx>
      <vsProc>
         <name>Number of processes</name>
         <direction>output</direction>
         <query_name>vsProc</query_name>
      </vsProc>
      <vsVsz>
         <name>Virtual memory used</name>
         <direction>output</direction>
         <query_name>vsVsz</query_name>
      </vsVsz>
      <vsRss>
         <name>Real memory used</name>
         <direction>output</direction>
         <query_name>vsRss</query_name>
      </vsRss>
      <vsUserTime>
         <name>CPU user time</name>
         <direction>output</direction>
         <query_name>vsUserTime</query_name>
      </vsUserTime>
      <vsSysTime>
         <name>CPU system time</name>
         <direction>output</direction>
         <query_name>vsSysTime</query_name>
      </vsSysTime>
   </fields>
</query>

Go to Data Query -> Add

Click on Create

Select the newly created query template vs-stat and go to Associated Graph Templates -> Add

Click on Save

Modify Host template