简体   繁体   English

应用程序心跳监视,可能通过SQL Server

[英]Application heartbeat monitoring, possibly via SQL server

I have an application written in ASP.NET C# that should run for about 2 days and then stop until it is started again. 我有一个用ASP.NET C#编写的应用程序,该应用程序应运行约2天,然后停止直到再次启动。 The application sometimes runs into some trouble that, at the moment, requires manual intervention to make it continue. 该应用程序有时会遇到一些麻烦,目前需要人工干预才能使其继续运行。 (So far, SQL server in itself was never the problem) (到目前为止,SQL Server本身从来都不是问题)

When working, the application writes a line to a log database table at least every 20 minutes. 在工作时,该应用程序至少每20分钟将一行写到日志数据库表中。 If these lines are not there, it means the application either finished the task or needs help to continue. 如果这些行不存在,则意味着应用程序已完成任务或需要帮助才能继续。 In these cases, I would like to get an email or some other notification. 在这种情况下,我想收到电子邮件或其他通知。

What is the best way to detect and notify me if or when the application has stopped writing these lines to the log database table? 检测或通知我是否或何时应用程序停止将这些行写入日志数据库表的最佳方法是什么?

If it makes things easier, I could make the application perform some other regular task, such as writing to a file or sending a TCP/UDP packet somewhere. 如果使事情变得容易,我可以使应用程序执行其他一些常规任务,例如写入文件或在某个地方发送TCP / UDP数据包。

Aside of the obvious concerns with the design of this application. 除了这个应用程序的设计存在明显的问题。 Given your current design, you could potentially write a windows service to monitor the log file. 根据当前的设计,您可能会编写Windows服务来监视日志文件。 If it's older than N minutes, fire off an System.Net.Mail.MailMessage . 如果早于N分钟,请启动System.Net.Mail.MailMessage

If you're able to make the application do something like sending packets, is there any reason you couldn't make the application send its own alerts? 如果您能够使应用程序执行诸如发送数据包之类的操作,那么是否有任何理由无法使应用程序发送其自己的警报? The alert needs to be sent when the application has finished, or when it needs "help" (I'm assuming some sort of manual input or confirmation). 需要在应用程序完成或需要“帮助”时发送警报(我假设是某种手动输入或确认)。 It's reasonable to assume that the application can tell when either of these things have happened, so... why can't the application send an alert? 可以合理地假设应用程序可以告知发生这两种情况的时间,因此...为什么应用程序无法发送警报? ASP.NET apps can access SMTP and send emails really easily using the System.Net.Mail.SmtpClient . ASP.NET应用程序可以使用System.Net.Mail.SmtpClient轻松访问SMTP并发送电子邮件。 It seems really odd to me to have a separate program sending emails on behalf of a program that has access to a perfectly good email client class. 对于我来说,有一个单独的程序代表可以访问非常好的电子邮件客户端类的程序发送电子邮件真的很奇怪。

You can send emails from the global application error handler (Application_Error in Global.asax). 您可以从全局应用程序错误处理程序(Global.asax中的Application_Error)发送电子邮件。 Windows service monitoring the database is another solution, but it may be better to write a short script/command line application and run it with windows scheduler. Windows服务监视数据库是另一个解决方案,但是编写一个简短的脚本/命令行应用程序并使用Windows Scheduler运行它可能会更好。 It has lower footprint and it is easier to write and install. 它具有较小的占地面积,并且更易于编写和安装。

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

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