Introduction
InfluxDB, a widely-used open-source time series database, excels in handling large volumes of time-stamped data for applications like monitoring systems, IoT devices, and financial tracking. This tutorial will guide you through querying InfluxDB, demonstrating practical examples and setup instructions.
If you haven’t installed InfluxDB yet, refer to the installation guide provided earlier to get started. This introduction sets the stage for you to effectively manage and analyze time-series data using InfluxDB’s powerful features.
InfluxDB examples
InfluxDB show databases
[root@MonitoringServer ~]# influx
Connected to http://localhost:8086 version 1.7.4
InfluxDB shell version: 1.7.4
Enter an InfluxQL query
> show databases
name: databases
name
----
_internal
devopsrolesDB
telegraf
Use databases
> use devopsrolesDB
Using database devopsrolesDB
>
Uptime Server
> select last("uptime_format") as "value" from "system" where "host" =~ /DevopsRoles\.com$/ AND time >= now() - 1h GROUP BY time(60s)
Check Root FS used
> SELECT last("used_percent") FROM "disk" WHERE ("host" =~ /^DevopsRoles\.com$/ AND "path" = '/') AND time >= now() -6h GROUP BY time(5m) fill(null)
Swap used
> SELECT last("used_percent") FROM "swap" WHERE ("host" =~ /^DevopsRoles\.com$/) AND time >= now() -1h GROUP BY time(5m) fill(null)
Users login
> SELECT last("n_users") FROM "system" WHERE ("host" =~ /^DevopsRoles\.com$/) AND time >= now() -1h GROUP BY time(5m) fill(null)
CPU usage
> SELECT last("usage_idle") * -1 + 100 FROM "cpu" WHERE ("host" =~ /^DevopsRoles\.com$/ AND "cpu" = 'cpu-total') AND time >= now() -1h GROUP BY time(5m) fill(null)
RAM Usage
> SELECT last("used_percent") FROM "mem" WHERE ("host" =~ /^DevopsRoles\.com$/) AND time >= now() -1h GROUP BY time(5m) fill(null)
CPU Load
> SELECT mean(load1) as load1,mean(load5) as load5,mean(load15) as load15 FROM "system" WHERE host =~ /^DevopsRoles\.com$/ AND time >= now() -1h GROUP BY time(5m) fill(null)
CPUs number
> SELECT last("n_cpus") FROM "system" WHERE ("host" =~ /^DevopsRoles\.com$/) AND time >= now() -1h GROUP BY time(5m) fill(null)
Other Influxdb examples
How to list all value systems, swap, CPUs, Memory, and so on.
Enter as following for the system
> select * from "system" where host =~ /^DevopsRoles\.com$/ AND time >= now() -1h
## The output as below:
name: system
time host load1 load15 load5 n_cpus n_users uptime uptime_format
---- ---- ----- ------ ----- ------ ------- ------ -------------
1574665340000000000 DevopsRoles.com 0.27 0.03 0.11 4 1 8105215 93 days, 19:26
1574665350000000000 DevopsRoles.com 0.22 0.03 0.1 4 1 8105225 93 days, 19:27
1574665360000000000 DevopsRoles.com 0.19 0.03 0.1 4 1 8105235 93 days, 19:27
CPU
> select * from "cpu" where host =~ /^DevopsRoles\.com$/ AND time >= now() - 120s
## The output as below:
name: cpu
time cpu host usage_guest usage_guest_nice usage_idle usage_iowait usage_irq usage_nice usage_softirq usage_steal usage_system usage_user
---- --- ---- ----------- ---------------- ---------- ------------ --------- ---------- ------------- ----------- ------------ ----------
1574670090000000000 cpu-total DevopsRoles.com 0 0 99.92494371410935 0 0 0 0 0 0.025018764076678877 0.050037528153357755
1574670090000000000 cpu0 DevopsRoles.com 0 0 100 0 0 0 0 0 0 0
1574670090000000000 cpu1 DevopsRoles.com 0 0 99.89989990213955 0 0 0 0 0 0.1001001000954934 0
1574670090000000000 cpu2 DevopsRoles.com 0 0 99.89979960143319 0 0 0 0 0 0.10020040080409609 0
1574670090000000000 cpu3 DevopsRoles.com 0 0 100 0 0 0 0 0 0 0
1574670100000000000 cpu-total DevopsRoles.com 0 0 99.79989994515057 0.12506253122346286 0 0 0 0 0.05002501250212444 0.02501250625561197
1574670100000000000 cpu0 DevopsRoles.com 0 0 99.49949949205266 0.5005005005184352 0 0 0 0 0 0
1574670100000000000 cpu1 DevopsRoles.com 0 0 100 0 0 0 0 0 0 0
1574670100000000000 cpu2 DevopsRoles.com 0 0 99.79999999517575 0 0 0 0 0 0.09999999999286956 0.09999999998377461
1574670100000000000 cpu3 DevopsRoles.com 0 0 100 0 0 0 0 0 0 0
1574670110000000000 cpu-total DevopsRoles.com 0 0 99.64982491096929 0.22511255633968244 0 0 0 0.025012506253392856 0.05002501250223596 0.05002501249768622
DISK
> select * from "disk" where host =~ /^DevopsRoles\.com$/ AND time >= now() - 120s
## The output as below:
name: disk
time device free fstype host inodes_free inodes_total inodes_used mode path total used used_percent
---- ------ ---- ------ ---- ----------- ------------ ----------- ---- ---- ----- ---- ------------
1574670150000000000 10.10.10.225:/mnt_nfs/data_volume/ 64795705344 nfs4 DevopsRoles.com 5924993 6553600 628607 rw /mnt_nfs/data 105554903040 35373711360 35.313883742109724
1574670150000000000 mapper/VolGroup-lv_root 40046198784 ext4 DevopsRoles.com 3014316 3182400 168084 rw / 51484815360 8823488512 18.0551360162319
1574670150000000000 vda1 427900928 ext4 DevopsRoles.com 127976 128016 40 rw /boot 507744256 53628928 11.137196859502726
1574670150000000000 vdb1 9870200832 ext4 DevopsRoles.com 655325 655360 35 rw /app 10568843264 161775616 1.612599639149392
Diskio
> select * from "diskio" where host =~ /^DevopsRoles\.com$/ AND time >= now() - 120s
## The output as below:
name: diskio
time host io_time iops_in_progress name read_bytes read_time reads weighted_io_time write_bytes write_time writes
---- ---- ------- ---------------- ---- ---------- --------- ----- ---------------- ----------- ---------- ------
1574670240000000000 DevopsRoles.com 137167292 0 dm-0 2659918848 2451413 181804 3747940429 51691593728 3745384372 12620365
1574670240000000000 DevopsRoles.com 3102 0 vdb1 5949440 3049 770 5493 315904 2445 59
1574670240000000000 DevopsRoles.com 6376 0 dm-1 7897088 31096 1928 68191 27774976 37096 6781
1574670240000000000 DevopsRoles.com 137161235 0 vda 2674118656 1651142 137682 1886179382 51719428096 1884529301 4253428
1574670240000000000 DevopsRoles.com 667 0 vda1 2124800 370 521 667 47104 297 19
1574670240000000000 DevopsRoles.com 107 0 sr0 155648 107 49 107 0 0 0
Kernel
> select * from "kernel" where host =~ /^DevopsRoles\.com$/ AND time >= now() - 120s
## The output as below:
name: kernel
time boot_time context_switches entropy_avail host interrupts processes_forked
---- --------- ---------------- ------------- ---- ---------- ----------------
1574670390000000000 1566560125 897266212 1320 DevopsRoles.com 611974729 543719
1574670400000000000 1566560125 897267347 1320 DevopsRoles.com 611975497 543719
1574670410000000000 1566560125 897268311 1320 DevopsRoles.com 611976101 543719
1574670420000000000 1566560125 897269308 1355 DevopsRoles.com 611976734 543719
1574670430000000000 1566560125 897270363 1396 DevopsRoles.com 611977420 543719
1574670440000000000 1566560125 897271391 1412 DevopsRoles.com 611978084 543719
1574670450000000000 1566560125 897272328 1412 DevopsRoles.com 611978685 543719
1574670460000000000 1566560125 897273390 1423 DevopsRoles.com 611979457 543719
>
Network
> select bytes_recv,bytes_sent,drop_in,drop_out from "net" where host =~ /^DevopsRoles\.com$/ AND time >= now() - 120s
## The output as below:
name: net
time bytes_recv bytes_sent drop_in drop_out
---- ---------- ---------- ------- --------
1574670830000000000 42310540034 60204453178 0 0
1574670840000000000 42310549919 60204469772 0 0
1574670850000000000 42310565133 60204488497 0 0
1574670860000000000 42310577265 60204503755 0 0
1574670870000000000 42310587249 60204520594 0 0
1574670880000000000 42310613504 60204538330 0 0
Processes
> select * from "processes" where host =~ /^DevopsRoles\.com$/ AND time >= now() - 120s
## The output as below:
name: processes
time blocked dead host idle paging running sleeping stopped total total_threads unknown zombies
---- ------- ---- ---- ---- ------ ------- -------- ------- ----- ------------- ------- -------
1574670990000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 209 0 0
1574671000000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 209 0 0
1574671010000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 210 0 0
1574671020000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 210 0 0
1574671030000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 210 0 0
1574671040000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 210 0 0
1574671050000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 210 0 0
1574671060000000000 0 0 DevopsRoles.com 0 0 0 126 0 126 210 0 0
swap
> select * from "swap" where host =~ /^DevopsRoles\.com$/ AND time >= now() - 120s
## The output as below:
name: swap
time free host in out total used used_percent
---- ---- ---- -- --- ----- ---- ------------
1574671030000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671040000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671050000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671060000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671070000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671080000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671090000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671100000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
1574671110000000000 831287296 DevopsRoles.com 6680576 27774976 855629824 24342528 2.8449835801889956
How to show tag values.
SHOW TAG VALUES FROM system WITH KEY=host
SHOW TAG VALUES FROM "cpu" WITH KEY = "cpu" WHERE host =~ /$server/
SHOW TAG VALUES FROM "disk" WITH KEY = "device"
SHOW TAG VALUES FROM "net" WITH KEY = "interface" WHERE host =~ /$server/
Conclusion
Through the article, How to query Influxdb examples above. InfluxDB is widely used in various domains, including DevOps, IoT, monitoring and observability, and real-time analytics, due to its high performance, scalability, and ease of use. I hope will this your helpful. Thank you for reading DevOpsRoles.com page