-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (33 loc) · 891 Bytes
/
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
const numerify = require('./lib/numerify');
const { pattern } = require('./lib/pattern');
const NUMERIC_FIELDS = [
'took_millis',
'num_yields',
'resp_length'
];
module.exports = (string) => {
const match = pattern.exec(string);
if (!match) {
return {};
}
const [, timestamp, severity, operation, connection_id, namespace, command, action, num_yields, resp_length, protocol, took_millis] = match;
return process({
timestamp,
severity,
operation,
connection_id,
namespace,
command,
action,
num_yields,
resp_length,
protocol,
took_millis
});
};
function process(entry) {
// convert elasticsearch timestamp to unix timestamp
entry.timestamp = Date.parse(entry.timestamp.replace(',', '.'));
numerify(entry, NUMERIC_FIELDS);
return entry;
}