Post on 16-Apr-2017
InfluxDBTime Series Database
InfluxDB
● Written in go● Uses Time Series Merge tree as internal DB engine (v0.10)● Self contained binary● No external dependency● Provides cluster support● Provides HTTP Native support by doing read/write, manage data via HTTP● Provides security based on users and their permissions● SQL style queries
InfluxDB Data Organization
● Databases like mysql● Time series like tables● Points or tags like rows
Example:Measurement are events like search_event, cpu_usage etc (which is a time series). Each measurement has tags (query_param, location), points and timestamp.All data is indexed by measurement, tag and timestamp.
Installation
● May require root or administrator privileges in order to complete installation.
● Ubuntu○ sudo apt-get update && sudo apt-get install influxdb○ sudo service influxdb start
● generate a new configuration file○ influxd config > influxdb.generated.conf○ Edit generated config file based on required configration.
● Start influx demon with config file:○ influxd -config influxdb.generated.conf
HTTP Queries
● Write queries:○ Create database: curl -G http://localhost:8086/query --data-urlencode "q=CREATE
DATABASE db_name"
○ Query going to localhost port 8086 where influxd is listening. Based on query it creates a new database
○ curl -i -XPOST 'http://localhost:8086/write?db=db_name' --data-binary 'search_event,query=red shirt,category=Cloth value=1 1434055562000000000'
● Read query:○ curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=db_name" --data-
urlencode "q=SELECT value FROM search_event WHERE category='Cloth'"
Query Response
● 2xx: ok, if some error then check for body for error message.
● 4xx: InfluxDB could not understand the request.
● 5xx: The system is overloaded or significantly impaired.
Retention Policies
● describes how long InfluxDB keeps data
● how many copies of those data are stored in the cluster
Authentication and Authorization
● Can enable through config file.○ Authorization is only enforced once you’ve enabled authentication.○ Authorization is enabled then you need to send credentials in each http requests.
● Different users can have different kind of privileges :○ Admin User
■ All access of database management■ All access of user management
○ Non admin user■ Read, Write and all(Read and write both) access per database■ No access to any database until they are specifically granted privileges to a
database by an admin user.● Unauthorized request gets HTTP 401 Unauthorized response
InfluxDB Running
● Influxd: Daemon running on port 8086 which handle all read write queries and ping.
● Influx client: Influx client can be run using command influx, with which we can send commands and receive response from influxd.
● Influx admin ui: Influx admin runs on port 8083 from where we can run queries using any browser.
● Along with these influx handles all communication between its cluster on ports 8088 and 8091.
Influxd Commands
● Run- Runs influx demon which stores complete data, handle cluster and lot more
● Backup- Backup databases and metafile
● Restore- Restore databases and metafile
● Config - Gives us all config parameters
● Version - Gives us version of demon
● Help- Shows different commands to run and how to do that
InfluxDB Backup
● Backup metadata: metastore contains internal information about the
status of the system.○ influxd backup /path/to/backup
● Backup database: Can back complete database, specific shard, specific
retention policy, since date based on different optional flags○ influxd backup -database database_name path/to/backup
● Remote backup: Can capture backup on remote node○ influxd backup -database database_name -host host_ip:port path/to/backup
InfluxDB Restore
● To restore we need to provide path of backup○ influx restore /path/to/backup
● Can restore metadata(default path: /var/lib/influxdb/meta), database,
retention policy etc.○ influxd restore -database database_name /path/of/backup
○ influxd restore -metadir /var/lib/influxdb/meta /path/of/backup
● Get list of all databases : influxd -execute ‘show databases’