背景
最近在研究Gatling,這是一款釋出很久但在國内使用範圍不是很廣泛的壓測工具。研究這款工具的理由很簡單,很喜歡生成的html報告,本文會提供幾張截圖給大家一個直覺感受,但這不是本文的重點,Gatling官網下載下傳的版本不支援實時監控,隻有在simulations結束後,打開html報告才能看到資料圖表,這不符合我們邊壓測邊看圖表的習慣。
實時監控
官網說明文檔中有關于實時監控章節的介紹,有興趣的同學可以直接去官網看Realtime monitoring,本文要介紹的部署方式:influxdb + grafana采用docker部署,更友善便捷。
部落客伺服器環境為centos7,如為ubuntu、mac等環境,請自行研究,應該大緻上差不多
部署
安裝鏡像
在安裝influxdb和grafana鏡像前,先安裝docker環境和docker-compose環境。Docker-Compose是一個部署多個容器的簡單但是非常必要的工具
* docker安裝
- docker-compose安裝
安裝Docker-Compose之前,請先安裝 python-pip。
1、首先檢查linux有沒有安裝python-pip包,終端執行 pip -V
[root@vm-- network-scripts]# pip -V
-bash: pip: command not found
沒有python-pip包就執行指令 yum -y install epel-release
3、執行成功之後,再次執行yum -y install python-pip
4、對安裝好的pip進行更新 pip install –upgrade pip
至此,pip安裝好了,執行pip -V 再次檢查pip環境。
[[email protected] local]# pip -V
pip from /usr/lib/python2/site-packages (python )
安裝Docker-Compose
檢查docker-compose 安裝:docker-compose -version
[root@host---- local]# docker-compose -version
docker-compose version .0, build dd22a9
- influxdb鏡像
docker pull influxdb;
- grafana鏡像
docker pull grafana/grafana;
配置檔案
在伺服器/usr/local目錄下建立monitor目錄,并在monitor下建立兩個目錄influxdb和grafana
[root@host---- local]# ls monitor
grafana influxdb
在influxdb目錄下建立docker-compose.yml檔案,檔案内容如下:
[[email protected] influxdb]# cat docker-compose.yml
version: "2"
services:
influxdb:
image: influxdb
ports:
- :
- :
environment:
- INFLUXDB_GRAPHITE_ENABLED=true
8086端口為influxdb的監聽端口,2003端口為gatling的監聽端口
在grafana目錄下建立docker-compose.yml檔案,檔案内容如下:
[[email protected] grafana]# cat docker-compose.yml
version: "2"
services:
influxdb:
image: grafana/grafana
ports:
- :
environment:
- GF_SERVER_ROOT_UR=http://127.0.0.1
- GF_SECURITY_ADMIN_PASSWORD=passwd
3000端口為grafana的監聽端口
配置完influxdb和grafana後,我們再配置gatling内容,進入gatling的conf目錄下,打開gatling.conf,按照實際情況修改如下内容:
配置檔案配置完成後,然後就是依次啟動influxdb和grafana服務
服務啟動
influxdb啟動
進入/usr/local目錄下,執行如下指令:
檢查influxdb啟動結果,運作指令docker ps
[root@host---- local]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ffa5f8edeea6 influxdb "/entrypoint.sh influ" hours ago Up hours ...:->/tcp, ...:->/tcp influxdb_influxdb_1
進入influxdb容器,修改配置檔案
[root@host---- local]# docker exec -it ffa5f8edeea6 bash
root@ffa5f8edeea6:/#
安裝vim編輯器
apt-get update
apt-get install -y vim
修改influxdb配置檔案,添加如下内容:
[email protected]:/# vim /etc/influxdb/influxdb.conf
[meta]
dir = "/var/lib/influxdb/meta"
[data]
dir = "/var/lib/influxdb/data"
engine = "tsm1"
wal-dir = "/var/lib/influxdb/wal"
[[graphite]]
enabled = true
database = "gatlingdb"
templates = [
"gatling.*.*.*.* measurement.simulation.request.status.field",
"gatling.*.users.*.* measurement.simulation.measurement.request.field"
]
influxdb配置檔案修改後,需要重新開機容器,操作步驟如下:
1、退出influxdb容器
2、進入到/usr/local/monitor/influxdb目錄下,執行指令docker-compose restart
grafana啟動
進入/usr/local目錄下,執行如下指令:
grafana管理背景操作
啟動成功後,通路http://10.200.143.10:3000即可打開grafana管理頁面,進入登入頁面:
使用者名預設為admin,密碼為前面grafana目錄下docker-compose.yml配置的密碼,登入成功後看到的頁面
配置資料源Data Sources,如
配置完成後,點選儲存,這裡可能會遇到如下問題
解決方法:
1、進入influxdb控制台
[root@host---- local]# influx
Connected to http://localhost:8086 version 1.4.2
InfluxDB shell version: .4
2、檢視influxdb資料庫
> show databases;
name: databases
name
----
_internal
确實沒有gatlingdb資料庫,但我們可能建立gatlingdb資料庫
3、建立gatlingdb資料庫
> create database gatlingdb;
> show databases;
name: databases
name
----
_internal
gatlingdb
說明gatlingdb資料庫建立好了,然後就是導入實時監控模闆,模闆位址:https://github.com/gatling/gatling/blob/master/src/sphinx/realtime_monitoring/code/gatling.json
将模闆json import到監控面闆即可
終于弄好了,現在見證奇迹的時候到了,執行gatling的scala腳本,實時監控壓測情況
實時監控圖表
參考資料:
https://testerhome.com/topics/9380
http://gatling.io/docs/current/realtime_monitoring/