zoukankan      html  css  js  c++  java
  • telegraf1.8+influxdb1.6+grafana5.2 环境搭建 结合JMeter3.2

    telegraf1.8+influxdb1.6+grafana5.2 环境搭建 结合JMeter3.2

    参考地址:https://blog.csdn.net/laisinanvictor/article/details/80007356

    1)配置yum源
    #配置yum源 /etc/yum.repos.d/influxdb.repo
    [influxdb]
    name = InfluxDB Repository - RHEL $releasever
    baseurl = https://repos.influxdata.com/rhel/$releasever/$basearch/stable
    enabled = 1
    gpgcheck = 1
    gpgkey = https://repos.influxdata.com/influxdb.key


    2)安装telegraf
    #收集系统和服务的统计数据 , 并写入到 InfluxDB数据库 , 在需要监控的机器上安装
    yum -y install telegraf

    #配置文件路径
    /etc/telegraf/telegraf.conf


    #设置开机时启动
    systemctl enable telegraf.service

    #启动
    systemctl start telegraf
    systemctl status telegraf

    #例子:配置Telegraf(这里用不到,所以不用配置)
    [root@monitor src]# vim /etc/telegraf/telegraf.conf
    ## 修改内容如下
    # Configuration for influxdb server to send metrics to
    [[outputs.influxdb]]
    ## The full HTTP or UDP URL for your InfluxDB instance.
    ##
    ## Multiple URLs can be specified for a single cluster, only ONE of the
    ## urls will be written to each interval.
    # urls = ["unix:///var/run/influxdb.sock"]
    # urls = ["udp://127.0.0.1:8089"]
    # urls = ["http://127.0.0.1:8086"]

    urls = ["http://10.1.5.49:8086"]

    ## The target database for metrics; will be created as needed.
    # database = "telegraf"

    database = "ip_214_70_stat"

    systemctl restart telegraf

    #卸载telegraf(重装时需要卸载)
    rm -rf telegraf
    rm -rf /etc/systemd/system/multi-user.target.wants/telegraf.service

    #检查Telegraf配置
    systemctl status telegraf
    #状态是running说明配置加载成功


    3)安装influxdb
    #时序数据库,默认端口为Web端8083,API端8086,默认登陆信息admin 使用方式有点类似MySQL
    #新版本 web界面功能被去掉了

    #安装
    yum -y install influxdb

    #设置开机时启动
    systemctl enable influxdb.service

    #启动
    systemctl start influxdb
    systemctl status influxdb

    #增加8083 8086端口,允许他通过防火强 influxdb:8083 8086
    firewall-cmd --zone=public --add-port=8083/tcp --permanent
    firewall-cmd --zone=public --add-port=8086/tcp --permanent

    #重新加载防火强
    firewall-cmd --reload

    #查看通过防火强的端口
    firewall-cmd --zone=public --list-ports

    #重启防火强
    systemctl restart firewalld


    4)创建 Influxdb数据库
    [root@monirot src]# influx
    Connected to http://localhost:8086 version 1.6.3
    InfluxDB shell version: 1.6.3

    #重启influxdb
    systemctl restart influxdb

    #查看数据
    打开 Influxdb 查询界面:http://你的ip地址:8086 , 输入查询语句seclect * from cpu可查询到 CPU 相关信息。

    访问 influxdb
    http://ip:8086/


    5)安装Grafana
    #访问各类数据源,自定义报表,显示图表等等, 用于提供界面监控,默认端口为3000,默认登陆信息admin
    地址:https://grafana.com/grafana/download?platform=linux

    wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.4-1.x86_64.rpm
    sudo yum -y localinstall grafana-5.2.4-1.x86_64.rpm

    yum -y install fontconfig
    yum -y install freetype*
    yum -y install urw-fonts


    安装路径 /usr/sbin/grafana-server
    init.d路径 /etc/init.d/grafana-server
    环境变量文件路径 /etc/sysconfig/grafana-server
    ini 文件路径 /etc/grafana/grafana.ini
    Installs systemd service (if systemd is available) name grafana-server.service
    日志文件路径 /var/log/grafana/grafana.log
    sqllite3库路径 /var/lib/grafana/grafana.db

    systemctl daemon-reload
    systemctl start grafana-server
    systemctl status grafana-server

    #设置开机时启动
    systemctl enable grafana-server.service

    #启动
    systemctl start grafana-server
    systemctl status grafana-server

    随机启动
    sudo systemctl enable grafana-server.service

    #安装ssh服务
    yum -y install openssh-server.x86_64

    #增加3000端口,允许他通过防火强 Grafana:3000
    firewall-cmd --zone=public --add-port=3000/tcp --permanent

    #重新加载防火强
    firewall-cmd --reload

    #查看通过防火强的端口
    firewall-cmd --zone=public --list-ports

    #重启防火强
    systemctl restart firewalld

    #重启
    systemctl restart grafana-server

    #配置Grafana
    http://192.168.169.131:3000 账号:admin 密码:admin 新密码为 123456


    6)将JMeter压测后的结果数据,通过Grafana界面展示出来
    #6-1修改influxdb配置文件
    vim /etc/influxdb/influxdb.conf

    #打开8086端口
    [http]
    # Determines whether HTTP endpoint is enabled.
    enabled = true

    # The bind address used by the HTTP service.
    bind-address = ":8086"

    # Determines whether user authentication is enabled over HTTP/HTTPS.
    auth-enabled = false


    #在以下地方新增 influx_db 数据库,配置好 监控 influx_db 端口号默认为 2003
    [[graphite]]
    # Determines whether the graphite endpoint is enabled.
    enabled = true
    database = "influx_db"
    retention-policy = "" #influxdb上数据保存策略,参考后面设置
    bind-address = ":2003"
    protocol = "tcp"
    consistency-level = "one"

    #influxdb上数据保存策略(该步骤可忽略)
    name 策略名 duration持续时间 0 无限制 shardGroupDuration shardGroup存储时间 replicaN副本个数 default 默认策略
    1、新建数据保存策略
    CREATE RETENTION POLICY "30d_jmeter" ON "influx_db" DURATION 30d REPLICATION 1 DEFAULT

    2、删除初始策略
    DROP RETENTION POLICY "autogen" ON "influx_db"

    3、显示已有策略
    SHOW RETENTION POLICIES on influx_db

    #保存文件后,再次启动 influxdb
    systemctl start influxdb

    #6-2创建jmeter数据库
    [root@monitor jmeter3.2]# influx
    Connected to http://localhost:8086 version 1.6.3
    InfluxDB shell version: 1.6.3
    > create database influx_db
    > use influx_db
    Using database influx_db
    > create user "admin" with password '123456' with all privileges

    > create database graphite_db
    > use graphite_db
    Using database graphite_db
    > create user "admin" with password '123456' with all privileges

    > create database ip_214_70_stat
    > use ip_214_70_stat
    Using database ip_214_70_stat
    > create user "admin" with password '123456' with all privileges
    > show databases
    name: databases
    name
    ----
    influx_db
    _internal
    ip_214_70_stat
    > exit


    #6-3在jmeter脚本文件中,新增监听器:Backend Listener
    方式1:
    Backend Listener implementation:保持默认 org.apache.jmeter.visualizers.backend.graphite.GraphiteBackendListenerClient
    Async Quenue size:取数据的间隔 5000毫秒

    graphiteMetricsSender:保持默认 org.apache.jmeter.visualizers.backend.graphite.TextGraphiteMetricsSender
    graphiteHost:influxdb机器的IP地址 ip
    graphitePort:influxdb中配置的端口号 默认 2003
    rootMetricsPrefix:influxdb中配置的表名 jmeter. 不要更改该名字
    summaryOnly:改成 false 是否统计总量
    samplersList:改成 .* 请求的URL关键字.*
    useRegexpForSamplersList:改成 true
    percentiles:保持默认 90;95;99

    #要配置对应某个请求的话,需要配置一下三项,否则保持默认就行
    summaryOnly:改成 false
    samplersList:改成 .*请求的URL关键字.* #summaryOnly=true,此处设置则失效,与请求的URL进行匹配,支持正则表达式,就是请求的名称是什么,这里就要配置的好去对应它
    useRegexpForSamplersList:改成 true


    方式2:
    Backend Listener implementation:保持默认 org.apache.jmeter.visualizers.backend.influxdb.influxdbBackendListenerClient
    Async Quenue size:取数据的间隔 5000毫秒

    graphiteMetricsSender:保持默认 org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
    graphiteHost:influxdb机器的IP地址 ip http://ip:8086/write?db=influx_db
    application:应用名 比如:某某系统接口测试 influx_db
    measurement: jmeter
    summaryOnly:改成 false 是否统计总量
    samplersRegex:.* 正则表达式
    percentiles:保持默认 50;90;95;99
    testTitle:influx_db_testTitle
    eventTags:influx_db_eventTags

    #6-4访问grafana http://ip:3000/
    #修改配置文件
    vim /etc/grafana/grafana.ini
    #打开一下注释
    [server]
    # Protocol (http, https, socket)
    protocol = http

    # The ip address to bind to, empty will bind to all interfaces
    ;http_addr =

    # The http port to use
    http_port = 3000

    [security]
    # default admin user, created on startup
    admin_user = admin

    # default admin password, can be changed before first start of grafana, or in profile settings
    admin_password = 123456


    #配置数据库 ,保存后退出
    #8086端口 是Grafana用来从数据库取数据的端口 2003端口是JMeter往数据库里面发数据的端口
    name:name 随意取值
    type:influxDB

    HTTP
    URL:http://ip:8086
    Access:Server(Default)

    InfluxDB Details
    Database:influx_db
    #创建jmeter数据库时,指定的用户,该用户可访问该jmeter数据库
    user:admin Password:123456

    Min time interval:10秒


    #配置数据库面板 Home->dashboard->Graph->Edit
    #在编辑中,选择数据库 Data Source :middleground
    #压测运行完成,到图标里面就可以看到对应数据库了

    jmeter.all.h.count 所有请求的TPS
    jmeter.<请求名称>.h.count 对应<请求名称>的TPS
    jmeter.all.ok.pct99 99%的请求响应时间
    jmeter.<请求名称>.ok.pct99 对应<请求名称>99%的请求响应时间
    jmeter.all.test.startedT 线程数

    #安装jmeter模板,进入下面网站,选择influxdb 搜索jmeter
    https://grafana.com/dashboards
    选择JMeter Load Testby NovaTec-APM,之后下载Download JSON
    下载文件JMeter-InfluxDB-Writer-plugin-1.2.jar 放到libext目录下

    在grafana中,上传刚下载的json文件到dashboard,将2个josn文件上传到grafana,导入到 dashboard 中
    业务资源:资源监控面板配置参考这个文件:https://grafana.com/dashboards/4026 或https://grafana.com/dashboards/1152 或https://grafana.com/dashboards/5496(使用该模板,要用jm5.0) 通过jmeter搜索

    硬件资源:资源监控面板配置参考这个文件:https://grafana.com/dashboards/3967 或https://grafana.com/dashboards/928 通过System搜索

    yum -y install sysstat
    telegraf.conf 配置新增以下内容
    [global_tags]
    [agent]
    interval = "15s"
    round_interval = true
    metric_batch_size = 1000
    metric_buffer_limit = 10000
    collection_jitter = "0s"
    flush_interval = "15s"
    flush_jitter = "0s"
    precision = ""
    debug = false
    quiet = false
    logfile = ""
    hostname = ""
    omit_hostname = false
    [[outputs.influxdb]]
    retention_policy = ""
    write_consistency = "any"
    timeout = "5s"
    username = "my login"
    password = "my password"
    [[inputs.cpu]]
    percpu = true
    totalcpu = true
    collect_cpu_time = true
    report_active = true
    [[inputs.disk]]
    ignore_fs = ["tmpfs", "devtmpfs", "devfs"]
    [[inputs.diskio]]
    [[inputs.kernel]]
    [[inputs.mem]]
    [[inputs.processes]]
    [[inputs.swap]]
    [[inputs.system]]
    [[inputs.net]]
    [[inputs.netstat]]
    [[inputs.sysstat]]
    activities = ["DISK"]
    [inputs.sysstat.options]
    -C = "cpu"
    -B = "paging"
    -b = "io"
    -d = "disk"
    "-n ALL" = "network"
    "-P ALL" = "per_cpu"
    -q = "queue"
    -r = "mem_util"
    -S = "swap_util"
    -u = "cpu_util"
    -v = "inode"
    -W = "swap"
    -w = "task"

  • 相关阅读:
    Intellijidea建javaWeb以及Servlet简单实现
    PHP关于文件与文件夹(1) 写入文件 文件权限 三、锁定文件
    mysql 时间戳格式化函数from_unixtime使用说明
    Ansible 2.0公布
    如何获取板子上独有的ID号EXYNOS4412/Imx6ul【转】
    2.7 xargs和exec详解【转】
    __setup 在内核中的作用【转】
    Linux __setup解析【转】
    c语言中 %p的含义【转】
    函数 devm_kzalloc()【转】
  • 原文地址:https://www.cnblogs.com/NiceTime/p/10025632.html
Copyright © 2011-2022 走看看