mazaid-rest-exec-tasks
Version:
exec tasks REST API
112 lines (97 loc) • 2.63 kB
JavaScript
var request = require('superagent');
var startPing = function (host) {
request.post('http://localhost:8084/execTasks')
.send({
type: 'exec',
data: {
command: 'ping -c 3 ' + host
}
})
.end(function (err, res) {
console.log(err, res.body.result.id);
});
};
var startHttp = function (url) {
request.post('http://localhost:8084/execTasks')
.send({
type: 'http',
data: {
method: 'GET',
url: url
}
})
.end(function (err, res) {
console.log(err, res.body.result.id);
});
};
var start = function () {
startPing('ngs.ru');
startPing('n1.ru');
startPing('monitor.n1.s');
startPing('selectel.ru');
startHttp('http://ngs.ru');
startHttp('http://novosibirsk.n1.ru');
startHttp('http://api.n1.ru/api/v1/offers/?limit=1');
startHttp('http://novosibirsk.n1.ru/search/');
startHttp('http://www.n1.ru/');
startHttp('http://realty.ngs.ru/');
var date = (new Date()).getTime();
date = date / 1000;
date = date.toFixed(0);
date = parseInt(date);
request.post('http://localhost:4242/api/put')
.send([{
"metric": "req.count",
"timestamp": date,
"value": 10,
"tags": {
"host": "exec-tasks"
}
}]).end(function (err, res) {
console.log(err, res.body);
});
};
start();
setInterval(function () {
start();
}, 60000);
setInterval(function () {
var date = (new Date()).getTime();
date = date / 1000;
date = date.toFixed(0);
date = parseInt(date);
request.post('http://localhost:4242/api/put')
.send([{
"metric": "gc",
"timestamp": date,
"value": 10,
"tags": {
"host": "exec-tasks"
}
}])
.end(function (err, res) {
// console.log('GC', err, res.body);
});
request.post('http://localhost:8084/_profile/gc/start')
.end(function (err, res) {
console.log('GC', err, res.body);
});
}, 5000);
// setInterval(function () {
// var date = (new Date()).getTime();
// date = date / 1000;
// date = date.toFixed(0);
// date = parseInt(date);
//
// request.post('http://localhost:4242/api/put')
// .send([{
// "metric": "req.count",
// "timestamp": date,
// "value": 0,
// "tags": {
// "host": "exec-tasks"
// }
// }]).end(function (err, res) {
// console.log(err, res.body);
// });
// }, 4000);