How to check application runs in AWS EC2 instance

前端 未结 4 407
别那么骄傲
别那么骄傲 2021-01-11 11:11

How can I check which platform my app runs, AWS EC2 instance, Azure Role instance and non-cloud system? now I do that like this:

if(isAzure())
{
    //run in         


        
4条回答
  •  一向
    一向 (楼主)
    2021-01-11 11:50

    As you said the WebRequest.Create() call is slow on your desktop so you really need to check the network traffic (using Netmon) to actually determine what took long time. This request, opens connection, connects to target server, downloads the content and then close the connection so it is good to know where this time is taken.

    Also if you just want to know if any URL (on Azure, on EC2 or any other web server is live and working fine you can just request to only download headers by using

    string URI = "http://www.microsoft.com";
    HttpWebRequest  req = (HttpWebRequest)WebRequest.Create(URI);
    req.Method = WebRequestMethods.Http.Head;
    var response = req.GetResponse();
    int TotalSize = Int32.Parse(response.Headers["Content-Length"]);
    // Now you can parse the headers for 200 OK and know that it is working.
    

    You can also use GET only a range of the data instead of full data to expedite to call:

    HttpWebRequest myHttpWebReq =(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
    myHttpWebReq.AddRange(-200, ContentLength); // return first 0-200 bytes
    //Now you can send the request and then parse date for headers for 200 OK
    

    Any of the above method will be faster to get where your site is running.

提交回复
热议问题