SNMP (Simple network Management Protocol), which is one of the most commonly used data acquisition technologies in the field of network and system monitoring. Although this protocol is very simple, but in the large-scale IT environment monitoring, still often encounter a variety of pits, so excellent cloud open source a set of friendly snmpapi, and through this article briefly introduce some of the features of this API, I hope to help you operations Tongren early to avoid some problems.
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/89/BB/wKiom1ga5dSiaFIaAAMLT2dgj0c851.jpg "style=" height : auto;vertical-align:middle;border:0px; "title=" 1.jpg "alt=" Wkiom1ga5dsiafiaaamlt2dgj0c851.jpg "/>
features [0]. provides a solution for resolving various data types Snmpvalue class
In SNMP, there are a variety of data types, light expression of numeric types, there are Gauge32, Integer32, Counter32, Counter64 and so on, and even a kind of universal data type called octetstring, can represent common ASCII strings, IP addresses, MAC addresses, port lists, and so on. Many veteran are often octetstring by the wrong conversion, resulting in the use of the data is meaningless, not to mention the novice face these data types, will be more confused.
The collection results returned by this API use the Snmpvalue class to uniformly encapsulate a variety of original data types, providing a more user-friendly interface, as shown below:
features [1]. to avoid a dead loop. Walk Operation
Walk operation refers to the continuous use of Get-next requests to collect a number of neighboring OIDs of the device, to obtain a batch of related information operations.
From the SNMP specification, the OID arrangement on the device should be ascending and not repeating, but the woods are big and what birds have! Some OIDs can also appear with reverse growth or even simply repeating devices. So it is also common for programmers to write walk operations that will cause a dead loop.
The three features provided by this API can prevent this from happening:
• Compatible OID Reverse growth
• Automatically merge duplicate OIDs, preserving the last value collected by the same OID
• Allows setting a single walk maximum number of results to avoid a dead loop
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/89/B8/wKioL1ga5fzgRR1NAAGXqJ-_vX4652.jpg "style=" height : auto;vertical-align:middle;border:0px; "title=" 2.jpg "alt=" Wkiol1ga5fzgrr1naagxqj-_vx4652.jpg "/>
features [2]. provide Table data type and walktable Operation
Walk operation is a lot of time in the collection of equipment table class information, such as port list, routing table, forwarding and so on.
However, when you use the normal walk operation, only one-dimensional array is returned, and each element corresponds to only one cell in the table. Therefore, in order to extract a complete route records, port information, it is often necessary to constantly iterate through the array, based on the OID and index extract elements. At the same time, due to the fact that the table of the device may have changed during the walk process, it is sometimes possible to encounter the absence of certain cells and the inability to organize valid data.
Therefore, if you use traditional methods to extract information, you will typically write the following complex code:
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/89/B8/wKioL1ga5gmgHG8_AAPURW3VrH8088.jpg "style=" height : auto;vertical-align:middle;border:0px; "title=" 3.jpg "alt=" Wkiol1ga5gmghg8_aapurw3vrh8088.jpg "/>
Using the walktable and table data types in this API can greatly simplify the operation as follows:
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/89/BB/wKiom1ga5hLA2MQuAAIe_VFBi0Q349.jpg "style=" height : auto;vertical-align:middle;border:0px; "title=" 4.jpg "alt=" Wkiom1ga5hla2mquaaie_vfbi0q349.jpg "/>
features [3]. Merging PDU Issue multiple requestoid , significantly improve performance
In the case of SNMP acquisition, a large number of SNMP requests often occur because a large number of get-next operations need to be generated when walk is performed.
For example, to collect a device port table with 48 ports, the number of requests required is:
> 48 (Number of ports) * 22 (Number of fields per port) = 1056 Requests
This API, when designed with reduced request requirements, attempts to consolidate an OID request for more than one field into a single request, drastically reducing the number of packets that need to be emitted.
Also collect a 48 port, which requires the number of requests:
> 48 (Number of ports) * 1 (number of consolidated requests) = 48 requests
Visible 96% reduction in requests.
features [4]. Control SNMP collect frequency to avoid the tube device CPU Soaring
Finally, because some network equipment is older, its CPU performance is weak, and the manufacturer's SNMP agent has a performance flaw, so in the actual SNMP acquisition operation, often occur in the CPU utilization continues at 100%, even more began to appear network data packet loss, Conditions that affect the normal data forwarding function.
This API defaults to frequent 50ms minimum frequency control of access, and this parameter can be adjusted individually by the device being collected, thus effectively avoiding the harmful effects of SNMP acquisition on the device.
In addition to the above characteristics, this set of open Source Library, also provides such as "OID Union and parent-child judgment", "Exception simplification", "V3 parameter simplification", "Table missing fault tolerance" and other excellent features, welcome to use and further complementary features.
The author introduces Yu Junwei cloud software
· It operation and maintenance senior practitioners;
· Research and development results : Network management, System Management, CMDB, ITSM and other products, and successfully built a number of national network operation and maintenance management projects;
· Practice Projects : Open source Community technology promotion, implementation of SNMP protocol stack, research to centralized large-scale clustering technology.
This article is from the "excellent cloud dual-state Operations" blog, please be sure to keep this source http://uyunopss.blog.51cto.com/12240346/1868964
Take less long way! Excellent cloud band you walk through those pits of SNMP