newlisp获取并计算内存负载
下面的代码计算Linux下的内存负载
#!/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 "/mem.log") (append "\n" (string (now 480)) " ")) (append-file (append cur-path "/mem.log") (append ": " msg)) )(define (check-mem) (set 'in-file (open "/proc/meminfo" "read")) (set 'line1 (read-line in-file)) (set 'line2 (read-line in-file)) (set 'line3 (read-line in-file)) (set 'line4 (read-line in-file)) (add-log line1) (add-log line2) (add-log line3) (add-log line4) (set 'total-mem (int ((parse line1) 1))) (set 'free-mem (int ((parse line2) 1))) (set 'buffer-mem (int ((parse line3) 1))) (set 'cached-mem (int ((parse line4) 1))) (set 'll (div (- (- (- total-mem free-mem) buffer-mem) cached-mem) (int total-mem))) (add-log (string ll)))(check-mem)(exit)