简体   繁体   中英

How to ping my website in Azure?

I wrote a Windows application to ping my website each 5 minutes to control whether it is UP or DOWN at the moment. it was working in our network and in our test server but our live environment is in Azure and it doesn't allow me to ping that web site.

What can I use instead of Ping to control my website in Azure? and how?

I would suggest you take it outside of your own infrastructure. Mainly because ping 'ing something can give you very limited information anyway. What if the role is up and running but your website is actually crashing with an exception? What if you have multiple instances of your role, one of which is down, and your ping request doesn't say anything is wrong?

Use something like Pingdom:

http://www.pingdom.com

It'll allow you to do a few things, that are probably not possible (or not easy) to do with your own 'inhouse' solution. Such as transaction monitoring (similar to very basic UI tests, have a user log in and click around for instance), multiple ways of alerting (even Twitter alerts) and multiple different request locations (it may work in the UK, but does it work when accessing it from France?).

Services like this were created for this sole purpose. You need to define when you believe your website to "be up" or "be down". Is it when it responds to ping 's? Is it when your login page displays OK? Is it when your admin page displays OK?

Use HttpWebRequest and HttpWebResponse and remember to Dispose the objects you create. In particular the response stream of HttpWebResponse.

HttpWebResponse res = req.GetResponse() as HttpWebResponse;
using (Stream respStream = res.GetResponseStream())
{
  respStream.ReadByte();
  respStream.Close();
} 

I used HttpWebRequest and HttpWebResponse instead of Ping, but after 3 times the program freezes for some reason. I put everything in a try...catch block but it does not throw any exception either, only freezes.

 try
 {
      var myRequest = (HttpWebRequest)WebRequest.Create(url);
      var response = (HttpWebResponse)myRequest.GetResponse(); //After third time it freezes here

      if (response.StatusCode == HttpStatusCode.OK)
      {
          labelResult.Text += TxtIPAddress.Text + " is Available " + " " + System.DateTime.Now.ToString() + " " + Environment.NewLine;
      }
      else
      {                    
          labelResult.Text += TxtIPAddress.Text + " is Unavailable " +  System.DateTime.Now.ToString() + " " + Environment.NewLine;
      }
  }
  catch (Exception ex)
  {             
      labelResult.Text += TxtIPAddress.Text + " is Unavailable " + System.DateTime.Now.ToString() + " " + Environment.NewLine;
  }

Another monitoring tool which is more complex is PRTG

It provides a number of monitors and is free for so many sensors you wish to monitor.

This way you can monitor not just a sites existence but whether a web service for a specific call returns, a SQL query. The possibilities are almost endless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM