i have created site monitoring utility, sends http , ping request site, checks database make sure it's , ready take requests, , checks service website needs.
the problem is, utility randomly lose connection server hours @ time, no reason why.
i have run wireshark multiple times on server see if there network related, keep coming nothing. wireshark says no packets or getting dropped.
has else ever run that?
i can't post code service, contains sensitive information in it. don't think it's code, i'm having hard time figuring out be!
here code:
private void httprequest() { foreach(string urltotest in urls) { bool success = false; httpwebresponse urlres = null; httpwebrequest urlreq = null; bool timed = false; stringbuilder message = null; httpstatuscode code = httpstatuscode.unused; string codedescript = string.empty; (int = 0; < httpthreshold; i++) { try { writetoowneventlog("sending http request " + urltotest, "http request", true); urlreq = (httpwebrequest) webrequest.create(urltotest); urlreq.timeout = 300000; urlreq.proxy = null; urlreq.servicepoint.connectionleasetimeout = 300000; urlreq.servicepoint.maxidletime = 300000; urlreq.allowautoredirect = true; urlreq.authenticationlevel = system.net.security.authenticationlevel.none; servicepointmanager.securityprotocol = securityprotocoltype.ssl3; using(urlres = (httpwebresponse) urlreq.getresponse()) { if (urlreq.haveresponse) { if (urlres.statuscode == httpstatuscode.ok || urlres.statuscode == httpstatuscode.continue) { success = true; timed = false; break; } } } } catch (exception ex) { if (urlres != null && urlres.statuscode != null) code = urlres.statuscode; if (urlres != null && urlres.statusdescription != null) codedescript = urlres.statusdescription; if (ex.message == "the operation has timed out") { timed = true; } else { logerror(ex); if (i + 1 == httpthreshold) { message = new stringbuilder("message: " + ex.message + "<br/>"); if (ex.innerexception != null) message.append("inner exception: " + ex.innerexception + "<br/>"); if (ex.source != null) message.append("source: " + ex.source + "<br/>"); if (ex.stacktrace != null) message.append("stack trace" + ex.stacktrace + "<br/>"); } } } { if (urlreq != null) { urlreq.abort(); urlreq = null; } if (urlres != null) { urlres.close(); urlres = null; } gc.collect(); } } if (success) { writetoowneventlog("http request returned successful", "http request", true); } else { if (!timed && code != httpstatuscode.unused && !string.isnullorempty(codedescript) && message == null) emailerror("site '" + urltotest + "' httprequest returned status of " + code.tostring() + ". \n description: \n " + codedescript); else if (!timed && code != httpstatuscode.unused && !string.isnullorempty(codedescript) && message != null) emailerror("site '" + urltotest + "' errored exception. httprequest returned status of " + code.tostring() + ". \n description: \n " + codedescript + message.tostring()); else if (!timed && code == httpstatuscode.unused && string.isnullorempty(codedescript) && message == null) emailerror("site '" + urltotest + "' httprequest returned error. no information display"); else if (!timed && code == httpstatuscode.unused && string.isnullorempty(codedescript) && message != null) emailerror("site '" + urltotest + "' httprequest errored exception.<br/>" + message.tostring()); else if (timed) emailerror("site '" + urltotest + "' httprequest timed out"); writetoowneventlog("http request failed, email sent", "http request", true); } } writetoowneventlog("<--------------------------------------------------------------------------------------------->", "http request", false); } private void pingurl() { foreach(string urltotest in urls) { bool success = false; pingreply reply = null; stringbuilder message = null; ipstatus status = ipstatus.unknown; (int = 0; < pingthreshold; i++) { ping ping = null; try { ping = new ping(); writetoowneventlog("ping sent " + urltotest, "ping", true); string urltotest1 = urltotest.substring(urltotest.indexof(":") + 3); if (urltotest1.contains('/')) { urltotest1 = urltotest1.substring(0, urltotest1.indexof('/')); } reply = ping.send(urltotest1); status = reply.status; if (reply.status == ipstatus.success) { success = true; break; } } catch (exception ex) { logerror(ex); if (i + 1 == pingthreshold) { message = new stringbuilder("message: " + ex.message + "<br/>"); if (ex.innerexception != null) message.append("inner exception: " + ex.innerexception + "<br/>"); if (ex.source != null) message.append("source: " + ex.source + "<br/>"); if (ex.stacktrace != null) message.append("stack trace" + ex.stacktrace + "<br/>"); } } { if (ping != null) { ping.dispose(); ping = null; } if (reply != null) { reply = null; } gc.collect(); } } if (success) { writetoowneventlog("ping received successfully", "ping", true); } else { if (status != ipstatus.unknown && message != null) emailerror("ping failed. returned status of " + reply.status.tostring() + " site '" + urltotest + "'. exception:" + message); else if (status != ipstatus.unknown && message == null) emailerror("ping failed. returned status of " + reply.status.tostring() + " site '" + urltotest + "'."); else if (status == ipstatus.unknown && message != null) emailerror("ping failed exception. <br/>" + message.tostring()); else if (status == null && message == null) emailerror("ping failed. no information available"); writetoowneventlog("ping failed. email sent", "ping", true); } } writetoowneventlog("<--------------------------------------------------------------------------------------------->", "ping", false); } private void checkdatabase() { foreach(string database in databases) { bool success = false; stringbuilder message = null; string dbname = ""; string dbserver = ""; (int = 0; < databasethreshold; i++) { sqlconnection conn = null; try { using(conn = new sqlconnection(database)) { dbname = conn.database; dbserver = conn.datasource; writetoowneventlog("opening connection sql database " + dbname + " on " + dbserver, "database", true); conn.open(); success = true; conn.close(); break; } } catch (exception ex) { logerror(ex); if (i + 1 == databasethreshold) { message = new stringbuilder("message: " + ex.message + "<br/>"); if (ex.innerexception != null) message.append("inner exception: " + ex.innerexception + "<br/>"); if (ex.source != null) message.append("source: " + ex.source + "<br/>"); if (ex.stacktrace != null) message.append("stack trace" + ex.stacktrace + "<br/>"); } } { if (conn != null) { conn.close(); conn.dispose(); } gc.collect(); } } if (success) { writetoowneventlog("sql database connection successful " + dbname + " on " + dbserver, "database", true); } else { if (message != null) { emailerror("cannot connect sql database " + dbname + " on " + dbserver + "<br/>" + message.tostring()); writetoowneventlog("sql database connection failed database " + dbname + " on " + dbserver + ", email sent<br>" + message.tostring(), "database", true); } else { emailerror("cannot connect sql database " + dbname + " on " + dbserver + ", no information available"); writetoowneventlog("sql database connection failed database " + dbname + " on " + dbserver + ", email sent, no information available", "database", true); } } } writetoowneventlog("<--------------------------------------------------------------------------------------------->", "database", false); }
Comments
Post a Comment