七、JMeter压测实战
目录
- 配置Prometheus
- 配置Grafana
一、配置Prometheus
Prometheus简介
- Promethues是一款开源系统监控和警报工具。使用Go语言开发,有各种 exporter用来收集服务器性能数据。
- 我们通过Promethues来监控压测时服务端的性能。
部署Prometheus
- 编辑配置文件:https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus.yml
-
vim prometheus.yml
,输入下面的内容
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
-
运行:
docker run -d --name prometheus --network grafana -p 9090:9090 -v ${PWD}/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:v2.16.0 --config.file=/etc/prometheus/prometheus.yml
-
run
:启动容器 -
-d
:后台运行 -
--name
:指定容器名 -
--network
:指定容器网络 -
-p
:指定端口 -
-v
:将将promethus.yml
挂载到/etc/prometheus/prometheus.yml
路径 -
--config.file
:指定配置文件为容器里的/etc/prometheus/prometheus.yml
文件
image.png
-
-
访问9090端口
image.png -
查看容器状态:Status->Targets
image.png
部署node_exporter到需要被监控的主机上
-
选择稳定版本下载node_exporter:https://github.com/prometheus/node_exporter/releases
image.png
-
解压文件并运行
tar -xzvf node_exporter-1.1.2.linux-amd64.tar.gz
- 查看帮助信息
./node_exporter --help
:
image.png - 指定端口并在后台运行:
nohup ./node_exporter --web.listen-address=":9102" &
,其中nohup xxx &
即在后台运行,--web.listen-address=":9102"
如果主机有多个ip地址,还可以指定ip地址,如--web.listen-address="192.168.31.62:9102"
image.png - 查看nohub输出:
cat nohub.out
image.png
-
开放9102端口:
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
-
访问9102端口:
image.png
配置node_exporter 到 Prometheus
-
image.pngvim prometheus.yml
-
配置node_exporter,其中
job_name
可以随便填
- job_name: 'CentOS 192.168.31.61'
static_configs:
- targets: ['192.168.31.61:9102']
-
重启Prometheus
-
docker ps
:查看容器进程 -
docker restart prometheus
:重启
image.png
-
-
进入9090端口查看Prometheus状态:多出主机监听目标
image.png
二、配置Grafana
配置Data Source,收集服务器数据
-
进入Data Source
image.png
-添加Prometheus
image.png
- 配置Prometheus数据源
- scrape interval时长在
prometheus.yml
中查看
image.png - URL:
http://prometheus:9090
image.png - 点击:
Save & Test
提示working表示配置成功
image.png
- scrape interval时长在
配置Dashboard
-
Prometheus的Grafana Dashboard地址:https://grafana.com/grafana/dashboards/8919
image.png
-
导入Dashboard:
image.png
image.png
image.png
image.png
进行测试
-
查看系统版本:
cat /etc/redhat-release
-
下载nginx服务器:
image.pngyum install nginx
-
重启nginx:
systemctl restart nginx
-
访问80端口,重启成功
image.png -
打开JMeter进行压测
image.png -
使用终端形式运行压测脚本:
image.png./jmeter.sh -n -t bl.jmx
查看结果
-
Influxdb监控面板
image.png -
Prometheus监控面板
image.png
增加线程组进行压测
-
image.pngvim bl.jmx
,增加线程组至10
-
再次运行脚本:
./jmeter.sh -n -t bl.jmx
-
查看结果
image.png
image.png