[英]How to monitor Python scripts using Sensu?
我想使用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?
因此,我已經在sensu中為我的AWS Linux客戶端成功運行了一些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)
通常,以上腳本在運行的進程中搜索字符串chef-client
。 您可以將其替換為任何其他字符串,例如test.py
,它將檢測正在運行的任何程序的名稱是否為test.py
(您可能需要相匹配的子串test.py
如果你運行的程序python test.py
,我不知道紅寶石)。
我建議您將Sensu進程檢查插件用於更通用的功能,其中包括更多的自定義功能。 看看其他的sensu插件 。
為什么不監視腳本的預期結果或操作,而不是過程本身。 通常,我們將設置檢查以監視Web應用程序的端點或觀察到的行為(例如數據庫中的消息),以確定應用程序是否正在運行。
有時,該流程在技術上正在運行,但由於錯誤狀況或資源問題而無法執行任何操作。 監視預期結果是比監視過程更好的選擇。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.