How to use cacti to get the custom information sent by snmp? Figure

  

First, the actual demand server runs lighttpd, mainly to count the current number of connections, then cacti to draw the statistics of the current number of connections: here are a few A method to achieve this function: 1, snmpget direct value, often inaccurate value: # snmpget -c public -v 2c 127.0.0.1 .1.3.6.1.2.1.6.9.0 TCP-MIB::tcpCurrEstab .0 = Gauge32: 0 2. Use snmp to fetch all links and count the number of rows. Although the information is accurate, but the efficiency is low, if the monitoring point exceeds thousands, then almost all data is timeout: # snmpget -c public -v 2c 127.0.0.1 .1.3.6.1.2.1.6.13.1.3 | Wc -l 725 3. After writing script statistics on this machine, use snmp to send information, cacti collects and draws the picture, and the specific method; Second, the solution snmp provides the function of sending customized information. Looking at snmpd.conf will see a section about external scripts, Executables/scripts. This section also gives examples of how to send information via snmp. Add a line anywhere in snmpd.conf: exec .1.3.6.1.4.1.2021.18 tcpCurrEstab /etc/tcpconn.sh where tcpCurrEstab is the name of the command, followed by the command and parameters. The name of the command can be taken casually. The result of the script execution is similar to the following: # /etc/tcpconn.sh 80 The contents of the script are as follows: $ cat tcpconn.sh #!/bin/sh conn=`netstat -s -t |  Grep connections\\ established | Awk '{print $1}'` echo $conn Restart snmpd, then remotely receive data from snmpwalk and see:

# snmpwalk -c public -v 2c 127.0.0.1 .1.3.6.1.4.1.2021.18 UCD -SNMP-MIB::ucdavis.18.1.1 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.18.2.1 = STRING: "tcpCurrEstab" UCD-SNMP-MIB::ucdavis.18.3.1 = STRING: " ;/etc/tcpconn_total.sh" UCD-SNMP-MIB::ucdavis.18.100.1 = INTEGER: 0 UCD-SNMP-MIB::ucdavis.18.101.1 = STRING: "488" UCD-SNMP-MIB:: Ucdavis.18.102.1 = INTEGER: 0 UCD-SNMP-MIB::ucdavis.18.103.1 = "" where we need UCD-SNMP-MIB::ucdavis.18.101.1 = STRING: “488″ This line:

# snmpwalk -v 1 192.168.1.201 -c public .1.3.6.1.4.1.2021.18.101.1 UCD-SNMP-MIB::ucdavis.18.101.1 = STRING: "488" Once the data is collected, you can configure cacti to receive it. In the cacti interface, console->Templates->Data Templates, and then click Add in the upper right corner. The name in Data Templates is the name given to this data template. The name in the Data Source will be displayed in Data Sources. I will add it here. “;| Host_description|  - Tcp Conn. - ESTBLISHED”, select get snmp data, Internal Data Source Name can also be added, this is used to name the rrd file. After setting, you can save. After save, you will find some more options. Add the OID of the data we need to the bottom of the file. 1.1.3.6.1.4.1.2021.18.101.1”, you can save it. After that you need to create a Graph Templates so that cacti can generate images. In the cacti interface, console->Templates->Graph Templates, and then click Add in the upper right corner. The name in Templates is the name given to the data template. The name in the Graph Template is the content displayed in the middle of the image in the future. Add here “| Host_description|  - Tcp Conn. - ESTBLISHED”, others keep the default, and some options will appear after saving. Add an item in the Graph Template Items, select the data source before the selection, color select the color of a picture, Graph Item Type select AREA, which is the area, you can also choose other lines, Text Format setting instructions. Then add one, Graph Item Type selects GPRINT, Consolidation Function selects LAST, which is the current value, and Text Format enters current. You can also add some annotations such as Graph Item Type to COMMENT. Now just add this drawing template to the host and you can see the drawn picture. Attached: CUP usage script #!/bin/sh idle=`sar -u 1 3 |  Grep Average |  Awk '{print $8}'` used=`echo "100 - $idle" |  Bc -l -s` echo $used echo $idle memory usage script #!/bin/sh used=`/usr/bin/free -m |  Grep Mem | Awk '{print $3}'` total=`/usr/bin/free -m |  Grep Mem | Awk '{print $2}'` echo $used echo $total From: http://www.hiadmin.com/cacti%E8%BF%9B%E9%98%B6%E5%BC%95%E7%94% A8%E4%BA%8C%EF%BC%9A%E4%BD%BF%E7%94%A8cacti%E8%8E%B7%E5%8F%96snmp%E5%8F%91%E9%80%81% E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BF%A1%E6%81%AF%E5%90%8E%E4%BD%9C/

Get the Squid memory cache hit rate as an example.

You can see this example in /etc/snmp/snmpd.conf: # exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest can use scripts that you have written, such as :exec .1.3.6.1.4.1.2021.50 squidmemhits /usr/local/bin/squidmemhits.sh

vi /usr/local/bin/squidmemhits.sh

#!/bin/shPATH =$PATH:/usr/local/squid/binexport PATHsquidclient -t 1 -h localhost -p 3128 mgr:info |  Grep "Memory hits" |  Cut -d "%" -f 2 |  Awk '{print $5}'squidclient -t 1 -h localhost -p 3128 mgr:info |  Grep "Memory hits" |  Cut -d "%" -f 3 |  Awk '{print $3}'/etc/init.d/snmpd restart

Check if you can read the data: snmpwalk -v 2c 192.168.0.200 -c public .1.3.6.1.4.1.2021.50< Br>

UCD-SNMP-MIB::ucdavis.50.1.1 = INTEGER: 1UCD-SNMP-MIB::ucdavis.50.2.1 = STRING: "squidmemhits"UCD-SNMP-MIB::ucdavis.50.3. 1 = STRING: "/usr/local/bin/squidmemhits.sh"

Copyright © Windows knowledge All Rights Reserved