简体   繁体   English

监控.NET中运行的应用程序?

[英]Monitor running apps in .NET?

We have several apps that run on a Windows 2003/2008 server. 我们有几个在Windows 2003/2008服务器上运行的应用程序。 Some of these apps are Java JAR files that are kicked off with a Scheduled Task using a app.cmd file. 其中一些应用程序是使用app.cmd文件通过Scheduled Task启动的Java JAR文件。

Others are "big ones" like SQL Server and IIS. 其他人是SQL Server和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#. 哦,这需要用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). 我正在考虑某种类型的“心跳”模式,以便每隔几分钟,我检查线程是否正在运行(再次,新的高级线程),如果是这样,发出“All's OK”消息(使用SMTP或其他东西) 。

Any tips where to get started? 任何提示从哪里开始?

Thanks for any suggestions. 谢谢你的任何建议。

You can use Process.GetProcesses() : 您可以使用Process.GetProcesses()

Use this method to create an array of new Process components and associate them with all the process resources on the local computer. 使用此方法可以创建一个新的Process组件数组,并将它们与本地计算机上的所有进程资源相关联。

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. 您应该根据具体情况处理每个应用程序,虽然您可以检查SQL 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... 类似地,您可以针对IIS服务器运行简单的HTTP请求以检查以确保正确设置权限等...

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). 显然,测试Java进程的方式取决于它们的工作方式,尽管您仍然可以检查进程是否正在运行(请注意,如果它们作为服务运行,它们可能正在其中一个svchost中运行.exe进程 - 虽然这不适用于计划任务)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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