zoukankan      html  css  js  c++  java
  • [Influxdb]记录

    1. Centos使用yum安装

    wget https://repos.influxdata.com/rhel/6/x86_64/stable/influxdb-1.7.2.x86_64.rpm
    sudo yum localinstall influxdb-1.7.2.x86_64.rpm

    2. 图片如下

    3.在/usr/bin 目录下会有如下文件

    influx    influxdb命令行客户端
    influxd  influxdb服务器
    influx_inspect   查看工具
    influx_stress      压力测试工具

    influx_tsm   数据库转换工具(将数据库从b1或bz1格式转换为tsm1格式

    4. 配置文件路径 /etc/influxdb/

    5. 启动

    以服务方式启动 sudo service influxdb start

    6 输入influx进入influxdb shell(CLI)/opt/influxdb/influx

    建库、用户

    show databases

    create database test

    show users

    create user test with password '123456'

    grant all on test to test

    建表

    use test

    show measurements //显示

    delete from user3rdlog

    概念

    influxDB名词

    • database:数据库;
    • measurement:数据库中的表;
    • points:表里面的一行数据。

    influxDB中独有的一些概念

    Point由时间戳(time)、数据(field)和标签(tags)组成。
    • time:每条数据记录的时间,也是数据库自动生成的主索引;
    • fields:各种记录的值;
    • tags:各种有索引的属性。

     例如:插入如下数据

    insert log,appid=10001,datatype="3rd.umeng" querystatus=0i,insertstatus=0i  //注意中间有个空格

    这条记录分成二部分,log是表名,appid和datatype是tags,querystatus和insertstatus是fields

    还有一个重要的名词:series
    所有在数据库中的数据,都需要通过图表来表示,series表示这个表里面的所有的数据可以在图标上画成几条线(注:线条的个数由tags排列组合计算出来),下面可以画出三条线

    influxdb数据类型 参考:https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_reference/

    如果在命令行模式下  insert log, appid="1001", datatype="user3rd.crd" insertstatus=0,querystatus=0i

    通过show field keys 查看字段类型  

    show tag keys on test

    显示tag信息

    如果希望字段类型是integer类型,需要在数据后面添加i标示。

    1.根据datatype groupby 

    时刻记住:查询数据都会带time时间信息

    select datatype,num_cn from (select count(querystatus) as num_cn from event group by datatype) 

    select time, datatype, num_cn from (select count(querystatus) as num_cn from event group by time(5m),datatype)

    2.在influxdb中,如果需要记录值是null,count统计不会统计进去

     influx 设置时间格式

      influx -precision rfc3339

      precision rfc3339

    influxdb连续查询

    1.查看连续查询

    show CONTINUOUS QUERIES

    2.创建连续查询

    CREATE CONTINUOUS QUERY <cq_name> ON <database_name>
    BEGIN
      <cq_query>
    END

    cq_query查询如下
    SELECT <function[s]> INTO <destination_measurement> FROM <measurement> [WHERE <stuff>] GROUP BY time(<interval>)[,<tag_key[s]>]
    删除 drop continuous query cq_withtag on test  //drop continuous query query_name on database
    例子
    有measurement如下所示
    CREATE CONTINUOUS QUERY test_cq on test begin select count(userid) as cn into logcg_2s from user3rdlog group by time(2s),datatype end
    注意事项

    欢迎关注Java流水账公众号
  • 相关阅读:
    爬取豆瓣电影
    post get 请求 headers注释哪些
    matlab 子图像subplot
    post请求get请求
    UA伪装
    urllib.request encode()/decode()
    urllib.parse quote/unquate/urlencode
    python 爬取图片
    二叉树满二叉树完全二叉树
    Linux | 性能分析系列学习 (1)
  • 原文地址:https://www.cnblogs.com/guofu-angela/p/10115688.html
Copyright © 2011-2022 走看看