


What is InfluxDB
InfluxDB is an open source sequential database developed by InfluxData. It is written in Go and focuses on high-performance query and storage of time series data. InfluxDB is widely used in scenarios such as monitoring data of storage systems and real-time data in the IoT industry. Technical features include:
- InfluxDB fully utilizes the characteristics of the Go language in terms of technical implementation and can be deployed independently without any external dependencies [5].
- InfluxDB provides a query language similar to SQL and a series of built-in functions to facilitate users to query data.
- The data stored in InfluxDB is logically composed of Measurement, tag group, field group and a timestamp:
Measurement: A string represents the meaning of the record. . For example, it can be monitoring data cpu_load, or measurement data average_temperature
tag group: It consists of a set of key-value pairs, which represents a series of attribute information of the record. The same measurement data does not necessarily have the same tag group, and it is Schema-free. Tag information is indexed by default.
Field group: It is also composed of a set of key-value pairs, which represents the specific value information (with a name) of the record. Definable value types in the field group include: 64-bit integer, 64-bit floating point, string and Boolean. Field information cannot be indexed.
Time stamp: It is the time attribute of the record. If the timestamp is not explicitly specified when inserting data, the timestamp stored in the database by default will be the entry time of the record.
InfluxDB supports HTTP-based data insertion and query. It also accepts connections directly based on TCP or UDP protocols.
InfluxDB allows users to define data retention policies (Retention Policies) to delete or downsample data stored for more than a specified period of time.
Add, delete, modify and query operations
Enter influxDB command line
influx -precision rfc3339
InfluxDB database operation
- Display database
show databases
- New database
create database shhnwangjian
- Delete database
drop database shhnwangjian
- Use the specified database
use shhnwangjian
InfluxDB data table Operation
In InfluxDB, there is no concept of table (table), instead it is MEASUREMENTS. The functions of MEASUREMENTS are consistent with the tables in traditional databases, so we can also call MEASUREMENTS a table in InfluxDB.
• Display all tables
SHOW MEASUREMENTS
• Create a new table
There is no explicit statement to create a new table in InfluxDB. New tables can only be created by inserting data.
insert disk_free,hostname=server01 value=442221834240i insert cpu_virtual_used_num,host=1 value=41556593150
where disk_free is the table name, hostname is the index (tag), value=xx is the record value (field), there can be multiple record values, and the system comes with additional timestamps
Or when adding data, write the timestamp yourself
insert disk_free,hostname=server01 value=442221834240i 1435362189575692182
• Delete table
drop measurement disk_free
Data retention policies (Retention Policies)
influxDB does not provide direct deletion of data records method, but provides a data storage strategy, which is mainly used to specify the data retention time. If the specified time is exceeded, this part of the data will be deleted.
- View current database Retention Policies
show retention policies on "db_name" show retention policies on cdhnm
- Create new Retention Policies
create retention policy "rp_name" on "db_name" duration 3w replication 1 default create retention policy test on cdhnm duration 1h replication 1 default
rp_name: Policy name;
db_name: specific database name;
3w: Save for 3 weeks, data before 3 weeks will be deleted. influxdb has various event parameters, such as: h (hour), d (day), w (week); replication 1: number of copies, usually 1 is enough;
default: set as the default policy
- Modify Retention Policies
alter retention policy “rp_name” on “db_name” duration 30d default alter retention policy autogen on cdhnm duration 1h default
- Modify data policy
alter retention policy autogen on cdhnm duration 0h replication 1 default
- Delete Retention Policies
drop retention policy “rp_name” on “db_name" drop retention policy test on cdhnm
Query data
select * fromcpu_virtual_used_num
Insert data
Insert data and create a table at the same time
insert disk_free,hostname=server01 value=442221834240i insert cpu_virtual_used_num,host=470b14f0-e869-43ed-a8e6-fd634258271f,hostname=server01 value=0.3 1557023160
Delete data
influxDB does not provide a method to directly delete data records, but it provides a data preservation strategy, which is mainly used to specify the data retention time, exceeding the specified time , delete this part of the data. Create a new database expiration policy for at least one hour
Retention Policies create retention policy "rp_name" on "db_name" duration 3w replication 1 default retention policy duration must be at least 1h0m0s influxdb
Query table field
Query tag: show tag keys from cluster_metric
Query field: show field keys from cluster_metric
Time zone problem
When using InfluxDB, I found that because InfluxDB uses UTC time, time zone problems are often encountered when querying
1. Time format
InfluxDB In addition to supporting epoch_time, it also supports rfc3339_date_time_string and rfc3339_like_date_time_string.
epoch_time
Some theoretical explanations are the time that has passed since Coordinated Universal Time (Thursday, 1 January 1970). For example, what we get by using System.currentTimeMillis() in a java program is this time. Generally, it is millisecond level (ms) precision, that is, 13-bit Long type. In InfluxDB, the accuracy of timestamps can reach nanosecond level (ns), which is the 19-bit Long type.
rfc3339_date_time_string
rfc3339时间格式是ietf协会定义的一种时间格式,这个名字是因为它被定义在rfc3339中。感兴趣的同学可以自己查看上面的连接。InfluxDB中rfc3339的时间格式是这样的:
‘YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ’
其中nnnnnnnnn是可选的,如果不写则会被设置为000000000。注意,如果使用这种时间格式,需要使用单括号(’)将时间括起来。
rfc3339_like_date_time_string
因为rfc3339_date_time_string的格式确实比较反人类,所以InfluxDB也支持这种人类阅读更友好的格式:
‘YYYY-MM-DD HH:MM:SS.nnnnnnnnn’
其中HH:MM:SS.nnnnnnnnn是可选的,如果不填写会被设置为00:00:00.000000000。所以查询时可以设置到天、小时、分钟、秒等不同精度。这种时间格式同样要求被单括号括起来。
2、调整时间戳精度
InfluxDB默认东时间是纳秒(ns),即19位时间戳。但是一般情况下时间精度不会这么高。所以如果使用秒级精度查询:
select * from cpu_virtual_used_num where time >= 1435333209s and time <= 1542964713s
如果使用毫秒级精度查询:
select * from cpu_virtual_used_num where time >= 1435333209000ms and time <= 1542964714000ms
3、调整时区
如果需要使用北京时间(东八区),可以在SQL中使用tc关键字:
select * from cpu_virtual_used_num where time >= '2018-11-23 14:30:39' and time <= '2019-11-23 14:32:32' tz('Asia/Shanghai')
4、UTC时间与Beijing时间转换
Timestamp时间列
既然是时间序列数据库,influxdb 的数据都有一列名为 time 的列,里面存储 UTC 时间戳。
Influxdb 时间转成北京时间:UTC time + 8 hours = Beijing time
sql语句
influx -precision rfc3339 show retention policies on cdhnm alter retention policy autogen on cdhnm duration 1h default create retention policy test on cdhnm duration 1h replication 1 default drop retention policy test on cdhnm insert cpu_virtual_used_num,host=470b14f0-e869-43ed-a8e6-fd634258271f,hostname=server01 value=0.9 1557045292000000000 select * from cpu_virtual_used_num where time >= '2018-11-23 14:30:39' and time <= '2019-11-23 14:32:32' tz('Asia/Shanghai') delete from cpu_virtual_used_num
启动服务
切换到root用户 命令:su 输入密码:123456
启动:
sudo service influxdb start
重启:
service influxdb restart
切换到普通用户:
命令:exit
The above is the detailed content of A must-read for operation and maintenance monitoring: A must-know InfluxDB usage guide that can be used at critical moments. For more information, please follow other related articles on the PHP Chinese website!

如何在FastAPI中实现请求日志记录和监控引言:FastAPI是一个基于Python3.7+的高性能Web框架,它提供了许多强大的功能和特性,包括自动化的请求和响应模型验证、安全性、性能优化等。在实际开发中,我们经常需要在应用程序中记录请求日志以便进行排错和监控分析。本文将介绍如何在FastAPI中实现请求日志记录和监控,并提供相应的代码示例。一、安装依

Linux下的实时日志监控与分析在日常的系统管理和故障排查中,日志是一个非常重要的数据来源。通过对系统日志的实时监控和分析,我们可以及时发现异常情况并进行相应的处理。本文将介绍Linux下如何进行实时日志监控和分析,并提供相应的代码示例。一、实时日志监控在Linux下,最常用的日志系统是rsyslog。通过配置rsyslog,我们可以实现将不同应用程序的日志

如果我们手头没有手机,只有电脑,但我们必须拍照,我们可以使用电脑内置的监控摄像头拍照,那么如何打开win10监控摄像头,事实上,我们只需要下载一个相机应用程序。打开win10监控摄像头的具体方法。win10监控摄像头打开照片的方法:1.首先,盘快捷键Win+i打开设置。2.打开后,进入个人隐私设置。3.然后在相机手机权限下打开访问限制。4.打开后,您只需打开相机应用软件。(如果没有,可以去微软店下载一个)5.打开后,如果计算机内置监控摄像头或组装了外部监控摄像头,则可以拍照。(因为人们没有安装摄

随着互联网的发展,web应用程序的性能监控以及安全分析越来越受到重视。nginx作为一款高性能的Web服务器和反向代理工具,其在性能监控和安全分析方面也受到广泛的关注和应用。本文将介绍一些Nginx性能监控和安全分析的辅助工具。Nginx性能监控工具NginxAmplifyNginxAmplify是Nginx公司推出的一款性能监控工具。该工具可以

Nginx监控实时状态配置,实时查看网站运行引言:Nginx是一款非常流行的反向代理服务器,其高性能和高并发能力使得它成为了许多网站的首选。为了保证网站的稳定运行,我们需要时刻监控Nginx的运行状态。本篇文章将介绍如何配置Nginx实时状态监控,并通过示例代码来让读者更好地理解。一、安装Nginx状态监控模块要实现Nginx的实时状态监控,需要在Nginx

在当今的互联网时代,Web应用程序的高效稳定运行是非常重要的。然而,应用程序可能会出现故障或崩溃,影响用户体验。为了确保应用程序的正常运行,我们需要对其进行监控。本文将探讨如何使用Golang实现Web应用程序监控。一、Golang的Web应用程序监控工具Golang拥有非常适合Web应用程序监控的工具。其中最流行的就是Prometheus。Promethe

如何在Linux上设置高可用的网络存储监控在现代的IT环境中,网络存储是一个关键组件,用于存储和管理海量的数据。为了确保数据的可靠性和高可用性,对网络存储的监控和故障恢复是非常重要的。本文将介绍如何在Linux上设置高可用的网络存储监控,并提供代码示例。第一步:安装监控工具在Linux上,我们可以使用一个开源的监控工具来监控网络存储,比如Nagios。首先,

随着微服务架构的广泛应用,调用链监控已经成为了保障微服务健康运行的重要手段。而基于go-zero框架实现微服务调用链监控,则是更加高效可靠的实现方式。一、调用链监控的基本概念微服务架构中,一个请求可能经过多个微服务组件的调用,这些调用形成了一条调用链。而一旦某一个环节出现问题,整个服务甚至整个系统都有可能受到影响。因此,调用链监控这个技术,就是通过记录整条调


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool