监控 .NET 中正在运行的应用程序?
我们有几个在 Windows 2003/2008 服务器上运行的应用程序。其中一些应用程序是 Java JAR 文件,这些文件是使用 app.cmd 文件通过计划任务
启动的。
其他的是“大的”,例如 SQL Server 和 IIS。
我想编写一个应用程序(实际上是服务)来简单地监视这些程序并查看它们是否正在运行。
这有点超出了我之前所做的。哦,这个需要用C#写。
我正在考虑某种类型的“心跳”模式,以便每隔几分钟,我检查线程是否正在运行(再次,新的高级线程),如果是,则发送一条“一切正常”消息(使用 SMTP 或其他方式) 。
有什么建议可以从哪里开始吗?
感谢您的任何建议。
We have several apps that run on a Windows 2003/2008 server. Some of these apps are Java JAR files that are kicked off with a Scheduled Task
using a app.cmd file.
Others are "big ones" like SQL Server and IIS.
I'd like to write an app (or service, actually) that simply monitors those programs and sees if they are running or not.
This is a little beyond what I've done before. Oh, this needs to be written in C#.
I was thinking of some type of "heart beat" pattern so that every few minutes, I check if the thread is running (again, new advanced threading) and if so, send out an "All's OK" message (using SMTP or something).
Any tips where to get started?
Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
Process.GetProcesses()
:You can use
Process.GetProcesses()
:您可能应该根据具体情况处理每个应用程序,例如,尽管您可以只检查 SQL Server 进程是否存在,但最好运行一个查询来(例如)检查给定进程是否存在服务器中的数据库。
类似地,您可以对 IIS 服务器运行一个简单的 HTTP 请求来检查以确保权限设置正确等等...
显然,您测试 Java 进程的方式将取决于它们的功能,尽管您仍然可以只检查查看进程是否正在运行(请注意,如果它们作为服务运行,它们可能在 svchost.exe 进程之一内运行 - 但这不适用于计划任务)。
You should probably handle each application on a case-by-case basis, for exaple although you could just check for the existance of the SQL Server process you would be better off running a query that (for example) checks for the existance of a given database in the server.
Similarly you could run a simple HTTP request against an IIS server to check to make sure that the permissions are set up correctly etc...
Obviously the way that you test your Java processes would depend on what they do, although you could still just check for to see if the process is running (be aware that if they are running as a service they may be running inside one of the svchost.exe processes - this doesn't apply to scheduled tasks though).