您的位置:首页 > 运维架构 > Linux

newlisp 监控Linux进程 三

2013-11-05 13:51 211 查看
本节很简单,仅仅是添加一个发送状态到web server的功能。
1表示进程或者,0表示进程已经不存在。
process.lsp全部代码:
#!/usr/bin/newlisp

(set 'cur-path "/opt/detector")
(load (append cur-path "/filter.lsp"))
(load (append cur-path "/config.lsp"))

(define (check-process filter-str)
(set 'r (exec (append "ps -def | grep " filter-str)))
(set 'l (length r))
(> l 2))

(define (add-log msg)
(println msg)
(append-file (append cur-path "/process.log") (append "\n" (string (now 480)) " "))
(append-file (append cur-path "/process.log") (append ": " msg))
)

(define (call-api process-status)
(set 'data (format "ip=%s&hostName=%s&time=%lld&status=%lld" ip host_name (date-value) process-status))
(println data)
(set 'r3 (post-url (format "http://%s/wind_tunnel/api/post/process" server) data))
(println r3))

(dolist (sub-list filters)
(if (check-process (first sub-list))
(begin
(add-log (append (sub-list 1) " is alive\n"))
(call-api 0)
)
(begin
(add-log (append (sub-list 1) " is dead\n"))
(eval (sub-list 2))
(call-api 0))))

(exit)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: