简体   繁体   English

Windows Service的心跳活动

[英]Heartbeat activity for Windows Service

I have many Windows Services (written in C# 4.0) that at various intervals connect to a database and do various complex tasks. 我有许多Windows服务(用C#4.0编写),它们以不同的时间间隔连接到数据库并执行各种复杂的任务。 Some of these tasks only occur every X hour intervals per day. 其中一些任务每天仅隔X小时间隔执行一次。 However, the server support team would like to know if the Windows Service is actually running as there can be a big interval between tasks. 但是,服务器支持团队想知道Windows服务是否正在实际运行,因为任务之间的间隔可能很大。 They would like essentially a heartbeat for each Windows Service. 他们本质上希望每个Windows服务都心跳。 Every 5 minutes the Windows Service would do something that could be monitored by Microsoft System Center Operation Manager (SCOM). Windows服务每5分钟执行一次可以由Microsoft System Center Operation Manager(SCOM)进行监视的操作。 Any solution must being easily monitored by SCOM as the server support team rely on it. 服务器支持团队必须依靠SCOM轻松监视任何解决方案。

What is the best way to achieve this type of funcationality? 实现这种功能的最佳方法是什么? I thought of using Performance Counters and have SCOM listen for those but not sure if that is that best use of perf counters. 我考虑过使用性能计数器,并让SCOM监听那些性能计数器,但是不确定这是否是对性能计数器的最佳使用。

UPDATE (Totally forgot to include): Currently each service writes to a database this action but SCOM is not very good at monitoring databases records and differentiating which service is doing what etc. UPDATE(完全忘记包括):当前,每个服务都会将此操作写入数据库,但是SCOM不太擅长监视数据库记录并区分哪个服务在做什么等。

If your case here is limited to service health check, I am pretty sure this can be done by windows tools such as windows performance monitor. 如果您的情况仅限于服务运行状况检查,我很确定这可以通过Windows工具(例如Windows性能监视器)来完成。 Collecting their data should be an easier task than creating heartbeats in a usually disconnected environment. 与在通常断开连接的环境中创建心跳相比,收集他们的数据应该是一件容易的事。
There are plenty of server and service monitoring tools. 有很多服务器和服务监视工具。 Few of them are also open-source, which you can choose as an initial step. 他们中很少有人也是开源的,您可以选择第一步。

You could add either SNMP or WMI instrumentation to your services - this incidentally will allow you to raise more than just heartbeat messages - for example you could also raise events when you encounter transient faults that require an operation to be retried. 您可以在服务中添加SNMP或WMI工具-附带地,这不仅可以引发心跳消息-例如,当遇到需要重试操作的瞬时故障时,您还可以引发事件。

There are plenty of SNMP libraries out there and WMI support is built into the .NET framework. 有很多SNMP库,并且.NET框架内置了WMI支持。

Just FYI, I'm researching this question because how I do it is that the Service application logs a hearbeat message every X seconds when it polls the Db for a new job. 仅供参考,我正在研究此问题,因为我的工作方式是服务应用程序在轮询Db进行新工作时每隔X秒记录一次监听消息。 At midnight, all heartbeat messages over a week old are deleted from the log. 在午夜,所有超过一周的心跳消息将从日志中删除。 I do have an application scheduled at 7 AM that checks when the last heartbeat message was sent, but it looks like I'm going to have to run it constantly to periodically check ... and notify Solar Winds to send an alert if there is a problem. 我确实有一个计划在上午7点进行检查的应用程序,该应用程序将检查何时发送了最后一个心跳消息,但是看来我将不得不不断运行它以定期检查...并通知Solar Winds发送警报(如果有)一个问题。

简单地写入数据库或事件日志该怎么办?

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

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