elasticsearch-watchdog
Version:
A watchdog of elasticsearch - cluster nodes' statuses monitor, auto restart, keep PRIMARY node unique.
41 lines (36 loc) • 1.07 kB
JavaScript
var express = require('express'),
swig = require('swig'),
path = require('path'),
chalk = require('chalk'),
_ = require('lodash'),
mon = require('../util/mon');
module.exports = function(port){
var app = express();
// all environments
app.set('view engine', 'html');
app.set('views', path.join(__dirname, 'views'));
app.engine('html', swig.renderFile);
app.use(express.static(path.join(__dirname, 'public')));
// router
// get all processes.
app.get('/', function(req, res, next){
res.redirect('/html')
});
app.get('/:type', function(req, res, next){
if (req.params.type == 'json') {
mon.list(false, function(err, data){
if (err) {
return res.json({error: err.message});
}
res.status(200).json(data);
});
} else {
res.render('index', {title: 'Puppies'});
}
});
if (!port || isNaN(port)) {
port = 8088;
}
app.listen(port);
console.log('\n', chalk.bold('Watchdog server is listening on port ') + chalk.bold.magenta(port), '\n');
}