This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmockup.js
78 lines (66 loc) · 1.93 KB
/
mockup.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const Influx = require('influx');
// http://docs.grafana.org/features/datasources/influxdb/
// http://docs.grafana.org/reference/annotations/
// http://docs.grafana.org/http_api/annotations/
// https://play.grafana.org/d/000000059/influxdb-table?orgId=1
const influx = new Influx.InfluxDB({
host: 'localhost',
database: 'historian',
schema: [{
measurement: 'process',
fields: {
value: Influx.FieldType.FLOAT,
},
tags: [
'unit',
'sensor_name',
'sensor_type',
]
}]
})
// time reading sensor_type sensor_name unit
// <someTimestamp> 450 temperature T101 °C
// <someTimestamp> 320 pressure P101 bar(a)
// https://stackoverflow.com/a/1527820/3991125
const getRandomInt = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const writeDummyData = () => {
console.log('writing dummy data to InfluxDB ...')
return influx.writeMeasurement('process', [
{
fields: {
value: getRandomInt(100, 200),
},
tags: {
unit: 'bar(a)',
sensor_name: 'P101',
sensor_type: 'pressure'
},
},
{
fields: {
value: getRandomInt(20, 120),
},
tags: {
unit: '°C',
sensor_name: 'T101',
sensor_type: 'temperature'
},
},
{
fields: {
value: getRandomInt(450, 600),
},
tags: {
unit: 'K',
sensor_name: 'T102',
sensor_type: 'temperature'
},
},
])
.catch( (err) => console.log(err) )
}
setInterval(writeDummyData, 1000);