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)
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)
相关文章推荐
- newlisp 监控Linux进程 二
- newlisp 监控Linux进程 四
- newlisp 监控Linux进程 一
- newlisp 监控Linux进程 四
- 使用Shell来监控linux系统和进程(3)
- Linux 后台进程管理器 supervisor 安装配置(使用httpd来做被监控进程)
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 【Linux安全】系统资源监控与进程终止
- Linux 下简单监控进程
- Linux监控脚本监控后台进程,当进程死掉后重新启动服务
- linux进程监控与自动重启实现
- 监控Linux进程
- RHEL六(监控和管理Linux进程)
- Shell脚本实现Linux系统和进程资源监控
- 用NetHogs监控Linux每个进程的网络使用情况
- 用Shell脚本定时监控Linux下的进程状态并自动重启
- Linux 进程资源用量监控和按用户设置进程限制
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- Linux 运行进程实时监控pidstat命令详解