<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Add a New Graph</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="The Cacti Manual" HREF="index.html"><LINK REL="UP" TITLE="Command Line Scripts" HREF="scripts.html"><LINK REL="PREVIOUS" TITLE="Associate a Graph Template to an existing Host" HREF="cli_add_graph_template.html"><LINK REL="NEXT" TITLE="Add Items to a Tree" HREF="cli_add_tree.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="manual.css"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >The Cacti Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="cli_add_graph_template.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 20. Command Line Scripts</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="cli_add_tree.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="CLI_ADD_GRAPHS" >Add a New Graph</A ></H1 ><P >You won't stop now as you've just created a device from cli. Surely, the task of setting up graphs is the next step. This is done using <TT CLASS="FILENAME" >add_graphs.php</TT >. Calling the script with the parameter <KBD CLASS="USERINPUT" >--help</KBD > yields</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php Add Graphs Script 1.2, Copyright 2008 - The Cacti Group A simple command line utility to add graphs in Cacti usage: add_graphs.php --graph-type=[cg|ds] --graph-template-id=[ID] --host-id=[ID] [--graph-title=title] [graph options] [--force] [--quiet] For cg graphs: [--input-fields="[data-template-id:]field-name=value ..."] [--force] --input-fields If your data template allows for custom input data, you may specify that here. The data template id is optional and applies where two input fields have the same name. --force If you set this flag, then new cg graphs will be created, even though they may already exist For ds graphs: --snmp-query-id=[ID] --snmp-query-type-id=[ID] --snmp-field=[SNMP Field] --snmp-value=[SNMP Value] [--graph-title=] Defaults to what ever is in the graph template/data-source template. [--reindex-method=] the reindex method to be used for that data query if data query already exists, the reindex method will not be changed 0|None = no reindexing 1|Uptime = Uptime goes Backwards (Default) 2|Index = Index Count Changed 3|Fields = Verify all Fields List Options: --list-hosts --list-graph-templates [--host_template=[ID]] --list-input-fields --graph-template-id=[ID] --list-snmp-queries --list-query-types --snmp-query-id [ID] --list-snmp-fields --host-id=[ID] [--snmp-query-id=[ID]] --list-snmp-values --host-id=[ID] [--snmp-query-id=[ID]] --snmp-field=[Field] 'cg' graphs are for things like CPU temp/fan speed, while 'ds' graphs are for data-source based graphs (interface stats etc.)</PRE ><P >Like the graph creation from the console, this task is split into two different ones:</P ><P ></P ><UL ><LI ><P ><SPAN CLASS="GUIMENUITEM" >Associated Graph Templates</SPAN >: These are named <KBD CLASS="USERINPUT" >cg</KBD > graph_type for this script.</P ></LI ><LI ><P ><SPAN CLASS="GUIMENUITEM" >Associated Data Queries</SPAN >: These are named <KBD CLASS="USERINPUT" >ds</KBD > graph_type for this script. Additional SNMP parameters are required to define those graphs.</P ></LI ></UL ><DIV CLASS="CAUTION" ><P ></P ><TABLE CLASS="CAUTION" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Exact typing required</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >When running this cli script, caution must be taken to avoid typos. Sometimes, list options take an ending <SPAN CLASS="QUOTE" >"s"</SPAN >, where the option for graph creation comes without <SPAN CLASS="QUOTE" >"s"</SPAN >. Error messages are not issued to indicate this typo; instead you will see the general help screen.</P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="SECT2" ><H2 CLASS="SECT2" ><A NAME="CLI_ADD_GRAPHS_LIST_CG" >List Options for Associated Graph Templates</A ></H2 ><P >The first list option, <KBD CLASS="USERINPUT" >--list-hosts</KBD >, is required only if you do not know the <KBD CLASS="USERINPUT" >id</KBD > of the device you want to add graphs for. It will produce output as follows</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --list-hosts Known Hosts: (id, hostname, template, description) ... 11 router.mydomain.com 3 Device Add Test</PRE ><P >You surely recognize the device we've just added?</P ><P >The next list option, <KBD CLASS="USERINPUT" >--list-graph-templates</KBD >, is required to identify the number of an <KBD CLASS="USERINPUT" >Associated Graph Templates</KBD >.</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --list-graph-templates Known Graph Templates:(id, name) 2 Interface - Traffic (bits/sec) 3 ucd/net - Available Disk Space 4 ucd/net - CPU Usage 5 Karlnet - Wireless Levels 6 Karlnet - Wireless Transmissions 7 Unix - Ping Latency 8 Unix - Processes 9 Unix - Load Average ...</PRE ><P >We will need the graph template id of the <KBD CLASS="USERINPUT" >ucd/net - CPU Usage</KBD > template later. So note the number <KBD CLASS="USERINPUT" >4</KBD > for it.</P ><P >It is possible to reduce the listing to the graph templates associated with a specific host template by using <KBD CLASS="USERINPUT" >--list-graph-templates --host-template-id=[id]</KBD >. For a "ucd/net SNMP Host" this yields</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --list-graph-templates --host-template-id=3 Known Graph Templates:(id, name) 4 ucd/net - CPU Usage 11 ucd/net - Load Average 13 ucd/net - Memory Usage...</PRE ></DIV ><DIV CLASS="SECT2" ><H2 CLASS="SECT2" ><A NAME="CLI_ADD_GRAPHS_LIST_DS" >List Options for Associated Data Queries</A ></H2 ><P >First task is to find all id's for available data queries.</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --host-id=2 --list-snmp-queries Known SNMP Queries:(id, name) 1 SNMP - Interface Statistics 2 ucd/net - Get Monitored Partitions 3 Karlnet - Wireless Bridge Statistics 4 Netware - Get Available Volumes 6 Unix - Get Mounted Partitions 7 Netware - Get Processor Information 8 SNMP - Get Mounted Partitions 9 SNMP - Get Processor Information</PRE ><P >For standard interface statistics, we note the id of <KBD CLASS="USERINPUT" >1</KBD ></P ><P >Next task is to find the query_type as done by issuing</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --snmp-query-id=1 --list-query-types Known SNMP Query Types: (id, name) 2 In/Out Errors/Discarded Packets 3 In/Out Non-Unicast Packets 4 In/Out Unicast Packets 9 In/Out Bytes (64-bit Counters) 13 In/Out Bits 14 In/Out Bits (64-bit Counters) 16 In/Out Bytes 20 In/Out Bits with 95th Percentile 21 In/Out Bits with Total Bandwidth 22 In/Out Bytes with Total Bandwidth 23 In/Out Bits 1 min 24 In/Out Bits 1 min (64-bit Counters)</PRE ><P >For a standard <KBD CLASS="USERINPUT" >In/Out Bits</KBD > type, we note the id of <KBD CLASS="USERINPUT" >13</KBD ></P ><P >Next issue is to select the <KBD CLASS="USERINPUT" >SNMP Field</KBD > that shall be used for a new graph.</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --host-id=11 --list-snmp-fields Known SNMP Fields for host-id 11: (name) ifAlias ifDescr ifHwAddr ifIndex ifIP ifName ifOperStatus ifSpeed ifType</PRE ><P >For our graph, we will use the field <KBD CLASS="USERINPUT" >ifOperStatus</KBD > to select the correct interfaces.</P ><P >In general, you will next determine the values available for the <KBD CLASS="USERINPUT" >SNMP Field</KBD >, in our case <KBD CLASS="USERINPUT" >ifOperStatus</KBD >. This is done by</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --host-id=11 --snmp-field=ifOperStatus --list-snmp-values Known values for ifOperStatus for host 11: (name) Down Up</PRE ><P >This is no surprise, of course. Now, all paarmeters required for creating a new graph are determined.</P ></DIV ><DIV CLASS="SECT2" ><H2 CLASS="SECT2" ><A NAME="CLI_ADD_GRAPHS_CG" >Add Non-Indexed Graphs</A ></H2 ><P >We will create a graph for <KBD CLASS="USERINPUT" >ucd/net - CPU Usage</KBD >. Above, we've identified the graph template it to be <KBD CLASS="USERINPUT" >4</KBD >. In total, that makes up for the following command</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --host-id=11 --graph-type=cg --graph-template-id=4 Graph Added - graph-id: (39) - data-source-id: (63)</PRE ><P >Find the result when visiting <SPAN CLASS="GUIMENU" >Graph Management</SPAN ></P ><PRE CLASS="SCREEN" >Graph Title** Template Name Size Device Add Test - CPU Usage ucd/net - CPU Usage 120x500</PRE ><P >If the graph template was not associated with that host before, it is now added to the list of <SPAN CLASS="GUIMENU" >Associated Graph Templates</SPAN >.</P ></DIV ><DIV CLASS="SECT2" ><H2 CLASS="SECT2" ><A NAME="CLI_ADD_GRAPHS_DS" >Add Indexed Graphs</A ></H2 ><P >First, let's sum up the id's of all resources required for this task:</P ><DIV CLASS="TABLE" ><A NAME="AEN3330" ></A ><P ><B >Table 20-2. Parametes required for an Interface Traffic Graph</B ></P ><TABLE BORDER="1" FRAME="border" RULES="all" CLASS="CALSTABLE" ><COL><COL WIDTH="1*"><COL WIDTH="3*"><THEAD ><TR ><TH ALIGN="CENTER" >Object</TH ><TH ALIGN="CENTER" >Value</TH ><TH ALIGN="CENTER" >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD >Graph Template Id</TD ><TD ALIGN="RIGHT" >2</TD ><TD >Interface - Traffic (bits/sec)</TD ></TR ><TR ><TD >SNMP Query Id</TD ><TD ALIGN="RIGHT" >1</TD ><TD >SNMP - Interface Statistics</TD ></TR ><TR ><TD >SNMP Query Type Id</TD ><TD ALIGN="RIGHT" >13</TD ><TD >In/Out Bits</TD ></TR ><TR ><TD >SNMP Field</TD ><TD ALIGN="RIGHT" >ifOperStatus</TD ><TD > </TD ></TR ><TR ><TD >SNMP Value</TD ><TD ALIGN="RIGHT" >Up</TD ><TD > </TD ></TR ></TBODY ></TABLE ></DIV ><P >This will make up for the following command</P ><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >shell></SAMP >php -q add_graphs.php --host-id=11 --graph-type=ds --graph-template-id=2 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifOperStatus --snmp-value=Up Graph Added - graph-id: (40) - data-source-id: (65)</PRE ><P >Find the result when visiting <SPAN CLASS="GUIMENU" >Graph Management</SPAN ></P ><PRE CLASS="SCREEN" >Graph Title** Template Name Size Device Add Test - CPU Usage ucd/net - CPU Usage 120x500 Device Add Test - Traffic - lo Interface - Traffic (bits/sec) 120x500</PRE ><P >If the data query was not associated with that host before, it is now added to the list of <SPAN CLASS="GUIMENU" >Associated Graph Templates</SPAN >. In this case, the <SPAN CLASS="GUIMENU" >Re-Index Method</SPAN > of <CODE CLASS="PARAMETER" >Uptime Goes Backwards</CODE > is defaulted if not given otherwise. You may provide a different <SPAN CLASS="GUIMENU" >Re-Index Method</SPAN > by entering the optional parameter <CODE CLASS="PARAMETER" >--reindex-method</CODE >.</P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="cli_add_graph_template.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="cli_add_tree.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Associate a Graph Template to an existing Host</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="scripts.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Add Items to a Tree</TD ></TR ></TABLE ></DIV ></BODY ></HTML >