我想使用Sensu Core来监控python脚本,我很困惑如何去做。
从Sensu文档中,这需要Sensu Checks。在提供的示例中,ruby脚本检查chef-client是否正在运行:
#!/usr/bin/env ruby
# get the current list of processes
processes = `ps aux`
# determine if the chef-client process is running
running = processes.lines.detect do |process|
process.include?('chef-client')
end
# return appropriate check output and exit status code
if running
puts 'OK - Chef client process is running'
exit 0
else
puts 'WARNING - Chef client process is NOT running'
exit 1
end
如何对特定脚本而不是应用程序执行此类检查?也就是说,我将如何监控特定的python脚本(例如test.py)而不是一般的python?
答案 0 :(得分:2)
所以,我已经成功地为我的AWS Linux客户端在sensu中运行了一些python脚本,这是我的检查定义的一个很好的例子:
{
"checks": {
"check-rds-limit": {
"interval": 86400,
"command": "/etc/sensu/plugins/rds-limit-check.py",
"contacts": [
"cloud-ops"
],
"occurrences": 1,
"subscribers": [
"cloud-ops-subscription"
],
"handlers": [
"email",
"slack"
]
}
}
}
你的python插件可以从定义shebang路径开始:
#!/usr/bin/env python
import sys
...
...
//<code condition for warning>
sys.exit(1)
//<code condition for critical>
sys.exit(2)
//<code condition where everything is fine>
sys.exit(0)
答案 1 :(得分:0)
更一般地说,上面的脚本在正在运行的进程中搜索字符串chef-client
。您可以将其替换为任何其他字符串,例如test.py
,这将检测运行的程序是否在其名称中运行test.py
。 (如果您使用test.py
运行程序,则可能需要匹配子字符串python test.py
,我不知道ruby。)
我建议你使用Sensu process check plugin来获得包含更多自定义功能的更通用的功能。另请查看其他sensu plugins。
答案 2 :(得分:0)
为什么不监视脚本的预期结果或操作而不是进程本身。通常,我们将设置检查以监视Web应用程序的终点或观察到的行为(例如数据库中的消息),以确定应用程序是否正在运行。
有时,进程在技术上运行,但由于错误情况或资源问题而无法运行。监视预期结果是比观看流程更好的选择。