开发者

is it possible to read /proc/{pid}/stat then transfer to client real time?

开发者 https://www.devze.com 2023-03-24 03:39 出处:网络
suppose i want to monitor mysql, as far as i know, all mysql runtime info is stored in /proc/{mysql_pid}/stat. so is it possi开发者_运维技巧ble to read and parse mysql stat info via node.js and client

suppose i want to monitor mysql, as far as i know, all mysql runtime info is stored in /proc/{mysql_pid}/stat. so is it possi开发者_运维技巧ble to read and parse mysql stat info via node.js and client display the chart real time ?

nagios and alternative is so heavy, and sometimes i just want to monitor some progress info. so i want a lightweight solution.


I tried using Node Inotify, which is an excellent library. Yet, it seems like the proc filesystem doesn't event to inotify when the stat files are changed. If you're watching a file on a normal filesystem, though, this is how you can do it using that library:

sys     = require('sys');
fs      = require('fs');
Inotify = require('inotify').Inotify;

var inotify = new Inotify(); 

function callback(ev) {
  console.log(sys.inspect(ev));
}

var home_dir = {
    path:      '/proc/5499/stat'
  , watch_for: Inotify.IN_ALL_EVENTS
  , callback:  callback
};

var home_watch_descriptor = inotify.addWatch(home_dir);

Just change Inotify.IN_ALL_EVENTS to whatever action you want to watch for, which is documented on the github page I linked.

Sorry this doesn't solve your particular problem, but I thought I'd post it informationally.


I'm assuming you haven't tried implementing a solution to your problem. What exactly do you mean by "real time"? What sort of client are you talking about?

If you're talking about a web browser client, there's no reason you couldn't update some sort of display every half-second with loads of clients (or much faster, if the charts aren't too intricate).

You should be more specific if you want a more specific answer than that.

0

精彩评论

暂无评论...
验证码 换一张
取 消