@icgio/icg-utils 1.7.32 → 1.7.34
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 +20 -25
- package/package.json +1 -1
package/lib/influxdb.js
CHANGED
|
@@ -15,17 +15,6 @@ function fields_check(fields) {
|
|
|
15
15
|
return result
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function check_points(points) {
|
|
19
|
-
return points.filter((point) => {
|
|
20
|
-
if (fields_check(point.fields) && (!point.timestamp || point.timestamp instanceof Date)) {
|
|
21
|
-
return true
|
|
22
|
-
} else {
|
|
23
|
-
console.error('influx check_points', point)
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
18
|
module.exports = class Influx {
|
|
30
19
|
constructor(config) {
|
|
31
20
|
const { url, token, org, org_id, bucket, schema } = config
|
|
@@ -67,8 +56,17 @@ module.exports = class Influx {
|
|
|
67
56
|
} else {
|
|
68
57
|
this.bucket_exist = true
|
|
69
58
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
59
|
+
}
|
|
60
|
+
points = points
|
|
61
|
+
.filter((point) => {
|
|
62
|
+
if (fields_check(point.fields) && (!point.timestamp || point.timestamp instanceof Date)) {
|
|
63
|
+
return true
|
|
64
|
+
} else {
|
|
65
|
+
console.error('influx check_points', point)
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
.map((p) => {
|
|
72
70
|
let p_temp = new Point(p.measurement)
|
|
73
71
|
for (let tag in p.tags) {
|
|
74
72
|
p_temp = p_temp.tag(tag, p.tags[tag])
|
|
@@ -86,17 +84,14 @@ module.exports = class Influx {
|
|
|
86
84
|
}
|
|
87
85
|
return p_temp
|
|
88
86
|
})
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
cb({ success: false, body: 'points-error' })
|
|
100
|
-
}
|
|
87
|
+
write_api.writePoints(points)
|
|
88
|
+
write_api
|
|
89
|
+
.close()
|
|
90
|
+
.then(() => {
|
|
91
|
+
cb({ success: true, body: points.length })
|
|
92
|
+
})
|
|
93
|
+
.catch((err) => {
|
|
94
|
+
cb({ success: false, body: err })
|
|
95
|
+
})
|
|
101
96
|
}
|
|
102
97
|
}
|