newlisp 获取cpu信息

发布时间:2016-12-7 5:47:43 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"newlisp 获取cpu信息",主要涉及到newlisp 获取cpu信息方面的内容,对于newlisp 获取cpu信息感兴趣的同学可以参考一下。

紧跟前文Linux CPU 负载度量公式,用newlisp写了一个获取本机cpu信息的小程序,每次都会调用REST API将数据发送给web server.#!/usr/bin/newlisp (load "config.lsp") (define (add-log msg) (append-file "cpu.log" (append "\n" (string (now 480)) " ")) (append-file "cpu.log" (append ": " msg)) ) ;; return a list ;; which contains total_jiffies and work_jiffies (define (check-cpu) (set 'in-file (open "/proc/stat" "read")) (set 'line (read-line in-file)) (set 'r (parse line)) (close in-file) (set 'total_jiffies 0) (println r) (set 'i 1) (do-while (< i 8) (set 'total_jiffies (+ total_jiffies (int (nth i r)))) (inc i) ) (set 'work_jiffies 0) (set 'i 1) (do-while (< i 3) (set 'work_jiffies (+ work_jiffies (int (nth i r)))) (inc i) ) (list total_jiffies work_jiffies) ) (set 'r2 (check-cpu)) (set 'r3 (post-url "http://localhost/wind_tunnel/api/post/cpu" (format "ip=%s&hostName=%s&epoch=%lld&totalJiffies=%lld&workJiffies=%lld" ip host_name 123456789 (nth 0 r2) (nth 1 r2)))) (add-log r3) (exit) config.lsp很简单,两行配置:(set 'host_name "beijinghome") (set 'ip "192.168.1.101")

上一篇:java基础入门----多线程1
下一篇:LINUX&nbsp;AS4&nbsp;系统下安装oracle&nbsp;10g终…

相关文章

相关评论