JAVA remote monitoring of IIS status (IIS6 above) via SNMP __java

Source: Internet
Author: User
Tags snmp svn

Because the project needs, has done a remote monitoring IIS6 or IIS6 through the SNMP program. Now share the core source code for everyone.

  Package Com.shine.framework.IIS; Import Java.util.HashMap; Import java.util.List; Import Java.util.Map; Import Com.shine.framework.core.util.SnmpUtils; @SuppressWarnings ("Unchecked") public class Iisutils {/** * Get IIS Data send information * * Totalbytessenthighword This is the total number of bytes sent by the WWW service since service startup In the 32-bit high. * Totalbytessentlowword This is the low 32 bits in the total number of bytes sent by the WWW service since service startup. * Totalbytesreceivedhighword This is the 32-bit high in the total number of bytes received by the WWW service since service startup. * Totalbytesreceivedlowword This is the low 32 bits in the total number of bytes received by the WWW service since service startup. * Totalfilessent This is the total number of files sent by the WWW service since service startup. Totalfilesreceived This is the total number of files received by the WWW * Service since service startup. * * @param IP * @param community * @param port * @return/public static map<string, string> Getiisdatainfo (String IP, String community, int port) {map<string, string> Map = new hashmap<string, string> (); Snmputils snmputils = null; String[] oid = {"1.3.6.1.4.1.311.1.7.3.1.1", "1.3.6.1.4.1.311.1.7.3.1.2", "1.3.6.1.4.1.311.1.7.3.1.3", " 1.3.6.1.4.1.311.1.7.3.1.5 "," 1.3.6.1.4.1.311.1.7.3.1.5 "," 1.3.6.1.4.1.311.1.7.3.1.6 "}; Try {snmputils = new Snmputils (IP, community, port); list<string> dataList = Snmputils.gettableview (OID); Map.put ("Totalbytessenthighword", Datalist.get (0)); Map.put ("Totalbytessentlowword", Datalist.get (1)); Map.put ("Totalbytesreceivedhighword", Datalist.get (2)); Map.put ("Totalbytesreceivedlowword", Datalist.get (3)); Map.put ("Totalfilessent", Datalist.get (4)); Map.put ("Totalfilesreceived", Datalist.get (5)); catch (Exception e) {e.printstacktrace ();} finally {snmputils.close ();} return map; /** * Get IIS Connection Count * * Currentanonymoususers the number of users currently using the WWW service to establish anonymous connections. Currentnonanonymoususers * The number of users currently using the WWW service to establish a non-anonymous connection. Totalanonymoususers This is the total number of users who have established an anonymous connection with the WWW service since service startup. * Totalnonanonymoususers This is the total number of users who have established a non-anonymous connection with the WWW service since service startup. Maxanonymoususers * This is the maximum number of users using the WWW service to establish an anonymous connection since service startup. Maxnonanonymoususers This is the maximum number of simultaneous non-anonymous connections with the WWW * service since service startup. Currentconnections This is the current number of connections established with the WWW service. MaxConnections * This is the maximum number of simultaneous connections established with the WWW service since service startup. Connectionattempts This is the number of connections that have attempted to use the WWW * service since service startup. Logonattempts This is since service startup,Number of attempts to log on to the WWW service. * * * @param IP * @param community * @param port * @return/public static map<string, string> Getiisconnectioninfo (String IP, string community, int port) {map<string, string> Map = new hashmap<string, string> (); Snmputils snmputils = null; String[] oid = {"1.3.6.1.4.1.311.1.7.3.1.7", "1.3.6.1.4.1.311.1.7.3.1.8", "1.3.6.1.4.1.311.1.7.3.1.9", " 1.3.6.1.4.1.311.1.7.3.1.10 "," 1.3.6.1.4.1.311.1.7.3.1.11 "," 1.3.6.1.4.1.311.1.7.3.1.12 "," 1.3.6.1.4.1.311.1.7.3.1.13 "," 1.3.6.1.4.1.311.1.7.3.1.14 "," 1.3.6.1.4.1.311.1.7.3.1.15 "," 1.3.6.1.4.1.311.1.7.3.1.16 "}; try {snmputils = new Snmputils (IP, community, port); list<string> dataList = Snmputils.gettableview (OID); Map.put ("Currentanonymoususers", Datalist.get (0)); Map.put ("Currentnonanonymoususers", Datalist.get (1)); Map.put ("Totalanonymoususers", Datalist.get (2)); Map.put ("Totalnonanonymoususers", Datalist.get (3)); Map.put ("Maxanonymoususers", Datalist.get (4)); Map.put ("Maxnonanonymoususers", dataList. Get (5)); Map.put ("Currentconnections", Datalist.get (6)); Map.put ("MaxConnections", Datalist.get (7)); Map.put ("Connectionattempts", Datalist.get (8)); Map.put ("Logonattempts", Datalist.get (9)); catch (Exception e) {e.printstacktrace ();} finally {snmputils.close ();} return map; /** * Get IIS Request counter Information * * Totaloptions This is the number of HTTP requests made using the OPTIONS method since service startup. Totalgets This is the number of HTTP requests made using the * Get method since service startup. A GET request is the most common HTTP request. Totalposts This is the number of * HTTP requests made using the Post method since service startup. Totalheads This is the number of HTTP requests made using the Head method since service startup. The head * Request usually indicates that a client is querying the status of a document that the request has determined to refresh. Totalputs This is the number of HTTP * requests made using the Put method since service startup. Totaldeletes This is the number of HTTP requests made using the DELETE method since service startup. Delete requests are typically used for file deletion. * Totaltraces This is the number of HTTP requests made using the TRACE method since service startup. The Trace * Request allows the client to view the received content at the end of the request chain and use that information for diagnostics. Totalmove This is the number of HTTP * requests made using the Move method since service startup. Move requests are used for moving files and directories. Totalcopy This is the number of HTTP requests made using the COPY method since service startup. Copy * Requests are used to copy files and directories. Totalmkcol This is the number of HTTP requests made using the Mkcol method since service startup. MKCOL * Requests are used to create a directory on the server. Totalpropfind This is the number of HTTP requests made using the PROPFIND method since service startup. Propfind * Requests to retrieve property values for files and directories. Totalproppatch This is the number of HTTP * requests made using the Proppatch method since service startup. Proppatch requests to set property values on files and directories. Totalsearch This is the number of HTTP * requests that have been made using the SEARCH method since service startup. The search request is used to query the server to find resources that match a set of criteria provided by the client. Totallock This is the number of * HTTP requests made using the LOCK method since service startup. The lock request is used to lock a file for a user, allowing only that user to modify the file. Totalunlock This is the number of HTTP requests made using the UNLOCK * method since service startup. Unlock requests are used to delete file locks. Totalothers this is when the server is started, with the exception of * OPTIONS, *, POST, PUT, DELETE, TRACE, move, COPY, Mkcol, PROPFIND, Proppatch, SEARCH, The HTTP request for the LOCK or * UNLOCK method. Currentcgirequests This is the number of current CGI requests being processed concurrently by the WWW service. * Currentbgirequests This is the number of current ISAPI requests that are being processed concurrently by the WWW service. Totalcgirequests * This is the total number of CGI requests since service startup. Totalbgirequests This is the total number of ISAPI requests received since service startup. * Maxcgirequests This is the maximum number of CGI requests processed by the WWW service at the same time since service startup. Maxbgirequests * This is the maximum number of ISAPI requests processed by the WWW service at the same time since service startup. * * * @param IP * @param community * @param port * @return/public static map<string, string> Getiisrequestinfo (St Ring IP, String community, int port) {map<string, string> Map = new hashmap<string, string> (); Snmputils Snmputils = null; String[] oid = {"1.3.6.1.4.1.311.1.7.3.1.17", "1.3.6.1.4.1.311.1.7.3.1.18", "1.3.6.1.4.1.311.1.7.3.1.19", " 1.3.6.1.4.1.311.1.7.3.1.20 "," 1.3.6.1.4.1.311.1.7.3.1.21 "," 1.3.6.1.4.1.311.1.7.3.1.22 "," 1.3.6.1.4.1.311.1.7.3.1.23 "," 1.3.6.1.4.1.311.1.7.3.1.24 "," 1.3.6.1.4.1.311.1.7.3.1.25 "," 1.3.6.1.4.1.311.1.7.3.1.26 "," 1.3.6.1.4.1.311.1.7.3.1.27 "," 1.3.6.1.4.1.311.1.7.3.1.28 "," 1.3.6.1.4.1.311.1.7.3.1.29 "," 1.3.6.1.4.1.311.1.7.3.1.30 "," 1.3.6.1.4.1.311.1.7.3.1.31 "," 1.3.6.1.4.1.311.1.7.3.1.32 "," 1.3.6.1.4.1.311.1.7.3.1.33 "," 1.3.6.1.4.1.311.1.7.3.1.34 "," 1.3.6.1.4.1.311.1.7.3.1.35 "," 1.3.6.1.4.1.311.1.7.3.1.36 "," 1.3.6.1.4.1.311.1.7.3.1.37 "," 1.3.6.1.4.1.311.1.7.3.1.38 "}; try {snmputils = new Snmputils (IP, community, port); list<string> dataList = Snmputils.gettableview (OID); Map.put ("Totaloptions", Datalist.get (0)); Map.put ("Totalgets", Datalist.get (1)); Map.put ("Totalposts", Datalist.get (2)); Map.put ("Totalheads", Datalist.get (3)); Map.put ("Totalputs", Datalist.get (4)); Map.put ("Totaldeletes", Datalist.get (5)); Map.put ("Totaltraces", Datalist.get (6)); Map.put ("Totalmove", Datalist.get (7)); Map.put ("Totalcopy", Datalist.get (8)); Map.put ("Totalmkcol", Datalist.get (9)); Map.put ("Totalpropfind", Datalist.get (10)); Map.put ("Totalproppatch", Datalist.get (11)); Map.put ("Totalsearch", Datalist.get (12)); Map.put ("Totallock", Datalist.get (13)); Map.put ("Totalunlock", Datalist.get (14)); Map.put ("Totalothers", Datalist.get (15)); Map.put ("Currentcgirequests", Datalist.get (16)); Map.put ("Currentbgirequests", Datalist.get (17)); Map.put ("Totalcgirequests", Datalist.get (18)); Map.put ("Totalbgirequests", Datalist.get (19)); Map.put ("Maxcgirequests", Datalist.get (20)); Map.put ("Maxbgirequests", Datalist.get (21)); catch (Exception e) {e.printstacktrace ();} finally {snmputils.close ();} return map; /** * Get blocking and deadlock information * * Currentblockedrequests This is the current number of requests temporarily blocked by the WWW service due to bandwidth throttling settings. * Totalblockedrequests This is the total number of requests temporarily blocked by the WWW service due to bandwidth throttling settings. Totalallowedrequests * This is enabled on the server since service startupThe total number of requests that the WWW service has allowed when bandwidth throttling is set. Totalrejectedrequests * This is the total number of requests rejected since service startup due to bandwidth throttling settings. Totalnotfounderrors * This is the number of requests that the server cannot process since service startup because the requested document cannot be found. Typically, they are reported to the client as an HTTP 404 error code. * Totallockederrors This is the total number of requests that the server cannot process since service startup due to the requested document lock. Typically, they are reported to the client as HTTP 423 * error codes. Measuredbandwidth This is the I/O bandwidth used by the WWW service, which is the average in one minute. * * * @param IP * @param community * @param port * @return/public static map<string, string> Getiisblockinfo (stri ng IP, String community, int port) {map<string, string> Map = new hashmap<string, string> (); Snmputils snmputils = null; String[] oid = {"1.3.6.1.4.1.311.1.7.3.1.39", "1.3.6.1.4.1.311.1.7.3.1.40", "1.3.6.1.4.1.311.1.7.3.1.41", " 1.3.6.1.4.1.311.1.7.3.1.42 "," 1.3.6.1.4.1.311.1.7.3.1.43 "," 1.3.6.1.4.1.311.1.7.3.1.44 "," 1.3.6.1.4.1.311.1.7.3.1.45 "}; try {snmputils = new Snmputils (IP, community, port); list<string> dataList = Snmputils.gettableview (OID); Map.put ("Currentblockedrequests", Datalist.get (0)); Map.put ("Totalblockedrequests", Datalist.get (1)); Map.puT ("Totalallowedrequests", Datalist.get (2)); Map.put ("Totalrejectedrequests", Datalist.get (3)); Map.put ("Totalnotfounderrors", Datalist.get (4)); Map.put ("Totallockederrors", Datalist.get (5)); Map.put ("Measuredbandwidth", Datalist.get (6)); catch (Exception e) {e.printstacktrace ();} finally {snmputils.close ();} return map; } }

Call the class

Package Com.shine.framework.IIS; Import java.util.ArrayList; Import Java.util.HashMap; Import java.util.List; public class Example {/** * @param args */public static void main (string[] args) {//iisutils.getiisdatainfo ("192.168.2"). ", public", 161); Iisutils.getiisconnectioninfo ("192.168.2.18", "public", 161); Iisutils.getiisrequestinfo ("192.168.2.18", "public", 161); } }

Package com.shine.framework.core.util;
Import java.net.InetAddress;
Import java.util.ArrayList;

Import java.util.List; Import SNMP.
Snmpobject; Import SNMP.
Snmpsequence; Import SNMP.
Snmpvarbindlist; Import SNMP.

Snmpv1communicationinterface;
	public class Snmputils {private Snmpv1communicationinterface cominterface = null;
	Private String IP;
	Private String community;
	private int port = 161;

	private int version = 0; /** * Initialize * @param IP * @param community * @param port * @throws Exception/Public snmputils (String IP
		, String community, int port) throws Exception {inetaddress hostaddress = inetaddress.getbyname (IP);
	Cominterface = new Snmpv1communicationinterface (version, hostaddress, community, Port); /** * Initialize * @param IP * @param community * @throws Exception/Public snmputils (string IP, string com
		munity) throws Exception {inetaddress hostaddress = inetaddress.getbyname (IP); Cominterface = new SNMPV1COMMUNICATIONINTERFACE (version, hostaddress, community);  /** * Get Value * * @param oid * @return/public string getoidvaluestring (String oid) {if cominterface
			= = null) {SYSTEM.OUT.PRINTLN ("SNMP initialization error");
		return null;
			try {snmpvarbindlist newvars = cominterface.getmibentry (OID);
			Snmpsequence pair = (snmpsequence) (Newvars.getsnmpobjectat (0));
			Snmpobject Snmpvalue = Pair.getsnmpobjectat (1);
		return snmpvalue.tostring ();
		catch (Exception e) {e.printstacktrace ();
	return null; /** * Get Table * * @param oid * @return/public list<string> Gettableview (String oid) {if comin
			Terface = = null) {SYSTEM.OUT.PRINTLN ("SNMP initialization error");
		return null;
			try {list<string> List = new arraylist<string> ();

			Snmpvarbindlist tablevars = cominterface.retrievemibtable (OID); for (int i = 0; i < tablevars.size (); i++) {snmpsequence pair = (snmpsequence) (tablevars. Getsnmpobjectat (i
				)); Snmpobject SNMpvalue = Pair.getsnmpobjectat (1);
			List.add (Snmpvalue.tostring ());
		} return list;
		catch (Exception e) {e.printstacktrace ();
	return null; /** * Get Table * * @param oid * @return/public list<string> Gettableview (String oid[]) {if (COM
			Interface = = null) {SYSTEM.OUT.PRINTLN ("SNMP initialization error");
		return null;
			try {list<string> List = new arraylist<string> ();

			Snmpvarbindlist tablevars = cominterface.retrievemibtable (OID); for (int i = 0; i < tablevars.size (); i++) {snmpsequence pair = (snmpsequence) (tablevars. Getsnmpobjectat (i
				));
				Snmpobject Snmpvalue = Pair.getsnmpobjectat (1);
			List.add (Snmpvalue.tostring ());
		} return list;
		catch (Exception e) {e.printstacktrace ();
	return null; /** * Reconnect * * @param IP * @param community * @param port */public void reconnection (string IP, string community, int port) {try {if (cominterface!= null) cominterfAce.closeconnection ();
			InetAddress hostaddress = inetaddress.getbyname (IP);
		Cominterface = new Snmpv1communicationinterface (version, hostaddress, community, Port);
		catch (Exception e) {e.printstacktrace (); }/** * Reconnect/public void reconnection () {try {if (cominterface!= null) cominterface.closeconnecti

			On ();
			InetAddress hostaddress = inetaddress.getbyname (IP);
		Cominterface = new Snmpv1communicationinterface (version, hostaddress, community, Port);
		catch (Exception e) {e.printstacktrace ();
		}/** * Shutdown/public void close () {try {if (cominterface!= null) cominterface.closeconnection ();
		catch (Exception e) {e.printstacktrace ();
		}/** * @param args */public static void main (string[] args) {snmputils util = null;
			try {string[] oid = {"1.3.6.1.4.1.311.1.7.2.1.1"};
			Util = new Snmputils ("192.168.2.18", "public", 161);
		list<string> list = Util.gettableview (OID);	for (String s:list) {System.out.println (s);
		} catch (Exception e) {e.printstacktrace ();
		finally {util.close ();
 }
	}
}



Svn:http://ken-javaframeword.googlecode.com/svn/trunk/javaframework2.0/src/com/shine/framework/iis/iisutils.java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.