How-to use cacti monitor db

1. Summary

Cacti is an open source graphic tools based on templates. Once you have a template, you can add new host in a few clicks. Reference: http://www.cacti.net/ This blog is based on cacti 0.8.7g.

2. Installation guide

3. Configure view graph without login

1. Create or enable a user, for example Guest.
Go to Console -> User Management, enable use Guest.
Click Guest, set password and don't check "User Must Change Password at Next Login",
Check "View Graphs" in "Realm permissions" section, Click Save.
Now the user Guest can login to view graphs

2. Config the use as Guest user.
Go to the Settings in Configurations section -> Authentication tab -> 
Set Guest User to "guest", click Save.
Now you can open the graphs page without login.

3. Add a link to login page
Go to cacti home at the install directory
cd $CACTI_HOME
vi auth_login.php, add one line after the "Login":
 
     <tr>
         <td><input type="submit" value="Login"></td>
         <td><a href="graph_view.php?action=tree">View graphs without login</a></td>
     </tr>

Now one can go to the login page and click the link above to view graphs.

4. Templates

There are many templates available at http://forums.cacti.net/about15067.html.
I setup these host templates as follows:

  1. * Linux Host (ucd/net-snmp) : for Linux host with SNMP installed, such as MongoDB hosts.
  2. X MongoDB Server HT : for MongoDB, this is home-grown template.
  3. X pushVM Server HT: for pushVM (XPRESSmp ), this is home-grown template.
  4. MySQL Server – Innodb: for MySQL Innodb, this is modified from X MySQL Server HT, the great work of mysql-cacti-templates
  5. MySQL Server – Memory: for Mysql Memory DB, this is modified from X MySQL Server HT.
  6. Cassandra 0.8: for Cassandra, this is modified from http://www.palominodb.com/node/65

5. How-to add servers

1. How-to add DB servers

It's the same for adding different DB type except choose different template as listed above and specified steps as below. Take mytestdb Mysql servers memory db as example:

Console -> Devices -> Add 
   description: mytestdb 
   host name: mytestdb.cacti.com
   Host Template: MySQL Server - Memory 
   Thold Up/Down Email Notification: Global List
   Downed Device Detection: None
   SNMP Version: None
 click Create
 Click "Create Graphs for this Host" at the top
 Check the top box, which will check all for you, then click Create
 
Follow section "10. How-to add host to a Graph tree" to add it to a tree

Confirm: click graphs, should see mytestdb (mytestdb.cacti.com) under MySQL Memory

Special for Cassandra

Special for MongoDB

  • When adding graphs, it will ask for Custom Data “Mongoport”, if mongo is running on port 27017, you can ignore it, just click Save. If mongo is running on other port, input the exact port, for example data nodes of sharding, input 27018.
  • For mongo configdb nodes, please do NOT select graph “X MongoDB ReplicatSet Lag GT”
  • For mongos nodes, ONLY add graph ” X MongoDB Commands GT”, ” X MongoDB Connections GT” and “X MongoDB Memory GT”
  • Add threshold for MongoDB Slave Lag:

Click “Data Sources” → Choose template “X MongoDB Slave Lag DT” → check the host → Choose an action: “Create Threshold from Template”

Special for MySQL DB

For MySQL DB, we need a user named “cacti” created at the db server

CREATE USER 'cacti'@'%' IDENTIFIED BY 'cacti';
GRANT
  CREATE TEMPORARY TABLES,
  LOCK TABLES,
  SUPER,
  PROCESS,
  SELECT,
  SHOW DATABASES,
  SHOW VIEW
ON *.* TO 'cacti'@'%';

To check the privileges of cacti:

select * from information_schema.USER_PRIVILEGES where GRANTEE like '%cacti%';

2. How-to add servers using Linux host template

Currently we separate host template from db template. So host template can be used by all DB hosts with the same OS.

  1. Let SA install SNMP as follows. NoSQL VM template already have it installed.
     install packages:  net-snmp, net-snmp-libs and net-snmp-utils 
     add below line to the top of /etc/snmp/snmpd.conf 
           rocommunity public
     Let snmpd service start automatically      
     
  1. Devices → Add → input “sharedmongo1_host” to Description, “sharedmongo1.cacti.com” to Hostname
  2. choose “* Linux Host (ucd/net-snmp” as Host Template
  3. Choose “Monitor Host”
  4. Thold Up/Down Email Notification, choose “Global List”
  5. Choose “Ping and SNMP” as Downed Device Detection
  6. Choose “Version 1” as SNMP Version
  7. Click “Save”
  8. Click “*Create Graphs for this Host”, choose all “Graph Templates” except “xx ucd 90 Filesystems”
  9. Choose “eth1”, Select a graph type: “In/Out Bits”
  10. Choose ”/data” in area “Data Query [ucd 10 fs]”
  11. Choose the mount point performance you want, eg. “sdb1” (/data), Select a graph type: “Device I/O – Bytes Read/Written”, Click “Create”
  12. Select a graph type: “Device I/O – Reads/Writes”, Choose the mount point performance you want, eg. “sdb1” (/data), Click “Create”
  13. Add the host to the graph tree same as it's DB, reference “10. How-to add host to a Graph tree”
  14. Add thresholds by template, reference “9. How-to add thresholds by templates”.
    • We have thresholds templates for Linux load, memory and disk space separately

6. How-to import templates

Find a templates from Internet and follow its README. 
There are many templates at http://forums.cacti.net/about15067.html.

7. How-to add templates manually

To add a new template, following the below steps:
Add Data Input Methods -> add Data Templates
 -> add Graph Templates -> add Host Templates

8. How-to create thresholds

 1. Click "Threshold Templates"
 2. Click "Add", choose "Data Template", for example "ucd_ssCpuRawIdle"
 3. Click "next", choose ""ucd_ssCpuRawIdle"
 4. Click "Create", change the Template Name to "ucd_ssCpuRawIdle TT", TT ->(Threshold Template)
 5. Check "Disable Restoration Email", so when the value back to normal, no mail send out.
 6. Re-Alert Cycle, choose "Every 15 minutes", so it will send mail every 15 minutes when the value is always abnormal.
 7. Low Warning Threshold: 30, when cpu idle is less than 30, it will send Warning emails.
 8. Low Threshold: 10, when cpu idle is less than 10, it will send Alert emails.
 9. Data Type: exact value. For other cases, like space usage, you can choose percentage.
 10. Warning Notification List: choose "DBA"
 11. Alert Notification List: choose "DBA"
 12. Click Save
 

9. How-to add thresholds by templates

1. Add thresholds in a batch:
Console -> Devices -> Choose Type eg. "X MongoDB Server HT", search lp -> Check all
       -> Choose an action: "Apply thresholds" -> Click Go -> Click Continue.

2. Add thresholds one by one:
Click "Data Sources" under Management section -> choose a data Template to select the Graphs
 -> Choose action "Create Threshold from Template" -> Click Go.
eg: data Template for Linux host: 'ucd_load1min', 'ucd_memAvailReal','Host MIB - Hard Drive Space'

OR

Click "Graph Management" -> choose a Template to select the Graphs
       -> Choose action "Create Threshold from Template" -> Click Go
eg: graph Template for Linux Host: 'xx ucd 01 Load Average', 'xx ucd 10 Memory', 'xx ucd 90 Filesystems'

3. Confirm:
Click "thold" at the top line -> Search eg. "sharedmongo", you will see the thresholds if they are added.

10. How-to add host to a Graph tree

1. For single db, such as MySQL and PushVM, we will add it to the root of the type

Console -> Graph tree -> MySQL Memory -> ADD
  Tree Item Type: Host
  Host:  mytestdb (mytestdb.cacti.com)
 click Create

2. For db cluster, we will create sub-tree for each cluster, like mongo and cassandra, for example:

Console -> Graph tree -> MongoDB -> ADD
  Tree Item Type: Header
  Title:  sharedmongo
  Click Create.
Console -> Devices -> Search: sharedmongo -> Choose all 
  -> Choose an action: Place on a Tree(MongoDB)-> Click Go
  -> Destination Branch: --sharedmongo -> Click Continue.
If sometimes it didn't work (bug?), then you need to the tree and click Save as follows:
Console -> Graph tree -> MongoDB -> click Save.

11. How-to add port option to Mongo templates

1. Modify ss_get_by_ssh_script.php script to accept option port2, which is designed for app port.

[root@vm-mydb02 scripts]# diff  ss_get_by_ssh_script.php   ss_get_by_ssh_script.php.bak
1289,1293c1289,1290
<    if ( !isset($options[port2]) || !$options[port2] ) {
<      return "/export/home/cacti/scripts/getMongoDBStats.pl -h $options[host]";
<    } else {
<      return "/export/home/cacti/scripts/getMongoDBStats.pl -h $options[host] -p $options[port2]";
<    }
---
> #   return "/oracle/home/bin/dbperl /oracle/home/admin/cron/getMongoDBStats.pl -h $options[host]";
>    return "/export/home/cacti/scripts/getMongoDBStats.pl -h $options[host]";

2. Modify EACH mongo in “Data Input Methods” in cacti console.

1) add " --port2 <mongoport>" to the Input String, click Save
<path_php_binary> -q <path_cacti>/scripts/ss_get_by_ssh_script.php --use-ssh FALSE --host <hostname> --port2 <mongoport> --type mongodb --items dk,dl,dm,dn 

2) Click add "Input Fields", add one with "Input Fields" = mongoport, Friendly Name = Mongoport, and check " Allow Empty Input", click Save
<code>

3. Edit each mongo entries in "Data Templates". 
In "Custom Data" section, you will see "Mongoport" at the bottom, check the box before "Use Per-Data Source Value (Ignore this Value)", click Save.

Reference

1. What is this 'm' or 'u' after my numbers in graphs?

10^-18  a - atto
10^-15  f - femto
10^-12  p - pico
10^-9   n - nano
10^-6   u - micro
10^-3   m - milli
0    (no unit)
10^3    k - kilo
10^6    M - mega
10^9    G - giga
10^12   T - tera
10^15   P - peta

2. How-to install plugin thold and monitor

1. Installing the Plugin Architecture (PIA)
   http://docs.cacti.net/manual:087:1_installation.9_pia
2. Installing plugin settings
   http://docs.cacti.net/plugin:settings
3. Installing plugin thold
   http://docs.cacti.net/plugin:thold
4. Installing plugin monitor
   http://docs.cacti.net/plugin:monitor
5. Click "User Management" -> Click username "admin" -> In "Realm Permissions" choose "Plugin Management" -> Save.
   Then you can see a "Plugin Management" menu on the left.
6. Click "Plugin Management", you can see the installed plugins with action icons,
    click the action icons to install/deinstall, enable/disable them 
Advertisements

About Alex Zeng
I would be very happy if this blog can help you. I appreciate every honest comments. Please forgive me if I'm too busy to reply your comments in time.

3 Responses to How-to use cacti monitor db

  1. http://andcarinsurancequotes.com says:

    Some genuinely fantastic articles on this internet site, regards for contribution.

  2. Melissa says:

    Would you mind if I quote a few of your articles as long as I provide credit and sources back to your blog:
    https://alexzeng.wordpress.com/2011/12/15/how-to-use-cacti-monitor-d/.
    I am going to aslo be certain to give you the proper anchor text link using your webpage
    title: How-to use cacti monitor db | Alex Zeng’s Blog. Be sure to let me know if this is ok with you. Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s