mkjiau / taifex-scrapy

0 stars 0 forks source link

influx #5

Open mkjiau opened 4 years ago

mkjiau commented 4 years ago
const Influx = require('influx');
const influx = new Influx.InfluxDB({
 host: 'localhost',
 database: 'taifex_db',
 schema: [
   {
     measurement: 'dlFutDataDown',
     fields: {
       '成交量': Influx.FieldType.STRING,
    //    duration: Influx.FieldType.INTEGER
     },
     tags: [
       '契約'
     ]
   }
 ]
})

// SELECT * FROM "taifex_db"."autogen"."dlFutDataDown" WHERE  time > '2020-01-01T00:00:00Z' AND time < '2020-07-01T00:00:00Z'  AND  "契約"='MTX' 
influx.query(`
    SELECT * FROM "taifex_db"."autogen"."dlFutDataDown"
    WHERE time > '2020-01-01T00:00:00Z' AND time < '2020-07-01T00:00:00Z' AND "契約"='MTX'
  `).then(result => {
    console.log('result', result)
  }).catch(err => {
    console.log('err', err)
  })
mkjiau commented 4 years ago

https://github.com/node-influx/node-influx/tree/master/examples/express_response_times
https://node-influx.github.io/class/src/index.js~InfluxDB.html#instance-method-query
https://node-influx.github.io/class/src/index.js~InfluxDB.html
https://node-influx.github.io/manual/tutorial.html

mkjiau commented 4 years ago

InfluxDB

https://docs.influxdata.com/influxdb/v1.8/concepts/key_concepts/ https://docs.influxdata.com/influxdb/v1.8/concepts/glossary/

Databases > Collections > Documents (JSON Docs)
Databases > Tables > Rows
Databases > Measurements > Points

Points consists of:

The structure is of the data is: (InfluxDB line protocol tutorial)

https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_tutorial/

    +-----------+--------+-+---------+-+---------+
    |measurement|,tag_set| |field_set| |timestamp|
    +-----------+--------+-+---------+-+---------+
measurement_name,tag_key1=tag_val1,tag_key2=tag_val2 field_key1=field_val1,field_key1=field_val1 timestamp

For example:

weather,location=us-midwest temperature=82 1465839830100400200
mkjiau commented 4 years ago
SELECT "water_level" FROM "NOAA_water_database"."autogen"."h2o_feet"

SELECT mean("water_level") AS "mean_water_level" FROM "NOAA_water_database"."autogen"."h2o_feet" WHERE  "location"='coyote_creek'

SELECT mean("water_level") AS "mean_water_level" FROM "NOAA_water_database"."autogen"."h2o_feet" WHERE  "location"='coyote_creek' GROUP BY time(30m) FILL(null)

SHOW TAG KEYS ON "NOAA_water_database" FROM "h2o_feet"
SHOW TAG VALUES ON "NOAA_water_database" FROM "h2o_feet" WITH KEY = "location"

Cardinality (The number of elements in a set/measurement)
SHOW FIELD KEY CARDINALITY ON "NOAA_water_database"
measurement count
average_temperature 1
h2o_feet    2
h2o_pH  1
h2o_quality 1
h2o_temperature 1

SHOW MEASUREMENT CARDINALITY ON "NOAA_water_database"
cardinality estimation
5

h2o_feet,location=santa_monica water_level=5.614,level\ description="between 3 and 6 feet" 1440902880

h2o_quality,location=santa_monica,randtag=1 index=42 1441828440

INSERT temperature,machineId=1,type=boiler actualTemperature=30,targetTemperature=32 
mkjiau commented 4 years ago

telegraf

curl -i -XPOST 'http://localhost:9001/telegraf' --data-binary 'price,type=BTC close=13333.0,high=1111.0,low=1111.0,open=1111.5,volume=400111 1529290060000000000'

SELECT "high", "low", "open", "volume", "close" FROM "mytail2"."autogen"."price" WHERE time > :dashboardTime:

sandbox enter telegraf
cd /etc/telegraf/
telegraf --config http_service.conf
mkjiau commented 4 years ago
use taifex_db
SELECT COUNT(*) FROM "taifex_db"."autogen"."dlFutDataDown" WHERE "契約"='TE' 
DELETE FROM "dlPcRatioDown" WHERE time > 0
DROP MEASUREMENT dlFutDataDown  # ./sandbox influxdb