newlsip 检查磁盘分区使用情况

主要还是用df -k这个命令,然后将输出结果全部逐行解析,最后调用REST API,发送给服务器保存。

参考代码:

 

#!/usr/bin/newlisp

(set 'cur-path "/opt/detector")
(load (append cur-path "/config.lsp"))
(define (add-log msg)
  (println msg)
  (append-file (append cur-path "/disk.log") (append "\n" (string (now 480)) " "))
  (append-file (append cur-path "/disk.log") (append  ": " msg))
  )

(define (process-record record)
  (add-log record)
  (set 'l (parse record))
  (set 'type (last l))
  (set 'a (int (l 1)))
  (set 'b (int (l 2)))
  (if (and a b)
      (begin
       (set 'll (div b a))
       ;;  (add-log (format "%lld,%lld,%f" a b ll))                                                                                                                              
       (set 'data (format "ip=%s&hostName=%s&type=fs_%s&values=%lld|%f" ip host_name type (date-value) ll))
       (add-log data)
       (set 'r3 (post-url (format "http://%s/wind_tunnel/api/post/data" server) data))
       (add-log r3))))

(define (check-disk)
  (set 'r (exec "df -k"))
  (pop r)
  (dolist (x r)
    (process-record x)))

(check-disk)

(exit)


 

 

posted on 2013-10-29 21:30  you Richer  阅读(154)  评论(0编辑  收藏  举报