preface
My previous node data is all stored in mongoDB. By accident, InfluxDB, a timing database, was discovered. So I took a few moments to briefly use it to see if I could replace mongoDB for storing history data.
InfluxDB profile
InfluxDB is an open source timing database. Suitable for processing and analyzing data related to resource data monitoring.
Docs.influxdata.com/influxdb/v1…
The installation
The latest version is V1.6.
Installing InfluxDB is simple (Ubuntu)
curl -sL <https://repos.influxdata.com/influxdb.key> | sudo apt-key add -
source /etc/lsb-release
echo "deb <https://repos.influxdata.com/${DISTRIB_ID,,}> ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update && sudo apt-get install influxdb
sudo service influxdb start
Copy the code
To complete. 😋
Then you can enter Influx pleasurable play on the command line.
Create some data using the command line
create database 'mydb'
use mydb
insert test,tag1=111,tag2=222 field1=111111,field2=222222
Copy the code
You can then query the data. As a novice, of course it is to use tools.
Previous versions came with a Web management interface. The current version is not ~
Attached is a visualization tool github.com/CymaticLabs…
In addition to the two tags, two fields, and an automatically added time, you can see that 😄 is successfully inserted. After all, it’s a sequential database!
In addition to using InfluxDBStudio, another tool, Grafana, is available. If you’re interested in grafana.com, check it out for yourself. Yeah, cool.
Use Nodejs
NPM package www.npmjs.com/package/inf…
The installation
npm install --save influx@next
Copy the code
The first step is to insert data
const Influx = require('influx'); / / package
// Define database connection and data format, create client
const client = new Influx.InfluxDB({
database: 'mydb'.username: 'root'.password: 'root'.hosts: [{ host: 'xx.xx.xx.xxx'}].schema: [{measurement: 'test'.// Similar to the concept of a data table
fields: { / / data table fields, define types, FLOAT/INTEGER STRING/BOOLEAN
field1:Influx.FieldType.INTEGER,
field2:Influx.FieldType.INTEGER,
}, // Tag is an index field. Query speed bar.
tags: ['tag1'.'tag2']}});// Insert data
client.writePoints([
{
measurement: 'test'.fields: {
field1:1231123.field2:44233,},tags: {
tag1:14233.tag2:41122}}])Copy the code
Step 2 Query the data
const Influx = require('influx');
// Same as above.
const client = new Influx.InfluxDB({
database: 'mydb'.username: 'root'.password: 'root'.hosts: [{ host: 'xx.xx.xx.xxx'}].schema: [{measurement: 'test'.// Similar to the concept of a data table
fields: { / / data table fields, define types, FLOAT/INTEGER STRING/BOOLEAN
field1:Influx.FieldType.INTEGER,
field2:Influx.FieldType.INTEGER,
}, // Tag is an index field. Query speed bar.
tags: ['tag1'.'tag2']}});// Get data within 5 minutes
// Regarding the Influx query syntax, it is said to be somewhat similar to mysql. There are no specific studies. Let's just do a quick one right now
client
.query(
` SELECT * FROM "test" WHERE time > now() - 5m `
)
.then(res= > {
console.log(res); // Output an array.
});
Copy the code
conclusion
So far, the project requirements have been basically met. What follows is a variety of fancy queries.
Various links 🔗
- Docs.influxdata.com/influxdb/v1…
- Github.com/CymaticLabs…
- grafana.com
- www.npmjs.com/package/inf…
- www.wugeek.com 😋 this is wuGeek.