我的网站是否已关闭、无法运行或出现错误?
我想创建一个小型 Windows 应用程序,它将在每个时间段自动访问我的站点,并检查其运行是否正常,是否发现它已关闭、无法工作或出现错误“示例:404、网络错误、与数据库的连接失败”将在我的屏幕上显示一条消息。
我如何知道使用任何 .NET 语言以编程方式存在错误?
I want to create a small windows application will go automatically every time period to my site and check if its running fine, if it found it down, not working or have an error "Examples: 404, network error, connection to db failed" it will show a message on my screen.
How can i know that there is an error there programmaticly using any .NET language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用
WebClient
可以很容易地做到这一点。 它看起来像这样:您可以将其与
Timer
的Tick
事件或其他事件挂钩以定期进行检查。It's pretty easy to do with a
WebClient
. It would look something like this:You could hook that up to a
Timer
'sTick
event or something to periodically make the check.何必呢? 您可以从像 RedAlert 这样的提供商那里以便宜的价格获得更好的解决方案,
这样做的好处是:
1)它从防火墙外部测试您的站点,因此可以检测到更广泛的问题。
2) 它是公正的第三方,因此如果您需要 SLA,您可以证明正常运行时间。
3) 只需支付少量费用,您就可以让该设备尝试并诊断问题。
4) 当出现问题时,它可以给您寻呼或发送电子邮件。
5) 您无需调试新服务器。
天哪,我听起来像是为这些家伙做的广告,但我保证我不会为他们工作或获取回扣。 我刚刚对我们服务器的服务感到满意。
顺便说一句:我查了一下定价,每个网站每月大约 20 美元。 因此,您可能可以比自己构建服务所需的时间更短地支付一年的服务费用。
Why bother? You can get a much better solution for cheap from a provider like RedAlert
The nice thing about this is:
1) It tests your site from outside your firewall, so it can detect a wider variety of problems.
2) It is an impartial 3rd party so you can prove uptime if you need to for an SLA.
3) For a small premium you can have the thing try and diagnose the problems.
4) It can page or e-mail you when there is a problem.
5) You don't need to commission a new server.
Geez, I sound like an ad for the guys, but I promise I don't work for them or get a kickback. I have just been happy with the service for our servers.
BTW: I checked pricing and it is about $20 per site/month. So you could probably pay for a year of the service in less time than it will take to build it yourself.
为了执行相同的功能,我首先研究了第三方解决方案。 一项免费且相当准确的特定服务是 MonitorUs。
但是,如果您想构建自己的,那么我有一个建议。 考虑使用 Head 请求而不是 get 请求:
这是Peter Bromberg 的文章的链接,该文章解释了如何在 C# 中执行 Head 请求。
Wanting to perform the same functionality I first looked into third party solutions. One particular service that is free and has been fairly accurate is MonitorUs.
If, however, you are wanting to build your own then I would have one recommendation. Consider using a Head request instead of a get request:
Here's a link to Peter Bromberg's article that explains how to perform a Head request in C#.
使用 System.Net.WebClient 对象。 它比 HttpWebRequest 更容易使用。 它有一个“DownloadString”方法,可以将 URL 的内容下载到字符串中。 如果服务器返回 500,该方法也可能抛出 WebException 错误。对于其他错误,您可以解析字符串并查找关键字。
Use the System.Net.WebClient object. It's easier to use than HttpWebRequest. It has a "DownloadString" method that will download the contents of a URL into a string. That method may also throw a WebException error if the server returns a 500. For other errors you can parse the string and look for key words.
使用 HttpWebRequest,并将其包装在 WebException 的 try catch 中。 异常对象中的错误代码将为您提供代码。 404等。如果是500,则可以打印该消息。
Use HttpWebRequest, and wrap it in a try catch for WebException. The error code in the exception object will give you the code. 404, etc. If it is 500, you could print the message.
如果这样做,请创建一个特殊页面来执行任何特殊子系统,例如数据库、文件 IO 等,并以纯文本(而不是 html)提供结果。 这将使您能够更轻松地解析返回的数据,并且还将捕获诸如 DB 或 IO 问题之类的问题,这些问题可能不会给您带来 404 或 500 HTTP 错误。
If you do this, create a special page that exercises any special subsystems, like the data base, file IO, etc, and serves up the results in plain text, not html. This will allow you to parse the returned data easier, and will also catch things like DB or IO problems that may not give you a 404 or 500 HTTP error.
尝试 Adventnet 的应用程序管理器 (http://www.manageengine.com/products/applications_manager/ ),它免费提供 5 个监视器,并提供出色的监控功能
您可以配置在发生故障时可以执行的操作,例如发送电子邮件等。
Try Adventnet's Application Manager (http://www.manageengine.com/products/applications_manager/), it is free for 5 monitors, and provides excellent monitoring capabilities
You could configure the actions that can be done in case of a failure like send email etc.
如果您希望在网站关闭时收到电子邮件/短信,请尝试我的网站是否正常运行网页基于解决方案。
If you'd prefer to get email/SMS when your sites are down, try the Are My Sites Up web-based solution.