@icgio/icg-utils 1.7.33 → 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 +19 -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
|
-
points.filter((point) => {
|
|
20
|
-
if (fields_check(point.fields) && (!point.timestamp || point.timestamp instanceof Date)) {
|
|
21
|
-
} else {
|
|
22
|
-
console.error('influx check_points', point)
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
18
|
module.exports = class Influx {
|
|
30
19
|
constructor(config) {
|
|
31
20
|
const { url, token, org, org_id, bucket, schema } = config
|
|
@@ -68,8 +57,16 @@ module.exports = class Influx {
|
|
|
68
57
|
this.bucket_exist = true
|
|
69
58
|
}
|
|
70
59
|
}
|
|
71
|
-
|
|
72
|
-
|
|
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) => {
|
|
73
70
|
let p_temp = new Point(p.measurement)
|
|
74
71
|
for (let tag in p.tags) {
|
|
75
72
|
p_temp = p_temp.tag(tag, p.tags[tag])
|
|
@@ -87,17 +84,14 @@ module.exports = class Influx {
|
|
|
87
84
|
}
|
|
88
85
|
return p_temp
|
|
89
86
|
})
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
cb({ success: false, body: 'points-error' })
|
|
101
|
-
}
|
|
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
|
+
})
|
|
102
96
|
}
|
|
103
97
|
}
|