@icgio/icg-utils 1.7.27 → 1.7.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/influxdb.js +28 -22
- package/lib/logger.js +1 -1
- package/package.json +3 -5
package/lib/influxdb.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
|
|
3
|
+
const { parse } = require('csv-parse')
|
|
4
|
+
|
|
3
5
|
const { InfluxDB, Point } = require('@influxdata/influxdb-client')
|
|
4
6
|
const { BucketsAPI } = require('@influxdata/influxdb-client-apis')
|
|
5
7
|
|
|
@@ -27,31 +29,35 @@ function check_points(points) {
|
|
|
27
29
|
module.exports = class Influx {
|
|
28
30
|
constructor(config) {
|
|
29
31
|
const { url, token, org, org_id, bucket, schema } = config
|
|
30
|
-
|
|
31
|
-
this.buckets_api = new BucketsAPI(influx_db)
|
|
32
|
-
this.write_api = influx_db.getWriteApi(org, bucket)
|
|
33
|
-
this.query_api = influx_db.getQueryApi(org)
|
|
32
|
+
this.influx_db = new InfluxDB({ url, token })
|
|
33
|
+
this.buckets_api = new BucketsAPI(this.influx_db)
|
|
34
34
|
this.org = org
|
|
35
35
|
this.org_id = org_id
|
|
36
36
|
this.bucket = bucket
|
|
37
37
|
this.bucket_exist = false
|
|
38
38
|
this.schema = schema
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
async query(query_string, cb) {
|
|
41
|
+
const query_api = this.influx_db.getQueryApi(this.org)
|
|
42
|
+
let result = await query_api.queryRaw(query_string)
|
|
43
|
+
let temp = parse(
|
|
44
|
+
result,
|
|
45
|
+
{
|
|
46
|
+
columns: true,
|
|
47
|
+
comment: '#',
|
|
48
|
+
skip_empty_lines: true,
|
|
49
|
+
},
|
|
50
|
+
(err, res) => {
|
|
51
|
+
if (!err) {
|
|
52
|
+
cb({ success: true, body: res })
|
|
53
|
+
} else {
|
|
54
|
+
cb({ success: false, body: err })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
}
|
|
54
59
|
async write_points_with_check(points, cb) {
|
|
60
|
+
const write_api = this.influx_db.getWriteApi(this.org, this.bucket)
|
|
55
61
|
if (!this.bucket_exist) {
|
|
56
62
|
const { buckets } = await this.buckets_api.getBuckets({ org: this.org })
|
|
57
63
|
const names = buckets.map((b) => b.name)
|
|
@@ -77,17 +83,17 @@ module.exports = class Influx {
|
|
|
77
83
|
}
|
|
78
84
|
return p_temp
|
|
79
85
|
})
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
write_api.writePoints(points)
|
|
87
|
+
write_api
|
|
82
88
|
.close()
|
|
83
89
|
.then(() => {
|
|
84
90
|
cb({ success: true, body: points.length })
|
|
85
91
|
})
|
|
86
92
|
.catch((err) => {
|
|
87
|
-
cb({ success: false,
|
|
93
|
+
cb({ success: false, body: err })
|
|
88
94
|
})
|
|
89
95
|
} else {
|
|
90
|
-
cb({ success: false,
|
|
96
|
+
cb({ success: false, body: 'points-error' })
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
}
|
package/lib/logger.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-utils",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.29",
|
|
4
4
|
"description": "Utils package.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -22,17 +22,15 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@influxdata/influxdb-client": "^1.33.0",
|
|
24
24
|
"@influxdata/influxdb-client-apis": "^1.33.0",
|
|
25
|
-
"
|
|
25
|
+
"csv-parse": "^5.3.3",
|
|
26
26
|
"external-ip": "^2.3.1",
|
|
27
27
|
"htmlparser2": "^3.10.1",
|
|
28
|
-
"influx": "^5.9.3",
|
|
29
28
|
"lodash": "^4.17.21",
|
|
30
29
|
"mailgun-js": "^0.18.1",
|
|
31
30
|
"needle": "^3.2.0",
|
|
32
31
|
"nodemailer": "^4.7.0",
|
|
33
32
|
"qrcode-terminal": "^0.12.0",
|
|
34
33
|
"websocket": "^1.0.33",
|
|
35
|
-
"winston": "^2.4.5"
|
|
36
|
-
"winston-papertrail": "^1.0.5"
|
|
34
|
+
"winston": "^2.4.5"
|
|
37
35
|
}
|
|
38
36
|
}
|