newlisp 监控Linux进程 一
来源:互联网 发布:java定义整形数组 编辑:程序博客网 时间:2024/06/11 06:33
之前我的newlisp 监控redmine中描述了监控redmine进程的方法,今天更进一步,添加一个配置文件,里面描述了要监控的进程list,这样每次逐个检查本机的进程.
先来实现个简单的检查,一个函数check-proces,接受一个字符串,用来检查进程是否存在
#!/usr/bin/newlisp(define (check-process filter-str) (set 'r (exec (append "ps -def | grep " filter-str))) (set 'l (length r)) (> l 3))(if (check-process "dispatch") (println "redmine is alive") (println "redmine is dead"))(exit)
好,添加一个配置文件叫做filter.lsp, 下面的filters是一个list,里面每个元素也是一个list,并且分两部分,一是用来检查进程的字符串,二是要检查进程的有意义的名称,可以用于写日志。
(set 'filters (list '("dispatch" "redmine")))
然后之前的process.lsp内容修改为:
#!/usr/bin/newlisp(load "/opt/detector/filter.lsp")(define (check-process filter-str) (set 'r (exec (append "ps -def | grep " filter-str))) (set 'l (length r)) (= 3 l))(dolist (sub-list filters) (if (check-process (first sub-list)) (println (append (sub-list 1) " is alive")) (println (append (sub-list 1) " is dead"))))(exit)
ok, 再进一步,写日志, 添加了add-log函数
#!/usr/bin/newlisp(set 'cur-path "/opt/detector")(load (append cur-path "/filter.lsp"))(define (check-process filter-str) (set 'r (exec (append "ps -def | grep " filter-str))) (set 'l (length r)) (= 3 l))(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)) )(dolist (sub-list filters) (if (check-process (first sub-list)) (add-log (append (sub-list 1) " is alive\n")) (add-log (append (sub-list 1) " is dead\n"))))(exit)
- newlisp 监控Linux进程 一
- newlisp 监控Linux进程 二
- newlisp 监控Linux进程 三
- newlisp 监控Linux进程 四
- newlisp 监控Linux进程 四
- newlisp 监控redmine
- 杀掉所有newlisp进程
- Linux进程实时IO监控iotop命令详解(系列一)
- 监控Linux进程
- linux 进程监控 shell
- Linux进程监控日志
- linux进程监控
- linux-进程监控
- linux 进程监控
- Linux进程监控
- 监控Linux进程状态
- Linux 下简单监控进程
- linux shell脚本-监控进程
- 十天的心理挑战
- 采用Jdic播放flash
- 互联网金融多模式发展 非资金基金模式回报更高
- Word2003、2007和2010文档隐藏回车换行符的方法
- KERNEL REQUIRES AN X86-64 CPU, BUT ONLY DETECTED AN I686 CPU
- newlisp 监控Linux进程 一
- LeetCode Copy List with Random Pointer 分析解答
- 解析linux根文件系统的挂载过程
- fstat、stat和lstat 区别(转)
- Jacobi 方法
- Android开发中遇到的错误
- java 下载文件 兼容 ie 火狐 google 浏览器 ,解决下载文件乱码问题
- Method Swizzling
- Tomcat 配置(解决一闪而过的问题)