-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_app.js
65 lines (56 loc) · 1.64 KB
/
report_app.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
/**
* New node file
*/
var config = require('./config.js'),
http = require('http'),
redis = require("redis"),
client = redis.createClient(),
os = require('os'),
crypto = require('crypto');
var data = {};
data.server = {};
data.server.port = config.server.port;
data.server.hostname = os.hostname();
data.server.type = os.type();
data.server.arch = os.arch();
data.server.platform = os.platform();
data.server.release = os.release();
data.server.uptime = os.uptime();
data.server.load = os.loadavg();
data.server.cpu = os.cpus();
data.server.memory_total = os.totalmem();
data.server.memory_free = os.freemem();
data.software = {};
data.software.id = config.server.id;
data.software.version = -1; // TODO
data.redis = {};
data.redis.host = config.redis.host;
data.redis.port = config.redis.port;
data.redis.size = -1; // TODO
data.usage = {};
data.usage.requests = -1; // TODO
data.usage.uniqueDevices = -1; // TODO
data.usage.localRequests = -1; // TODO
data.usage.externalRequest = -1; // TODO
var json_data = JSON.stringify(data);
var send_data = 'report=' + json_data + '&hash=' + crypto.createHash('md5').update(json_data).digest("hex");
console.log(send_data);
// TODO: add hash signature with local secret
var options = {
host: config.report.server,
port: config.report.port,
path: config.report.path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': send_data.length
}
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log("body: " + chunk);
});
});
req.write(send_data);
req.end();