https://docs.influxdata.com/influxdb/v0.8/api/query_language/

InfluxDB features a SQL like query language, only used for querying data. The HTTP API has endpoints for writing data and performing other database administration tasks. The only exception to this is continuous queries, which perpetually write their results into one or more time series.

Getting series with special characters

InfluxDB allows you to use any characters in your time series names. However, parsing queries for those series can be tricky. So it’s best to wrap your queries for any series that has characters other than letters in double quotes like this:

select * from "series with special characters!"

select * from "series with \"double quotes\""

Getting a List of Time Series

There are two different methods for returning a list of all time series in a database:

list series
-- or this
select * from /.*/ limit 1

The first query will return all series, while the second will return the most recent point from each series that matches the given regex.

Select and Time Ranges

By default, InfluxDB returns data in time descending order. The most efficient queries run over only a single column in a given time series.

select value from response_times;

This simple query pulls the values for the value column from the response_times series.

How to set query start and end time

If start and end times aren’t set they will default to beginning of time until now, respectively.

The column time is built in for every time series in the database. You specify the start and end times by setting conditions on the time columns in the where clause.

Below are the different formats that can be used to specify start and end times.

Date time strings

Date time strings have the format YYYY-MM-DD HH:MM:SS.mmm where mmm are the milliseconds within the second. For example:

select value from response_times
where time > '2013-08-12 23:32:01.232' and time < '2013-08-13';

The time and date should be wrapped in single quotes. If you only specify the date, the time will be set to 00:00:00. The .232 after the hours, minutes, and seconds is optional and specifies the milliseconds.

Relative time

You can use now() to calculate a timestamp relative to the server’s current timestamp. For example:

select value from response_times where time > now() - 1h limit 1000;

will return all points starting an hour ago until now.

Other options for how to specify time durations are u for microseconds, s for seconds, m for minutes, h for hours, d for days and w for weeks. If no suffix is given the value is interpreted as microseconds.

Absolute time

You can specify timestamp in epoch time, which is defined as the number of microseconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970. You can use the same suffixes from the previous section if you don’t want to specify timestamp in microseconds. For example:

select value from response_times where time > 1388534400s

will return all points that were writtern after 2014-01-01 00:00:00

Selecting a Specific Point

Points are uniquely identified by the time series they appear in, the time, and the sequence number. Here’s a query that returns a specific point.

select * from events where time = 1400497861762723 and sequence_number = 2321;

Note that the time is a very large number. That’s because it’s a microsecond scale epoch. InfluxDB always stores points at this scale, but most libraries will return the time as either a second, or millisecond scale value. If you’re selecting a specific point, you’ll need to know the exact microsecond scale epoch that point has otherwise you’ll get an unexpected empty result.

Selecting Multiple Series

You can select from multiple series by name or by specifying a regex to match against. Here are a few examples.

select * from events, errors;

Get the last hour of data from the two series events, and errors. Here’s a regex example:

select * from /^stats\./i where time > now() - 1h;

Get the last hour of data from every time series that starts with stats. (case insensitive). Another example:

select * from /.*/ limit 1;

Return the last point from every time series in the database.

Deleting data or dropping series

The delete query looks like the following:

delete from response_times where time < now() - 1h

With no time constraints this query will delete every point in the time series response_times. You must be a cluster or database admin to run delete queries.

You can also delete from any series that matches a regex:

delete from /^stats.*/ where time < now() - 7d

Any conditions in the where clause that don’t set the start and/or end time will be ignored, for example the following query returns an error:

delete from response_times where user = 'foo'

Delete time conditions only support ranges, an equals condition (=) is currently not supported.

Deleting all data for a series will only remove the points. It will still remain in the index. If you want to remove all data from a series and remove it from the list of series in a database use the drop query:

drop series response_times

Note about Delete Performance

Currently, deletes are not very efficient. If you want to quickly evict old data, the best way to do that is by dropping a shard. For more information on shards go here.

The Where Clause

We’ve already seen the where clause for selecting time ranges and a specific point. You can also use it to filter based on given values, comparators, or regexes. Here are some examples of different ways to use where.

select * from events where state = 'NY';

select * from log_lines where line =~ /error/i;

select * from events where customer_id = 23 and type = 'click';

select * from response_times where value > 500;

select * from events where email !~ /.*gmail.*/;

select * from nagios_checks where status <> 0;

select * from events where signed_in = false;

select * from events
where (email =~ /.*gmail.*/ or email =~ /.*yahoo.*/) and state = 'ny';

The where clause supports comparisons against regexes, strings, booleans, floats, integers, and the times listed before. Comparators include = equal to, > greater than, < less than, <> not equal to, =~ matches against, !~ doesn’t match against. You can chain logic together using and and or and you can separate using ( and )

Group By

The group by clause in InfluxDB is used not only for grouping by given values, but also for grouping by given time buckets. You’ll always be pairing this up with a function in the select clause. Here are a few examples to illustrate how group by works.

-- count of events in 10 minute intervals
select count(type) from events group by time(10m); -- count of each unique type of event in 10 minute intervals
select count(type) from events group by time(10m), type; -- 95th percentile of response times in 30 second intervals
select percentile(value, 95) from response_times group by time(30s);

By default functions will output a column that have the same name as the function, e.g. count will output a column with the name count in order to change the name of the column an AS clause is required. Here is an example to illustrate how aliasing work:

select count(type) as number_of_types group by time(10m);

The time function takes the time interval which can be in microseconds, seconds, minutes, hours, days or weeks. To specify the units you can use the respective suffix usmhd and w.

Filling intervals with no data

By default, group by intervals that have no data will not have associated datapoints. For instance, say you have the following query:

select count(type) from events
group by time(1h) where time > now() - 3h

If the events series had data for this hour and two hours ago only, you’d only get two points in the result. If you want to ensure that you get back points for intervals that don’t have data, you can use the fill function. Any numerical value, including negative values, and the special value null, are valid values for fill. For example, each of the following queries is valid:

select count(type) from events
group by time(1h) fill(0) where time > now() - 3h
select count(type) from events
group by time(1h) fill(-1) where time > now() - 3h
select count(type) from events
group by time(1h) fill(null) where time > now() - 3h

Note that fill must go at the end of the group by clause if there are other arguments:

select count(type) from events
group by time(1h), type fill(0) where time > now() - 3h

Merging Series

You can merge multiple time series into a single stream in the select clause. This is helpful when you want to run a function over one of the columns with an associated group by time clause.

select count(type) from user_events merge admin_events group by time(10m)

You’d get a single time series with the count of events from the two combined in 10 minute intervals.

Joining Series

Joins will put two or more series together. Since timestamps may not match exactly, InfluxDB will make a best effort to put points together. Joins are used when you want to perform a transformation of one time series against another. Here are a few examples.

select hosta.value + hostb.value
from cpu_load as hosta
inner join cpu_load as hostb
where hosta.host = 'hosta.influxdb.orb' and hostb.host = 'hostb.influxdb.org';

The above query will return a time series of the combined cpu load for hosts a and b. The individual points will be coerced into the closest time frames to match up.

select errors_per_minute.value / page_views_per_minute.value
from errors_per_minute
inner join page_views_per_minute

The above query will return the error rate per minute.

infludb语法--官网的更多相关文章

  1. template.js artTemplate 简洁语法官网下载不了 template.js artTemplate 新下载地址

    参考:https://blog.csdn.net/tavatimsa/article/details/82019792

  2. [Android]官网《monkeyrunner》中文翻译

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5050768.html 翻译自 Android Develope ...

  3. [Android]官网《UI/Application Exerciser Monkey》中文翻译

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5049041.html 翻译自 Android Develope ...

  4. Knockout.Js官网学习(简介)

    前言 最近一段时间在网上经常看到关于Knockout.js文章,于是自己就到官网看了下,不过是英文的,自己果断搞不来,借用google翻译了一下.然后刚刚发现在建立asp.net mvc4.0的应用程 ...

  5. Python自学笔记-列表生成式(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 列表生成式 列 ...

  6. React 系列教程 1:实现 Animate.css 官网效果

    前言 这是 React 系列教程的第一篇,我们将用 React 实现 Animate.css 官网的效果.对于 Animate.css 官网效果是一个非常简单的例子,原代码使用 jQuery 编写,就 ...

  7. 【工利其器】必会工具之(三)systrace篇(1)官网翻译

    前言 Android 开发者官网中对systrace(Android System Trace)有专门的介绍,本篇文章作为systrace系列的开头,笔者先不做任何介绍,仅仅翻译一下官网的介绍.在后续 ...

  8. Knockout 官网学习文档目录

    官网:https://knockoutjs.com/documentation/introduction.html Knockout-Validation: https://github.com/Kn ...

  9. MySQL入门(参考官网)

    目录 一.登陆和退出 1. 远程主机 2. 登陆本机 3. 退出mysql 二.输入查询 三.创建和使用数据库 3.1 创建和选择数据库 3.2 创建表 3.3 将数据加载到表中 3.4 操作表格 3 ...

随机推荐

  1. 利用Axis2默认口令安全漏洞入侵WebService网站

    近期,在黑吧安全网上关注了几则利用Axis2默认口令进行渗透测试的案例,大家的渗透思路基本一致,利用的技术工具也大致相同,我在总结这几则案例的基础之上进行了技术思路的拓展.黑吧安全网Axis2默认口令 ...

  2. Jenkins介绍-安装-部署...

    1.背景      大师Martin Fowler对持续集成是这样定义的:持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个成员每天至少集成一次,也就意味着每天可能会发生多次集成. ...

  3. CorelDRAW快速制作绚丽的彩色透明心形

    今天小编分享给小伙伴们用CorelDRAW打造绚丽的彩色透明心形.主要使用完美形状组中的心形造型制作出心形图案,经过对图形的模糊操作,再经过图框精确剪裁,最后添加一个彩虹渐变色实现绚丽的彩色透明效果. ...

  4. MaterialDesign动画

    一.概述 MaterialDesign设计理念 MaterialDesign动画 二.实例讲解 (1)Touch Feedback (2)Reveal Effect (3)Activity Trans ...

  5. redis 安装成功后外部服务器链接不上

    1.reids服务器的6379端口telnet不通 2. 查看reids进程和端口,都是存在的.只是ip地址是127.0.0.1而不是0.0.0.0,只是本机能使用 3.查找redis的配置文件red ...

  6. pyhton的selenium的搭建

    一.好记性不如烂笔头,小伙伴们.让我们做下笔记吧 1.首先要安装pycharm  激活注册码地址:http://idea.lanyus.com/ 2.下载python3.6   python下载地址: ...

  7. IOS:兼容ios6和低版本

    viewDidUnload在ios6开始被弃用了,所以我们在这里处理内存警告的这类问题,这个时候我们就要把相应的处理放在 didReceiveMemoryWarning中. - (void)didRe ...

  8. Project Euler 18 Maximum path sum I( DP and 记忆化搜索 )

    题意:求从三角形顶端出发到达底部,所能够得到的最大路径和 方法一:记忆化搜索 /************************************************************ ...

  9. python初学者学习笔记

    python开发: a.Python基础 b.网络编程 c.web框架 —用于写网站 d.设计阶段+算法 e.项目阶段 开发: 开发语言:高级语言:python/Java/PHP/C#/Go/ruby ...

  10. soapui测试接口使用步骤

    1.新建项目 2. 定义接口 url输入接口 3.新建测试集 选择项目,右键 4.在测试集下新建测试用例 5.在测试步骤中导入要测试的请求 6.run