Wednesday, April 24, 2024
Data AnalyticsHow ToTutorials/DIY

Getting Started with InfluxDB

What is InfluxDB?

InfluxDB is an open-source time series database (TSDB) developed by InfluxData. It is written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics.

What is a Time Series Database?

A Time Series Database (TSDB) is a database optimized for time-stamped or time series data. Time series data are simply measurements or events that are tracked, monitored, downsampled, and aggregated over time. This could be server metrics, application performance monitoring, network data, sensor data, events, clicks, trades in a market, and many other types of analytics data.

For more information read this article http://iotbyhvm.ooo/what-is-a-time-series-database/

Getting Started with InfluxDB

I use ubuntu 16.04 LTS OS . Follow instructions are given below:

  • Download and install InfluxDB

Read This article How to Install InfluxDB on Ubuntu and follow instructions.

  • Now Check status of InfluxDB
systemctl status influxdb.service
  • After Activation start Influx
influx
  • First create a database
> create database mydb
  • To view the list of databases
> show databases
name: databases
---------------
name
_internal
mydb

>
  • For using the database
> use mydb

Note : In influxdb we call tables as measurements and columns as fields.

We don’t need to define measurements(tables) and fields(columns). It will create measurements and add columns automatically when we insert data.

Inserting Data

Format for writing data is

measurementName field1=value1,field2=value2,field3=value3 timestamp
  • The timestamp is in nanoseconds. If we don’t provide timestamp it will assign the local current timestamp.
  • By default it assumes all the numbers as doubles. For integer value we have to append i at the end.
    > insert measurementName field4=12i
  • String values should be in double quotes.
    > insert measurementName field5="qwqw"
  • For boolean values use t, T, true, True, or TRUE for TRUE, and f, F, false, False, or FALSE for FALSE
    > insert measurementName field6=T
  • We can use \ character for escaping comma, space, equal and other special character in field (field) value

For more details refer official documentation

Querying Data

To select all fields from measurement

> select * from measurementName

To select particular fields

> select field1, field2 from measurement

Note : If your mesurement name or field name contains characters such as .# or =, then use double quotes

> select "field1.name", "field2.name" from "measurement.name"

Where clause

A typical usage of where clause

> select * from measurement where field1 > 12 and field2 = 'sparta' and time > now() - 1d

We can also use or logic using separaters ( and ).

Supported comaparaters in influxdb are

  • = equal to
  • <> not equal to
  • != not equal to
  • > greater than
  • < less than
  • =~ matches against
  • !~ doesn’t match against

You can learn about queries in details from official influxDB Documentation.

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

One thought on “Getting Started with InfluxDB

Leave a Reply

Your email address will not be published. Required fields are marked *