-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
110 lines (102 loc) · 2.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var express = require('express'),
os=require('os'),
pm2=require('pm2'),
app = express();
//Information
app.get('/serverStat',function(req,res){
var _stat={
system_info:{
hostName:os.hostname(),
uptime:os.uptime()
},
monit:{
loadavg:os.loadavg(),
total_mem:os.totalmem(),
free_mem:os.freemem(),
cpu:os.cpus(),
interfaces:os.networkInterfaces()
},
os:{
type:os.type(),
platform:os.platform(),
release:os.release(),
},
cpu_arch:os.arch(),
loadAvg:os.loadavg(),
};
pm2.connect(function(){
pm2.list(function(err,list){
pm2.disconnect();
_stat.processes=list;
res.json(_stat);
});
});
});
//Operations
app.get('/operations/stop/:id',function(request,response){
if(!request.params.id){
response.send(400 ,{
error:"Process id not supplied"
});
return;
}
pm2.connect(function(){
pm2.stop(request.params.id,function(err,details){
if(err){
console.log(err);
response.send(err)
}else
response.send(details);
pm2.disconnect();
})
});
});
app.get('/operations/restart/:id',function(request,response){
if(!request.params.id){
response.send(400 ,{
error:"Process id not supplied"
});
return;
}
pm2.connect(function(){
pm2.restart(request.params.id,function(err,details){
if(err){
console.log(err);
response.send(err)
}else
response.send(details);
pm2.disconnect();
})
});
});
app.get('/operations/delete/:id',function(request,response){
if(!request.params.id){
response.send(400 ,{
error:"Process id not supplied"
});
return;
}
pm2.connect(function(){
pm2.delete(request.params.id,function(err,status){
if(err){
console.log(err);
response.send(err)
}else
response.send(status);
pm2.disconnect();
})
});
});
app.get('/operations/kill',function(request,response){
pm2.connect(function(){
pm2.killDaemon(function(err,status){
if(err){
console.log(err);
response.send(err)
}else
response.send(status);
})
});
});
app.use('/',express.static(__dirname+'/web/'));
var server = app.listen(3190);