newlisp 监控Linux进程 四
来源:互联网 发布:.手机域名在哪里注册 编辑:程序博客网 时间:2024/06/05 21:27
本节尝试将监控进程的方式交给调用者。主要有两个原因:
1. 调用者传递判定代码,这样可以根据不同的平台进行变化,比如windows肯定没有ps -def 命令。这样可以适应更多的情况
2. ps -def | grep ***的方式,在newlisp中返回的表的元素数目少数时候会少一个元素,比如我在监控mongodb的时候遇到下面的元素有时候得不到。
"root 10658 10655 0 00:46 ? 00:00:00 grep mongodb"因此如果还用
(> l 2)来判断是不正确的,会误报。
先调整一下filter.lsp,如下例:
(set 'filters (list '((exec "pidof mongod") "mongodb" (exec "service mongodb start")) ))第一个元素现在是一个list,运行pidof命令,如果找到mongod进程,则返回含有进程id的list,否则返回()
再修改一下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 check-cmd) (set 's (eval check-cmd)) (add-log (string s)) s ) (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-name process-status) (set 'data (format "ip=%s&hostName=%s&type=proc_%s&values=%lld|%f" ip host_name process-name (date-value) process-status)) (println data) (set 'r3 (post-url (format "http://%s/wind_tunnel/api/post/data" 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 (sub-list 1) 1.0) ) (begin (add-log (append (sub-list 1) " is dead\n")) (eval (sub-list 2)) (call-api (sub-list 1) 0)))) (exit)
好,现在MongoDB进程监控正常了,不会误报。并且可以在filter.lsp中配置各种专用命令来检测进程。
- newlisp 监控Linux进程 四
- newlisp 监控Linux进程 四
- newlisp 监控Linux进程 一
- newlisp 监控Linux进程 二
- newlisp 监控Linux进程 三
- newlisp 监控redmine
- 杀掉所有newlisp进程
- 监控Linux进程
- linux 进程监控 shell
- Linux进程监控日志
- linux进程监控
- linux-进程监控
- linux 进程监控
- Linux进程监控
- 监控Linux进程状态
- Linux 下简单监控进程
- linux shell脚本-监控进程
- Linux进程实时监控 - htop
- Struts2之Action基础与配置
- 部分iPad mini 2存屏幕残影问题
- CSDN网盘入口
- 新闻门户网站如何进行SEO优化
- JRadioButton单选按钮代码2
- newlisp 监控Linux进程 四
- 定制iOS 7中的导航栏和状态栏
- alsa编程
- linux进程间通信概述
- C#总结1
- WebKit加载网页的流程
- 有一个分数数列2/1,3/2,5/3,8/5,。。。。。求出这个数列的前20项之和
- PackageManagerService对象构造过程
- alsa声音编程介绍