美文网首页
docker: influxDb + telegraf + gr

docker: influxDb + telegraf + gr

作者: 炒面Z | 来源:发表于2020-11-12 17:36 被阅读0次
    名称
    influxDb 时序数据库
    telegraf 数据采集agent

    使用 telegraf 采集数据写入 influxDb 中存储,然后通过grafana展示成BI报表

    1.influxDb 在 docker下的安装

    • docker-compose.yml
    version: '2'
    services:
      influxdb:
        image: tutum/influxdb:latest
        container_name: influxdb
        volumes:
          - /opt/influxdb/conf:/etc/influxdb
          - /opt/influxdb/data:/var/lib/influxdb
          - /etc/localtime:/etc/localtime
        ports:
          - "8086:8086"
          - "8083:8083"
        restart: always
        environment:
          - ADMIN_USER="root"
          - INFLUXDB_INIT_PWD="123456"
          - PRE_CREATE_DB="telegraf"
    
    • 由镜像生成容器运行
    docker-compost up -d
    
    • 测试
    访问 IP:8083 可访问influxDb的web界面
    
    image.png
    或者使用命令访问
    root@xxxx:/opt/influxdb# docker exec -it influxdb bash
    root@7823c55b1e4f:/# influx
    Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
    Connected to http://localhost:8086 version 1.0.0
    InfluxDB shell version: 1.0.0
    > show databases
    name: databases
    ---------------
    name
    _internal
    telegraf
    
    > show users
    user    admin
    root    true
    
    > use telegraf
    Using database telegraf
    > SHOW MEASUREMENTS
    name: measurements
    ------------------
    name
    cpu
    disk
    diskio
    kernel
    mem
    processes
    swap
    system
    
    > select * from cpu limit 5
    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
    1605171380000000000 cpu-total   iZ8vbealpwhng8ovp3fyz6Z 0       0           97.14141158872732   0.025297242601537845    0       0       0.050594485201925304    0       1.188970402249271   1.5937262838738766
    1605171380000000000 cpu3        iZ8vbealpwhng8ovp3fyz6Z 0       0           97.77777778039092   0.10101010101153356 0       0       0.10101010101153356 0       1.0101010101325607  1.0101010101325607
    1605171380000000000 cpu1        iZ8vbealpwhng8ovp3fyz6Z 0       0           98.09045226190388   0           0       0       0           0       1.0050251255947016  0.9045226130498564
    1605171380000000000 cpu0        iZ8vbealpwhng8ovp3fyz6Z 0       0           96.73802242782325   0           0       0       0           0       1.325178389401408   1.9367991845183081
    1605171380000000000 cpu2        iZ8vbealpwhng8ovp3fyz6Z 0       0           96.34146341590379   0           0       0       0           0       1.321138211375501   2.337398373977728
    

    2.telegraf的安装和启动 - 非docker模式

    安装启动

    mkdir /downloads
    cd /downloads
    wget https://dl.influxdata.com/telegraf/releases/telegraf_1.12.1-1_amd64.deb
    dpkg -i telegraf_1.12.1-1_amd64.deb
    systemctl enable --now telegraf
    systemctl status telegraf
    启动成功后 telegraf 就会默默的写入cpu,disk等信息到influxdb中
    

    查telegraf 状态

    root@xxx:/# telegraf status
    2020-11-12T09:34:48Z I! Starting Telegraf 1.12.1
    2020-11-12T09:34:48Z I! Using config file: /etc/telegraf/telegraf.conf
    2020-11-12T09:34:48Z I! Loaded inputs: cpu disk diskio kernel mem processes swap system
    2020-11-12T09:34:48Z I! Loaded aggregators: 
    2020-11-12T09:34:48Z I! Loaded processors: 
    2020-11-12T09:34:48Z I! Loaded outputs: influxdb
    2020-11-12T09:34:48Z I! Tags enabled: host=iZ8vbealpwhng8ovp3fyz6Z
    2020-11-12T09:34:48Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"xxx", Flush Interval:10s
    ^C2020-11-12T09:34:52Z I! [agent] Hang on, flushing any cached metrics before shutdown
    
    

    由上可知配置文件为 /etc/telegraf/telegraf.conf ,有其他操作可修改配置文件

    3.最后用grafana展示influxDb中的数据

    如果需要在docker中安装grafana请参考 : https://www.jianshu.com/p/87e1ca5b84c9

    • 下图为在grafana中的explore模块查找influxDb中的数据做出的时序报表
    image.png

    相关文章

      网友评论

          本文标题:docker: influxDb + telegraf + gr

          本文链接:https://www.haomeiwen.com/subject/rmnfbktx.html