1 | 'use strict'
|
2 |
|
3 | const stream = require('stream')
|
4 |
|
5 | class ProcessStatToCSV extends stream.Transform {
|
6 | constructor (interval) {
|
7 | super({
|
8 | readableObjectMode: false,
|
9 | writableObjectMode: true
|
10 | })
|
11 |
|
12 | this._interval = interval
|
13 |
|
14 | this.push('timestamp, interval, delay, cpu, memory.rss, ' +
|
15 | 'memory.heapTotal, memory.heapUsed, memory.external, handles\n')
|
16 | }
|
17 |
|
18 | _transform (data, encoding, done) {
|
19 | const time = data.timestamp
|
20 | const inInterval = time >= this._interval[0] && time <= this._interval[1]
|
21 |
|
22 | this.push(`${data.timestamp}, ${inInterval ? 1 : 0}, ${data.delay}, ` +
|
23 | `${data.cpu}, ${data.memory.rss}, ${data.memory.heapTotal}, ` +
|
24 | `${data.memory.heapUsed}, ${data.memory.external}, ` +
|
25 | `${data.handles}\n`)
|
26 | done(null)
|
27 | }
|
28 | }
|
29 |
|
30 | module.exports = ProcessStatToCSV
|