2015-07-20 77 views
1
extend layout 
block content 

script. 
    var monitor = require("os-monitor"); 

    monitor.start(); 

    monitor.start({ 
    delay: 3000 
    , freeman: 1000000000 
    , uptime: 1000000 
    , critical1: 0.7 
    , critical5: 0.7 
    , critical15: 0.7 
    , silent: false 
    , stream: false 
    , immediate: false 
    }); 
    monitor.on('monitor',function(event) { 
    console.log(event.type, 'This event always happens on each monitor cycle!'); 
    }); 
    monitor.on('loadavg1',function(event) { 
    console.log(event.type, 'Load average is exceptionally high!'); 
    }); 
    monitor.on('freemem',function(event) { 
    console.log(event.type, 'Free memory is very low!'); 
    }); 
    monitor.throttle('loadavg5',function(event) { 
    },monitor,minutes(5)); 
    monitor.config({ 
    freemem: 0.3 
    }); 
    monitor.stop(); 
    monitor.isRunning(); 
    monitor.start({stream:true}).pipe(process.stdout); 



block side bar 
    .widget 
    h1 Widget 
    p 
    | Sed ccccc rhoncus ut 
    | eleifvvvv in nulla enim. 
    p 
    | Vivambbbbbbbbbbbbt molestie 
    | vebula. 

運行在網頁

var express = require('express'); 
 
var stylus = require('stylus'); 
 
var nib = require('nib'); 
 

 
var app = express(); 
 

 
function compile(str, path) { 
 
    return stylus(str) 
 
\t .set('filename', path) 
 
\t .use(nib()) 
 
} 
 
app.set('views', __dirname + '/views'); 
 
app.set('view engine', 'jade'); 
 
app.use(express.logger('dev')); 
 
app.use(stylus.middleware({ 
 
    src: __dirname + '/public', 
 
    compile: compile 
 
})); 
 
app.use(express.static(__dirname + '/public')); 
 

 
app.get('/', function(req, res) { 
 
    res.render('index', { 
 
\t title: 'Home' 
 
    }) 
 
}); 
 
app.listen(3000, function() { 
 
    console.log('Server start http://localhost:3000'); 
 
});
的node.js模塊,我做了一個簡單的網站和服務器與玉Node.js的。 我希望網站顯示進程狀態,不僅在終端中,所以我發現一些模塊(npm os-monitor,cpu-usage)來檢查我的進程狀態。但我不知道如何在網絡上運行它們。

回答

0

你可能更喜歡使用類似socket.io的東西來將數據從服務器傳遞到瀏覽器。使用os-monitor或您希望在服務器上使用的任何其他模塊(在您的app.js中),然後將數據廣播或單獨發送給瀏覽器客戶端。

+0

我的天啊。你救我。謝謝!我會嘗試 :) – Jemkim