SNMP-Informant Win32 Memory Usage
Out of the box, Cacti for Linux does not include any tools that are capable of monitoring memory utilization on Windows-based systems. This is because Windows memory utilization data is not typically available to Linux-based management systems, since Windows only automatically publishes this data through the Windows Management Instrumentation (WMI) interface, which can only be queried over Windows network protocols, and those are not readily available on Linux. Thus, in order for Windows memory utilization data to be available to Cacti for Linux, the management data must be republished through some kind of interface that Linux is able to access.
In the case of this script template, I have chosen to use SNMP Informant Advanced, which is a WMI-to-SNMP gateway that runs on Windows hosts. Essentially, this tool provides SNMP MIBs for the system-level WMI instrumentation, which in turn allows the WMI data to be queried by any SNMP management station. Once the gateway software is installed and configured, this script template uses a PHP script to query for the necessary MIBs, and then performs any arithmetic or string manipulation that is needed.
For illustration purposes, the sample graph at right shows the memory usage for a Windows host with 768 MB of RAM. In that chart, the amount of real memory that is available to the system is displayed along with the amount of memory that has been reserved for processes ("used real"), the amount that has been allocated for disk caching, the amount that has not been allocated ("unused real"), and also shows the amount of disk space that is currently in use for the c:\pagefile.sys swap file as a pink strip on top.
To use this script template, perform the following steps:
- Obtain a working copy of SNMP Informant Advanced, and install it on the Windows server that you want to monitor.
- Download cacti-snmp-informant-memory.0.5.tar.gz to a temporary directory on the Cacti server machine.
- Expand the archive with the command
tar -xvzf cacti-snmp-informant-memory.0.5.tar.gz, and change to the cacti-snmp-informant-memory directory that is created.
- Copy scripts/ss_informant_memory_usage.php to the <cacti>/scripts/ directory.
- Access the Cacti installation in a web browser, click on the "Import Templates" menu item on the left side of the Console screen, and import the templates/snmp-informant_memory_graph_template.xml file. Cacti should automatically create the required graph template, data input method, and data template objects.
- Click on the Devices menu item on the left side of the Console screen, select a Windows host that is running SNMP Informant Advanced, and scroll down to the "Associated Graph Templates " table. Select "Host Memory - SNMP Informant - Memory Usage" in the "Add Graph Template " drop-down box, and click the "Add" button.
- After the Device screen reloads, verify that the "Host Memory - SNMP Informant - Memory Usage" graph template is now present, and then click the "Create Graphs for this Host" link at the top of the page.
- Locate the "Host Memory - SNMP Informant - Memory Usage" graph template, enable the checkbox to its right, and then scroll to the bottom of the page and click the "Create" button.
Note: these files are intended to be used with Cacti 0.8.6 and 0.8.7 and PHP 5.2, and may not operate as expected with other versions.
Script Input and Output
In some cases you may want to execute the script file manually for debugging purposes. The parameters to the script use a fixed structure that is optimized for use with the Cacti poller, but also allows for human interaction.
In particular, the script uses an SNMP protocol "bundle" of the following values, separated by colon characters: In those cases where a value is unneeded (such as SNMP v3 authentication credentials for an SNMP v2 query), or where a default value is adequate (such as the SNMP port number), the value can be omitted.
- hostname: The domain name or IP address of the target device. This value is mandatory.
- version: The version of SNMP to use. The remaining parameter values will be verified against this value, and is mandatory.
- community: The SNMP community string to use. If version 1 or 2 was specified, the community string must be provided. If version 3 was specified, this value will be ignored.
- v3 username: Part of the credentials for SNMP v3 queries. If version 1 or 2 was specified, this value will be ignored.
- v3 password : Part of the credentials for SNMP v3 queries. If version 1 or 2 was specified, this value will be ignored.
- v3 authentication protocol : Part of the credentials for SNMP v3 queries. If version 1 or 2 was specified, this value will be ignored.
- v3 privilege password : Part of the credentials for SNMP v3 queries. If version 1 or 2 was specified, this value will be ignored.
- v3 privilige protocol : Part of the credentials for SNMP v3 queries. If version 1 or 2 was specified, this value will be ignored.
- v3 authentication context : Part of the credentials for SNMP v3 queries. If version 1 or 2 was specified, this value will be ignored.
- port number: The UDP port number for the SNMP daemon on the target device. If a value is not specified, the default value of "161" will be used.
- timeout: The number of seconds to wait for the SNMP query to be executed. If a value is not specified, the Cacti configuration will be read for a locally-defined default value.
Taken as a whole, a valid SNMP bundle for the localhost device using SNMP v2 with the community string of "public" on the default port number and a default timeout would be "localhost:2:public::::::::".
The output from the script contains the all of the data that is needed to populate the RRD file and associated graph template.
The full exchange for these requests, using example data from above, are shown below:
$ php ss_informant_memory.php hostname:2:public:::::::: totalReal:3220090880 availReal:2568044544 memCached:179519488 totalSwap:2145386496 usedSwap:141557760 usedReal:472526848 availSwap:2003828736