Table of Contents
​What is InfluxDB
Add, delete, modify and query operations
InfluxDB data table Operation
Data retention policies (Retention Policies)
Query data
Insert data
Delete data
Query table field
Time zone problem
1. Time format
2、调整时间戳精度
3、调整时区
4、UTC时间与Beijing时间转换
sql语句
启动服务
Home Operation and Maintenance Safety A must-read for operation and maintenance monitoring: A must-know InfluxDB usage guide that can be used at critical moments

A must-read for operation and maintenance monitoring: A must-know InfluxDB usage guide that can be used at critical moments

Jun 09, 2023 pm 01:40 PM
Operation and maintenance monitor

​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
Copy after login

InfluxDB database operation

  • Display database
show databases
Copy after login
  • New database
create database shhnwangjian
Copy after login
  • Delete database
drop database shhnwangjian
Copy after login
  • Use the specified database
use shhnwangjian
Copy after login

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
Copy after login

• 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
Copy after login

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
Copy after login

• Delete table

drop measurement disk_free
Copy after login

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
Copy after login
  • 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
Copy after login

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
Copy after login
  • Modify data policy
alter retention policy autogen on cdhnm duration 0h replication 1 default
Copy after login
  • Delete Retention Policies
drop retention policy “rp_name” on “db_name"
drop retention policy test on cdhnm
Copy after login

Query data

select * fromcpu_virtual_used_num
Copy after login

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
Copy after login

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
Copy after login

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’
Copy after login

其中nnnnnnnnn是可选的,如果不写则会被设置为000000000。注意,如果使用这种时间格式,需要使用单括号(’)将时间括起来。

rfc3339_like_date_time_string

因为rfc3339_date_time_string的格式确实比较反人类,所以InfluxDB也支持这种人类阅读更友好的格式:

‘YYYY-MM-DD HH:MM:SS.nnnnnnnnn’
Copy after login

其中HH:MM:SS.nnnnnnnnn是可选的,如果不填写会被设置为00:00:00.000000000。所以查询时可以设置到天、小时、分钟、秒等不同精度。这种时间格式同样要求被单括号括起来。

2、调整时间戳精度

InfluxDB默认东时间是纳秒(ns),即19位时间戳。但是一般情况下时间精度不会这么高。所以如果使用秒级精度查询:

select * from cpu_virtual_used_num where time >= 1435333209s and time <= 1542964713s
Copy after login

如果使用毫秒级精度查询:

select * from cpu_virtual_used_num where time >= 1435333209000ms and time <= 1542964714000ms
Copy after login

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')
Copy after login

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
Copy after login

启动服务

切换到root用户
命令:su
输入密码:123456
Copy after login

启动:

sudo service influxdb start
Copy after login

重启:

service influxdb restart
Copy after login

切换到普通用户:

命令: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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24
How long is home monitoring usually kept? How long is home monitoring usually kept? Aug 30, 2023 pm 04:44 PM

Home monitoring is generally kept for one to two weeks. Detailed introduction: 1. The larger the storage capacity, the longer the video can be saved; 2. The larger the capacity of the hard disk, the longer the video can be saved; 3. According to the requirements of different regions and laws and regulations, the number of surveillance videos The storage time may vary; 4. Some advanced surveillance systems can also trigger recording based on motion detection or specific events, thereby saving storage space and providing more useful recordings.

Python script for monitoring website changes Python script for monitoring website changes Aug 29, 2023 pm 12:25 PM

In today's digital age, being aware of the latest changes on your website is crucial for a variety of purposes, such as tracking updates on your competitors' websites, monitoring product availability, or staying informed of important information. Manually checking your website for changes can be time-consuming and inefficient. This is where automation comes into play. In this blog post, we will explore how to create a Python script to monitor website changes. By leveraging the power of Python and some handy libraries, we can automate the process of retrieving website content, comparing it to previous versions, and notifying us of any changes. This allows us to remain proactive and react promptly to updates or modifications to the sites we monitor. Setting up the environment Before we start writing scripts to monitor website changes, we need to set up P

Real-time log monitoring and analysis under Linux Real-time log monitoring and analysis under Linux Jul 29, 2023 am 08:06 AM

Real-time log monitoring and analysis under Linux In daily system management and troubleshooting, logs are a very important data source. Through real-time monitoring and analysis of system logs, we can detect abnormal situations in time and handle them accordingly. This article will introduce how to perform real-time log monitoring and analysis under Linux, and provide corresponding code examples. 1. Real-time log monitoring Under Linux, the most commonly used log system is rsyslog. By configuring rsyslog, we can combine the logs of different applications

How to implement request logging and monitoring in FastAPI How to implement request logging and monitoring in FastAPI Jul 30, 2023 am 08:29 AM

How to implement request logging and monitoring in FastAPI Introduction: FastAPI is a high-performance web framework based on Python3.7+. It provides many powerful functions and features, including automated request and response model verification, security, and performance optimization. wait. In actual development, we often need to record request logs in the application for debugging and monitoring analysis. This article will introduce how to implement request logging and monitoring in FastAPI and provide corresponding code examples. 1. Installation

Laravel monitoring errors: improve application stability Laravel monitoring errors: improve application stability Mar 06, 2024 pm 04:48 PM

Monitoring errors in Laravel is an important part of improving application stability. During the development process, various errors will inevitably be encountered, and how to detect and resolve these errors in a timely manner is one of the keys to ensuring the normal operation of the application. Laravel provides a wealth of tools and functions to help developers monitor and handle errors. This article will introduce some of the important methods and attach specific code examples. 1. Use logging Logging is one of the important means of monitoring errors. Laravel has a powerful logging system built-in, developers

C# Development Advice: Logging and Monitoring Systems C# Development Advice: Logging and Monitoring Systems Nov 22, 2023 pm 08:30 PM

C# Development Suggestions: Logging and Monitoring System Summary: In the software development process, logging and monitoring systems are crucial tools. This article will introduce the role and implementation suggestions of logging and monitoring systems in C# development. Introduction: Logging and monitoring are essential tools in large-scale software development projects. They can help us understand the running status of the program in real time and quickly discover and solve problems. This article will discuss how to use logging and monitoring systems in C# development to improve software quality and development efficiency. The role of logging system

How to use Docker for container monitoring and performance analysis How to use Docker for container monitoring and performance analysis Nov 08, 2023 am 09:54 AM

Overview of how to use Docker for container monitoring and performance analysis: Docker is a popular containerization platform that allows applications to run in independent containers by isolating applications and their dependent software packages. However, as the number of containers increases, container monitoring and performance analysis become increasingly important. In this article, we will introduce how to use Docker for container monitoring and performance analysis, and provide some specific code examples. Use Docker’s own container monitoring tool Docker provides

Will Sunflower Remote Control be monitored? Will Sunflower Remote Control reveal privacy? Will Sunflower Remote Control be monitored? Will Sunflower Remote Control reveal privacy? Mar 15, 2024 pm 05:28 PM

Will Sunflower remote control be monitored? Sunflower remote control software can help users quickly retrieve information from another computer, etc. However, there are also many users who are worried about the security of their own computers. Let the editor answer these questions for users. Question. Will Sunflower Remote Control be monitored? Answer: No. Although Sunflower Remote Control has the ability to do this, large software companies like Sunflower Remote Control that have been established for many years will not do such a thing. For office workers, perhaps a piece of software that must be installed on the computer is remote control. For many people, whether they are working from home or because they are unable to leave, operating the current computer from a distance through another computer can save a lot of time.

See all articles