As required by the project, a program is developed to remotely monitor IIS6 or IIS6 through SNMP. Now I will share with you the source code of its core class.
Package COM. shine. framework. IIS; </P> <p> Import Java. util. hashmap; <br/> Import Java. util. list; <br/> Import Java. util. map; </P> <p> Import COM. shine. framework. core. util. snmputils; </P> <p> @ suppresswarnings ("unchecked ") <br/> public class iisutils {<br/>/** <br/> * obtain IIS data sending information <br/> * totalbytessenthighword after, 32-bit high in the total number of bytes sent by the WWW Service. <Br/> * totalbytessentlowword: 32-bit lower in the total number of bytes sent by the WWW Service after the service is started. <Br/> * totalbytesreceivedhighword: the total number of bytes received by the WWW Service after the service is started is 32 bits. <Br/> * totalbytesreceivedlowword: 32-bit lower in the total number of bytes received by the WWW Service after the service is started. <Br/> * totalfilessent: Total number of files sent by the WWW Service after the service is started. Totalfilesreceived: Total number of files received by the WWW <br/> * service after the service is started. <Br/> * @ Param IP <br/> * @ Param community <br/> * @ Param port <br/> * @ return <br/> */<br/> Public static Map <string, string> getiisdatainfo (string IP, string community, int port) {<br/> Map <string, string> map = new hashmap <string, string> (); <br/> snmputils = NULL; <br/> string [] OID = {"Hangzhou", <br/> "1.3.6.1.4.1.311.1.7.3.1.2", "1.3.6.1.4.1.311.1.7.3.1.3", <Br/> "1.3.6.1.4.1.311.1.7.3.1.5", "1.3.6.1.4.1.311.1.7.3.1.5", <br/> "Hangzhou" }; <br/> try {<br/> snmputils = new snmputils (IP, community, port); <br/> List <string> datalist = snmputils. gettableview (OID); <br/> map. put ("totalbytessenthighword", datalist. get (0); <br/> map. put ("totalbytessentlowword", datalist. get (1); <br/> map. put ("totalbytesreceivedhighword", datalist. get (2); <br/> Map. put ("totalbytesreceivedlowword", datalist. get (3); <br/> map. put ("totalfilessent", datalist. get (4); <br/> map. put ("totalfilesreceived", datalist. get (5); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}finally {<br/> snmputils. close (); <br/>}< br/> return map; <br/>}</P> <p>/** <br/> * obtain the IIS connection count. <br/> * currentanonymoususers is currently created using the WWW Service. number of anonymous users. Currentnonanonymoususers <br/> * Number of users using the WWW Service to establish non-anonymous connections. Totalanonymoususers this is the total number of users who have established anonymous connections with the WWW Service since the service was started. <Br/> * totalnonanonymoususers: the total number of users who have established non-anonymous connections with the WWW Service since the service was started. Maxanonymoususers <br/> * This is the maximum number of users who use the WWW Service to establish anonymous connections after the service is started. Maxnonanonymoususers is the maximum number of non-anonymous connections established with the WWW <br/> * service after the service is started. Currentconnections: the number of current connections established with the WWW Service. Maxconnections <br/> * This is the maximum number of simultaneous connections established with the WWW Service after the service is started. Connectionattempts this is the number of times that the WWW <br/> * service has been tried since the service was started. Logonattempts: the number of attempts to log on to the WWW Service after the service is started. <Br/> * @ Param IP <br/> * @ Param community <br/> * @ Param port <br/> *@ return <br/> */<br/> Public static Map <string, string> getiisconnectioninfo (string IP, <br/> string community, int port) {<br/> Map <string, string> map = new hashmap <string, string> (); <br/> snmputils = NULL; <br/> string [] OID = {"1.3.6.1.4.1.311.1.7.3.1.7", <br/> "1.3.6.1.4.1.311.1.7.3.1.8", "1.3.6.1.4. 1.311.1.7.3.1.9 ", <br/>" 1.3.6.1.4.1.311.1.7.3.1.10 "," 1.3.6.1.4.1.311.1.7.3.1.11 ", <br/>" comment "," comment ", <br/>" comment "," comment ", <br/> "1.3.6.1.4.1.311.1.7.3.1.16"}; <br/> try {<br/> snmputils = new snmputils (IP, community, Port ); <br/> List <string> datalist = snmputils. gettableview (OID); <br/> map. put ("currentanonym Oususers ", datalist. get (0); <br/> map. put ("currentnonanonymoususers", datalist. get (1); <br/> map. put ("totalanonymoususers", datalist. get (2); <br/> map. put ("totalnonanonymoususers", datalist. get (3); <br/> map. put ("maxanonymoususers", datalist. get (4); <br/> map. put ("maxnonanonymoususers", datalist. get (5); <br/> map. put ("currentconnections", datalist. get (6); <br/> map. put ("maxconnections", datalist. g Et (7); <br/> map. put ("connectionattempts", datalist. get (8); <br/> map. put ("logonattempts", datalist. get (9); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}finally {<br/> snmputils. close (); <br/>}< br/> return map; <br/>}</P> <p>/** <br/> * obtain IIS request counter Information <br/> * totaloptions after, the number of HTTP requests using the Options method. Totalgets: the number of HTTP requests that are performed using the <br/> * Get method after the service is started. GET requests are the most common HTTP requests. Totalposts: this is the number of HTTP requests that are performed using the POST method after the service is started. <br/> * The number of HTTP requests. Totalheads is the number of HTTP requests that are carried out using the head method after the service is started. Head <br/> * a request usually indicates that a client is querying the request to determine the status of the document to be refreshed. Totalputs this is the number of HTTP <br/> * requests performed by the put method after the service is started. Totaldeletes: the number of HTTP requests initiated by the delete method after the service is started. Delete requests are usually used to delete objects. <Br/> * totaltraces: the number of HTTP requests performed by the TRACE method after the service is started. Trace <br/> * The request allows the client to view the received content at the end of the Request chain and use this information for diagnosis. Totalmove this is the number of HTTP requests that are performed using the move method after the service is started. <br/>. The move request is used to move files and directories. Totalcopy is the number of HTTP requests that are performed using the copy method after the service is started. Copy <br/> * The request is used to copy files and directories. Totalmkcol: the number of HTTP requests that are performed using the mkcol method after the service is started. Mkcol <br/> * The request is used to create a directory on the server. Totalpropfind is the number of HTTP requests that are performed using the PROPFIND method after the service is started. PROPFIND <br/> * request to retrieve the attribute values of files and directories. Totalproppatch: the number of HTTP requests that are performed using the proppatch method after the service is started. <br/>. The proppatch request sets the attribute values in the file and directory. Totalsearch is the number of HTTP <br/> * requests performed by the search method after the service is started. The search request is used to query the server to find resources that match a set of conditions provided by the client. Totallock: this is the number of HTTP requests performed by the lock method after the service is started. <br/>. The lock request is used to lock a file for a user and only allow the user to modify the file. Totalunlock: the number of HTTP requests that are performed using the unlock <br/> * method after the service is started. The unlock request is used to delete a file lock. Totalothers, except <br/> * options, get, head <br/> *, post, put, delete, Trace, move, copy, mkcol, PROPFIND, proppatch, search, lock, or <br/> * http request of the unlock method. Currentcgirequests: the number of current CGI requests simultaneously processed by the WWW Service. <Br/> * currentbgirequests: the number of current ISAPI requests simultaneously processed by the WWW Service. Totalcgirequests <br/> * this is the total number of CGI requests after the service is started. Totalbgirequests: Total number of ISAPI requests received after the service is started. <Br/> * maxcgirequests is the maximum number of CGI requests processed by the WWW Service after the service is started. Maxbgirequests <br/> * This is the maximum number of ISAPI requests simultaneously processed by the WWW Service after the service is started. <Br/> * @ Param IP <br/> * @ Param community <br/> * @ Param port <br/> *@ return <br/> */<br/> Public static Map <string, string> getiisrequestinfo (string IP, string community, int port) {<br/> Map <string, string> map = new hashmap <string, string> (); <br/> snmputils = NULL; <br/> string [] OID = {"1.3.6.1.4.1.311.1.7.3.1.17", <br/> "1.3.6.1.4.1.311.1.7.3.1.18", "1.3.6.1.4.1.311. 1.7.3.1.19 ", <br/>" 1.3.6.1.4.1.311.1.7.3.1.20 "," 1.3.6.1.4.1.311.1.7.3.1.21 ", <br/>" yellow "," yellow ", <br/>" yellow "," yellow ", <br/> "1.3.6.1.4.1.311.1.7.3.1.26", "1.3.6.1.4.1.311.1.7.3.1.27", <br/> "comment", "1.3.6.1.4.1.311.1.7.3.1.29", <br/> "comment", "comment" 1 ", <br/>" 1.3.6.1.4.1.311.1.7.3.1.32 "," 1.3.6.1.4.1.311.1.7.3.1.33 ", <br/>" yellow "," yellow ", <br/>" yellow "," yellow ", <br/> "1.3.6.1.4.1.311.1.7.3.1.38" };</P> <p> try {<br/> snmputils = new snmputils (IP, community, Port ); <br/> List <string> datalist = snmputils. gettableview (OID); <br/> map. put ("totaloptions", datalist. get (0); <br/> map. put ("totalgets", datalist. get (1); <br/> map. put ("totalposts", datalist. get (2); <br/> map. put ("totalheads", datalist. get (3); <br/> map. put ("totalputs", datalist. get (4); <br/> map. put ("totaldeletes", datalist. get (5); <br/> map. put ("totaltraces", datalist. get (6); <br/> map. put ("totalmove", datalist. get (7); <br/> map. put ("totalcopy", datalist. get (8); <br/> map. put ("totalmkcol", datalist. Get (9); <br/> map. put ("totalpropfind", datalist. get (10); <br/> map. put ("totalproppatch", datalist. get (11); <br/> map. put ("totalsearch", datalist. get (12); <br/> map. put ("totallock", datalist. get (13); <br/> map. put ("totalunlock", datalist. get (14); <br/> map. put ("totalothers", datalist. get (15); <br/> map. put ("currentcgirequests", datalist. get (16); <br/> map. put ("currentbgirequests", datalist. get (17) ); <Br/> map. put ("totalcgirequests", datalist. get (18); <br/> map. put ("totalbgirequests", datalist. get (19); <br/> map. put ("maxcgirequests", datalist. get (20); <br/> map. put ("maxbgirequests", datalist. get (21); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}finally {<br/> snmputils. close (); <br/>}< br/> return map; <br/>}</P> <p>/** <br/> * obtain blocking and deadlock Information <br/> * currentblockedrequests This is the current number of requests temporarily blocked by the WWW Service due to bandwidth limit settings. <Br/> * Total Number of requests temporarily blocked by the WWW Service due to bandwidth limit settings. Totalallowedrequests <br/> * this is the total number of requests allowed by the WWW Service when the bandwidth limit setting is enabled on the server after the service is started. Totalrejectedrequests <br/> * this is the total number of requests that are rejected due to bandwidth limit settings after the service is started. Totalnotfounderrors <br/> * this is the number of requests that the server cannot process since the request documentation is not found after the service is started. Generally, they are reported to the client as HTTP 404 error codes. <Br/> * totallockederrors indicates the total number of requests that cannot be processed by the server after the service is started because the request document is locked. Generally, they are reported to the client as an HTTP 423 <br/> * error code. Measuredbandwidth: the I/O bandwidth used by the WWW Service. It is the average value within one minute. <Br/> * @ Param IP <br/> * @ Param community <br/> * @ Param port <br/> *@ return <br/> */<br/> Public static Map <string, string> getiisblockinfo (string IP, string community, int port) {<br/> Map <string, string> map = new hashmap <string, string> (); <br/> snmputils = NULL; <br/> string [] OID = {"Hangzhou", <br/> "1.3.6.1.4.1.311.1.7.3.1.40", "1.3.6.1.4.1.311.1.7.3.1.41 ", <br/> "1.3.6.1.4.1.311.1.7.3.1.42", "1.3.6.1.4.1.311.1.7.3.1.43", <br/> "1.3.6.1.4.1.311.1.7.3.1.44", "1.3.6.1.4.1.311.1.7.3.1.45 "}; <br/> try {<br/> snmputils = new snmputils (IP, community, Port); <br/> List <string> datalist = snmputils. gettableview (OID); <br/> map. put ("currentblockedrequests", datalist. get (0); <br/> map. put ("totalblockedrequests", datalist. get (1); <br/> map. put ("totalallowedrequests", datalist. get (2); <br/> map. put ("totalrejectedrequests", datalist. get (3); <br/> map. put ("totalnotfounderrors", datalist. get (4); <br/> map. put ("totallockederrors", datalist. get (5); <br/> map. put ("measuredbandwidth", datalist. get (6); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}finally {<br/> snmputils. close (); <br/>}< br/> return map; <br/>}< br/>
Call this class
Package COM. shine. framework. IIS; </P> <p> Import Java. util. arraylist; <br/> Import Java. util. hashmap; <br/> Import Java. util. list; </P> <p> public class example {</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) {<br/> // iisutils. getiisdatainfo ("192.168.2.18", "public", 161); </P> <p> // iisutils. getiisconnectioninfo ("192.168.2.18", "public", 161); </P> <p> iisutils. getiisrequestinfo ("192.168.2.18", "public", 161); <br/>}</P> <p >}< br/>
SVN: http://ken-javaframeword.googlecode.com/svn/trunk/JavaFramework2.0/src/com/shine/framework/IIS/IISUtils.java