-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitor.js
More file actions
70 lines (63 loc) · 1.88 KB
/
monitor.js
File metadata and controls
70 lines (63 loc) · 1.88 KB
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
var mkdirp = require("mkdirp")
var fs = require("fs")
function init(config) {
mkdirp.sync(config.LOGDIR + "memory/")
var Nopen = "-1"
// Monitor and log memory usage every 1000 ms.
setInterval(function () {
var tmp = new Date()
mem = process.memoryUsage()
var yyyymmdd = tmp.toISOString().substring(0,10)
var file = config.LOGDIR + "memory/datacache_" + config.PORT + "_memory_"+yyyymmdd+".log"
fs.appendFile(file, tmp.toISOString() + " " + mem.rss + " " + mem.heapTotal + " " + mem.heapUsed + " " + Nopen + "\n")
},1000)
// Count number of open files and pipes every 1000 ms.
setInterval(function () {
//var com = 'lsof -p ' + process.pid + ' | grep REG | grep datacache/cache'
var com = 'lsof -p ' + process.pid
require('child_process').exec(com,
function (error,stdout,stderr) {
var filelist = stdout.split("\n")
Nopen = filelist.length
return
if (filelist.length > 0 && filelist[0] !== '') {
console.log("Open files:")
for (var i = 0; i < filelist.length; i++) {
var file = filelist[i]
console.log(file)
}
}
}
)
},1000)
if (0) {
// sudo apt-get install inotify-tools
var filemon = require('filemonitor');
var onFileEvent = function (ev) {
console.log("File " + ev.filename + " triggered event " + ev.eventId + " on " + ev.timestamp.toString());
}
var onFileCreation = function (ev) {
console.log("File " + ev.filename + " was created on " + ev.timestamp.toString());
}
var options = {
recursive: true,
target: "./cache/",
listeners: {
all_events: onFileEvent,
create: onFileCreation
}
}
filemon.watch(options);
}
if (0) {
fs.watch('somedir', function (event, filename) {
console.log('event is: ' + event);
if (filename) {
console.log('filename provided: ' + filename);
} else {
console.log('filename not provided');
}
})
}
}
exports.init = init