简体   繁体   English

监视自定义Windows服务

[英]Monitoring a custom windows service

I've built a windows service application using Visual Studio .NET and C#. 我使用Visual Studio .NET和C#构建了一个Windows服务应用程序。 This service will be deployed on a few hundred machines and I'm looking for a solid way to monitor the application. 这项服务将部署在几百台机器上,我正在寻找一种可靠的方法来监控应用程序。 By monitor, I mean, I just want to check to make sure that it's running, and check the status of a few settings on each client. 通过监视器,我的意思是,我只想检查以确保它正在运行,并检查每个客户端上的一些设置的状态。

Is there a common method of doing this? 这样做有一个共同的方法吗?

The easiest thing to do is have each application "call home". 最简单的方法是让每个应用程序“回家”。 Create a single central application, preferably a web app, and have the remote applications make a small call to the central app on whatever interval you feel is necessary. 创建一个单独的中央应用程序,最好是一个Web应用程序,让远程应用程序在您认为必要的任何时间间隔内对中央应用程序进行一次小调用。 They can include the extra information you want to monitor. 它们可以包含您要监控的额外信息。

Keep a list of where the application is deployed and if you don't get a call from any on the list within the expected timeframe, then you know it's offline. 保留部署应用程序的位置列表,如果在预期的时间范围内没有从列表中的任何人那里接到电话,那么您就知道它处于脱机状态。

If you can't change the actual application that you're monitoring, then write a small companion application that can run as a scheduled tasks and perform the same local checks and call back to the central application. 如果您无法更改正在监视的实际应用程序,请编写一个小型伴随应用程序,该应用程序可以作为计划任务运行并执行相同的本地检查并回调到中央应用程序。

We do this with thousands of client machines worldwide and it works well. 我们在全球拥有数千台客户端机器,并且运行良好。

You could write a little monitor utility program that checks the service state via the SCM and provides a simple HTTP interface so you can poll the status. 您可以编写一个小的监视器实用程序,通过SCM检查服务状态,并提供一个简单的HTTP接口,以便您可以轮询状态。 This would basically be just a big loop with some reporting if the service state changes. 如果服务状态发生变化,这基本上只是一个大循环,有一些报告。

while (true)
{
    string serviceName = "NameOfYourService";
    ServiceController Svc = new ServiceController(serviceName);
    if (Svc.Status != ServiceControllerStatus.Running)
    {
        //Do reporting/set status here
    }
    Thread.Sleep(5000);
}

例如,您可以利用像Zabbix这样的监控工具。

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

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