UdpTransport.js
948 Bytes
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
"use strict";
//Base Class for influxdb trabsport
let BaseTransport = require('./BaseTransport'),
dgram = require("dgram");
/**
* @class UdpTransport
* @author hbomb qiqi.zhou@gmail.com
*/
class UdpTransport extends BaseTransport {
/**
* @description init options and init database
* @example {
* level:'warn' //logger level
* host:'127.0.0.1' //influxdb host
* port:'4444'//influxdb port
* measurement:'api'//influxdb measurement
* }
*/
constructor(options) {
super(options);
this.name = "udpInfuxdbLogger";
}
/**
* @method addLine
* @description insert a line to influxdb
*/
addLine() {
let socket=dgram.createSocket("udp4"),
opts = this.options,
line = this.options.line,
buf=new Buffer(line),
length = buf.length;
socket.send(buf, 0, length, opts.port,opts.host, function () {
socket.close();
});
}
}
module.exports = UdpTransport;