我创建了一个 nodejs 应用程序来测试 Web 应用程序是否仍在运行,并且想知道是否有一种方法可以连接到特定的 tomcat 以在它关闭时重新启动它。 我试图用谷歌搜索它,但唯一会出现的是在 tomcat 上设置 Node 应用程序。
最佳答案
不确定为什么要通过 Node 应用程序进行监控,有付费和免费的框架可以非常有效地执行此操作,包括电子邮件警报、短信甚至电话。 newrelic、Sentry 和 Site24X7 等等,但是如果你想通过 nodejs 进行监控,你不能只用这样的东西检查主 url 吗?顺便说一句,您需要为此示例请求 NPM npm 安装请求
var request = require('request');
// Check every 30 seconds
var INTERVAL = 30;
var payload = {
// Edit to whatever tomcat URL you want to check periodically
url: 'http://localhost:8000',
//url: 'http://www.google.com',
method: 'GET'
}
setInterval(function() {
request(payload, function(err, response, body) {
if (err) {
// DO something with the error,like email, text or phone call
console.err(err);
} else {
if (response.statusCode != 200) {
// Error DO something with the error,like email, text or phone call
console.log('Error ....');
console.log(response.statusCode);
} else {
console.log('Server working okay');
}
}
});
}, INTERVAL * 1000);
关于node.js - 通过 nodejs 应用程序连接到 tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48326654/