检查 Java 停机时间的最佳方法是什么?
您能否建议检查服务器是否正在使用 java 运行的最佳方法? 我的意思是我想检查站点是否有停机时间。 连接到服务器并获取状态(如果返回 200 则表示已启动!)的方法正确吗?
如果建立连接并每 60 秒检查一次状态,这不会减慢服务器速度吗?
我当前正在使用 HttpConnection 进行连接,并通过 HttpConnection.getResponseCode 获取状态代码。 如果代码为 200,则服务器运行良好。 这种方法不会影响服务器吗?我的意思是它不会每分钟用自己的请求加载服务器吗?
Can you please advice on the best way to check if a server is running using java? I mean I want to check a site for downtime. Is connecting to the server and getting the status (if 200 returned then it's up!) the right way?
Won't this slow down the server in case connection is established and status checked every 60 seconds?
I'm currently connecting using HttpConnection and getting the status code through HttpConnection.getResponseCode. If the code is 200 then the server's running fine. Does this method not affect the server, I mean won't it load the server with its own requests every minute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
每分钟一个请求应该绝对没问题。
想想同时发生的其他请求的数量:-)
A single request every minute should be absolutely fine.
Just think of the volume of other requests that are happening at the same time :-)
如果停机对您来说意味着站点无法访问,并且您已调整服务器大小以获得足够的带宽和负载,那么您的解决方案是可以的..但对于企业报告使用来说还不够好。 你需要更多。
话虽如此,我确信您的托管提供商将能够更好地为您提供有关服务器运行状况和可用性的更准确的统计数据,而无需您进行任何监控。 检查您与他们的合同。
if downtime for you means that site is not accessible and you have sized the server for adequate bandwidth and load, your solution is ok.. but not good enough for enterprise reporting use. You need more.
Having said that I'm sure that your hosting provider will be better positioned to give you more accurate statistics about the health and availability of your server without you having to do any monitoring. Check your contract with them.
每分钟一个请求听起来可以忽略不计,除非该请求导致服务器执行大量繁重的工作。 您还可以请求静态资源(例如 css 文件)来简单地检查容器是否响应。
如果您想节省最后一点网络带宽,您可以将请求方法设置为“HEAD”而不是“GET”。
One request per minute sounds negligible unless that request causes the server to do a lot of heavy lifting. You could also request a static asset like a css file to simply check that container is responsive.
If you want to conserve every last bit of network bandwidth, you can make your request method "HEAD" rather than "GET".
有没有理由自己做而不依赖于制造这个东西的公司之一? 通常他们在世界各地都有服务器,可以通过邮件和短信的方式通知你,设置非常灵活。
我知道的一些公司是 host-tracker、monitis、watchour 和 < a href="http://mon.itor.us/" rel="nofollow noreferrer">mon.itor.us。 我与他们没有任何关系,只是一个客户。 我想还有其他人
Is there a reason to do it yourself and not rely on one of the companies who make this thing for living? Usually they have servers around the world, and they can notify you by mail and SMS, with very flexible settings.
Some of the companies I know are host-tracker, monitis, watchour and mon.itor.us. I'm not affiliated with them, just a customer. I guess there are others as well
使用 HEAD 请求将生成类似于 GET 的响应,但仅包含 HTTP 标头。
如果您可以控制正在监视的服务器,为什么不设置一个仅用于监视目的的 URL,它返回一个简单的文本响应和适当的响应代码,并且不会对资源产生额外的需求。
不要忘记,您可能不仅想要监控 HTTP 响应,还想要监控底层服务(例如数据库等)的运行状况。 您的监控 URL 可以在请求期间检查这些内容并适当修改 HTTP 响应代码(例如返回 500 - 服务器错误或类似错误)
Using the HEAD request will generate a response similar to that with GET but only including HTTP headers.
If you have control over the server you're monitoring, why not set up a URL solely fir monitoring purposes, that returns a simple text response an tyhe appropriate response code, and makes no extra demand on resources.
Don't forget that you may want to monitor not just the HTTP response but the health of the underlying services (eg databases etc.). Your monitoring URL can check these during the request and modify the HTTP response code appropriately (eg return a 500 - server error or similar)