Jmeter+InfluxDB+Grafana+Prometheus

前置:
- Linux系統(tǒng)版本:CentOS Linux release 7.8.2003 (Core)
- 命令:cat /etc/redhat-release

- JMeter版本:apache-jmeter-5.4.1
- InfluxDB版本:InfluxDB shell version: 1.8.4
- JDK版本:openjdk version "1.8.0_292"
- Windows查看端口是否被占用:netstat -ano|findstr "3306",沒有返回數(shù)據(jù)代表沒被占用

C:\Users\小二哥>netstat -ano|findstr "3306"

C:\Users\小二哥>netstat -ano|findstr "6060"

- Centos查看端口是否被占用:netstat -tunlp | grep 8086

一、安裝JDK

1.查看JDK可安裝版本
yum search java|grep jdk

[root@iZwz9ga2spyeb5u9tdq8t5Z /]# yum search java|grep jdk
ldapjdk-javadoc.noarch : Javadoc for ldapjdk
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-demo.i686 : OpenJDK Demos 8
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 8
java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed
java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle 8
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle
java-11-openjdk.i686 : OpenJDK Runtime Environment 11
......
java-latest-openjdk-static-libs-fastdebug.x86_64 : OpenJDK 16 libraries for
ldapjdk.noarch : The Mozilla LDAP Java SDK

2.查安裝JDK,這里安裝的是open jdk,默認安裝路徑:/usr/lib/jvm/
yum install -y java-1.8.0-openjdk-devel.x86_64

3.配置JDK環(huán)境變量
1)進入配置文件:vim /etc/profile
2)在結(jié)尾處添加, G 快速移至最后一行:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

3)重新加載profile文件:source /etc/profile
4)驗證JDK安裝和配置成功:java -version

二、安裝JMeter

1.官網(wǎng)下載到本地:http://jmeter.apache.org/download_jmeter.cgi

Jmeter

2.服務(wù)器創(chuàng)建安裝目錄

[root@iZwz9ga2spyeb5u9tdq8t5Z local]   cd /usr/local
[root@iZwz9ga2spyeb5u9tdq8t5Z local]   mkdir jmeter

3.上傳并解壓
1)上傳方式很多,自行百度。上傳到j(luò)meter目錄下
2)解壓:unzip apache-jmeter-5.4.1.zip

[root@iZwz9ga2spyeb5u9tdq8t5Z jmeter]# unzip apache-jmeter-5.4.1.zip 
[root@iZwz9ga2spyeb5u9tdq8t5Z jmeter]# ls
apache-jmeter-5.4.1  apache-jmeter-5.4.1.zip

4.配置JMeter環(huán)境變量
1)進入配置文件:vim /etc/profile
2)在結(jié)尾處添加, G 快速移至最后一行:

export JMETER_HOME=/usr/local/jmeter/apache-jmeter-5.4.1
export PATH=${JMETER_HOME}/bin:$PATH

3)重新加載profile文件:source /etc/profile
4)驗證安裝配置成功:jmeter -v

[root@iZwz9ga2spyeb5u9tdq8t5Z jmeter]# jmeter -v
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
    _    ____   _    ____ _   _ _____       _ __  __ _____ _____ _____ ____
   / \  |  _ \ / \  / ___| | | | ____|     | |  \/  | ____|_   _| ____|  _ \
  / _ \ | |_) / _ \| |   | |_| |  _|    _  | | |\/| |  _|   | | |  _| | |_) |
 / ___ \|  __/ ___ \ |___|  _  | |___  | |_| | |  | | |___  | | | |___|  _ <
/_/   \_\_| /_/   \_\____|_| |_|_____|  \___/|_|  |_|_____| |_| |_____|_| \_\ 5.4.1

Copyright (c) 1999-2021 The Apache Software Foundation

二、安裝InfluxDB

1.指定目錄下下載InfluxDB,由于之前安裝2.x的兼容不了,這里學(xué)習(xí)記錄的是1.x:
- 1.0 wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.4.x86_64.rpm
- 2.0 wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.0.4.x86_64.rpm

2.安裝InfluxDB:yum localinstall influxdb-1.8.4.x86_64.rpm,兩個主要文件位置

influxdb.service: /usr/lib/influxdb/scripts/influxdb.service
influxdb.conf: /etc/influxdb/influxdb.conf

3.更改服務(wù)啟動配置:vim influxdb.service
1)將User和Group值改成root

[Service]
User=root
Group=root
LimitNOFILE=65536
EnvironmentFile=-/etc/default/influxdb
ExecStart=/usr/bin/influxd -config /etc/influxdb/influxdb.conf $INFLUXD_OPTS
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=multi-user.target
Alias=influxd.service

2)重新生效服務(wù):systemctl daemon-reload

4.查看Influxdb安裝成功:influx -version

[root@iZwz9ga2spyeb5u9tdq8t5Z scripts]# influx -version
InfluxDB shell version: 1.8.4

5.啟動Influxdb服務(wù)
1)臨時啟動:systemctl start influxdb
2)開機啟動:systemctl enable influxdb
3)查看運行狀態(tài):ps -ef | grep -i "influx"或者service influxdb status

[root@iZwz9ga2spyeb5u9tdq8t5Z /]# ps -ef | grep -i "influx"
influxdb 18955     1  0 19:21 ?        00:00:00 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
root     22749 18221  0 19:24 pts/0    00:00:00 grep --color=auto -i influx

[root@iZwz9ga2spyeb5u9tdq8t5Z /]# service influxdb status
Redirecting to /bin/systemctl status influxdb.service
● influxdb.service - InfluxDB is an open-source, distributed, time series database
   Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2021-05-03 19:21:06 CST; 4min 22s ago
     Docs: https://docs.influxdata.com/influxdb/
 Main PID: 18955 (influxd)
   CGroup: /system.slice/influxdb.service
           └─18955 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

6.創(chuàng)建Influxdb數(shù)據(jù)庫
1) 進入influx命令:influx

[root@iZwz9ga2spyeb5u9tdq8t5Z /]# influx
Connected to http://localhost:8086 version 1.8.4
InfluxDB shell version: 1.8.4

2)展示數(shù)據(jù)庫,和mysql類似:show databases

> show databases
name: databases
name
----
_internal

3)創(chuàng)建/刪除數(shù)據(jù)庫: create/drop(刪除) jmeter(庫名)

> create database jmeter
> show databases
name: databases
name
----
_internal
jmeter

4)切換數(shù)據(jù)庫:use jmeter(庫名);展示表:show measurements

> use jmeter
Using database jmeter
> show measurements
> 

5)創(chuàng)建measurements:influxdb中沒有創(chuàng)建表的語句,是直接通過insert語句實現(xiàn)measurement
insert語法:insert measurementName,tag1=value1[,tag2=value2] field1=value1[,field2=value2] <時間戳>

  • insert
> insert aliyun,name="lily",age=18 favourite="melon",job=800
> insert aliyun,name="harry",age=22 favourite="magic",job=666
> show measurements
name: measurements
name
----
aliyun
> 
  • 查詢該表aliyun
> select * from aliyun
name: aliyun
time                age favourite job name
----                --- --------- --- ----
1620047056397676385 18  melon     800 "lily"
1620047100232010422 22  magic     666 "harry"
> 

※會發(fā)現(xiàn)查詢出來的時間是時間戳,解決辦法是:influx -precision rfc3339啟動數(shù)據(jù)庫

  • 查詢所有tag的key和value:age name
keys:
> show tag keys from aliyun
name: aliyun
tagKey
------
age
name
> 

values:
> show tag values from aliyun with key="name"
name: aliyun
key  value
---  -----
name "harry"
name "lily"
> 
  • ※疑問:
    a) 如何修改端口?2.x怎么安裝?小二還沒摸索明白~~
    b)官網(wǎng)說的yum安裝,還有密鑰認證,小二也沒成功

三、安裝Chronograf

由于InfluxDB1.x以后就沒有了webUI界面,所以需要Chronograf來實現(xiàn)可視化構(gòu)建

1.下載安裝Chronograf
wget https://dl.influxdata.com/chronograf/releases/chronograf-1.8.10.x86_64.rpm
sudo yum localinstall chronograf-1.8.10.x86_64.rpm

2.啟動Chronograf:systemctl start chronograf,同樣可以設(shè)置開機啟動
3.訪問webUI界面,配置influxdb數(shù)據(jù)庫:http://ip:8888
一路點到底,因為小二也不知道那些字段干什么的?/(ㄒoㄒ)/~~

新增數(shù)據(jù)庫連接

配置數(shù)據(jù)庫

四、安裝Grafana

Grafana是一款用Go語言開發(fā)的開源數(shù)據(jù)可視化工具,可以做數(shù)據(jù)監(jiān)控和數(shù)據(jù)統(tǒng)計,帶有告警功能:https://grafana.com/grafana/download

1.切換到指定目錄下rpm方式下載
wget https://dl.grafana.com/oss/release/grafana-7.4.3-1.x86_64.rpm

2.安裝:sudo yum install grafana-7.4.3-1.x86_64.rpm,配置文件grafana.ini位置

[root@iZwz9ga2spyeb5u9tdq8t5Z grafana]# ls
grafana.ini  ldap.toml  provisioning
[root@iZwz9ga2spyeb5u9tdq8t5Z grafana]# pwd
/etc/grafana

3.啟動grafana
1)開機啟動
啟動服務(wù):systemctl start grafana-server
開機啟動:systemctl enable grafana-server
重新啟動:systemctl restart grafana-server

2)查看啟動狀態(tài)

[root@iZwz9ga2spyeb5u9tdq8t5Z grafana]# service grafana-server status
● grafana-server.service - Grafana instance
   Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-05-05 17:56:30 CST; 1min 56s ago
     Docs: http://docs.grafana.org
 Main PID: 18383 (grafana-server)
   CGroup: /system.slice/grafana-server.service

4.配置grafana:默認監(jiān)聽端口3000,賬號admin/admin
1)添加數(shù)據(jù)源
Configration –>Data Sources –> Add data source ?選擇InfluxDB

配置InfluxDB

image.png

點擊 Save&Test 后出現(xiàn)綠色提示代表添加成功

保存

2)尋找儀表盤Dashboard模板:https://grafana.com/dashboards?dataSource=influxdb

輸入jmeter

復(fù)制ID

3)添加儀表盤Dashboard:Create→Import

第一步Import

第二步Load
第三步確認

※這里的measurement name要和jmeter里的一致~

五、安裝Prometheus

1.官網(wǎng)下載:https://prometheus.io/docs/introduction/first_steps/,以二進制方式安裝

下載地址

2.安裝Prometheus和node_exporter

  • 創(chuàng)建目錄:mkdir prometheus
  • 上傳壓縮包
  • 解壓文件:tar -zxvf prometheus.tar.gz
  • 修改解壓文件夾名稱:mv prometheus-2.26.0.linux-amd64 prometheus
  • 進入prometheus目錄下:cd prometheus

3.啟動服務(wù):./prometheus --config.file=prometheus.yml &

level=info ts=2021-05-11T05:39:39.559Z caller=main.go:815 fs_type=EXT4_SUPER_MAGIC
level=info ts=2021-05-11T05:39:39.559Z caller=main.go:818 msg="TSDB started"
level=info ts=2021-05-11T05:39:39.559Z caller=main.go:944 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2021-05-11T05:39:39.560Z caller=main.go:975 msg="Completed loading of configuration file" filename=prometheus.yml totalDuration=906.425μs remote_storage=7.891μs web_handler=543ns query_engine=1.073μs scrape=346.046μs scrape_sd=81.428μs notify=54.125μs notify_sd=30.896μs rules=4.826μs
level=info ts=2021-05-11T05:39:39.560Z caller=main.go:767 msg="Server is ready to receive web requests."

4.版本查詢:./promethues --version

[root@iZwz9ga2spyeb5u9tdq8t5Z prometheus]  ./prometheus --version
prometheus, version 2.26.0 (branch: HEAD, revision: 3cafc58827d1ebd1a67749f88be4218f0bab3d8d)
  build user:       root@a67cafebe6d0
  build date:       20210331-11:56:23
  go version:       go1.16.2
  platform:         linux/amd64

4.訪問UI界面:IP:9090

  • 打開網(wǎng)頁輸入以下指令
    rate(promhttp_metric_handler_requests_total{code="200"}[1m])
    輸入指令

5.下載安裝node_exporter:https://prometheus.io/download/

下載地址

  • 創(chuàng)建文件夾:mkdir /etc/default/node_exporter
  • 上傳壓縮文件
  • 解壓文件:tar -zxvf node_exporter.1.1.2.linux-amd64.tar.gz
  • 修改解壓文件夾名稱:mv node_exporter.1.1.2.linux-amd64 node_exporter
  • 進入目錄:cd node_exporter
  • 啟動服務(wù):nohup /etc/default/node_exporter/node_exporter/node_exporter &
  • 打開UI:IP:9100,查看端口:lsof -i:9100
[root@iZwz9ga2spyeb5u9tdq8t5Z node_exporter]# lsof -i:9100
COMMAND     PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
node_expo 30994 root    3u  IPv6 4015988      0t0  TCP *:jetdirect (LISTEN)
Node_exporter

6.編輯Prometheus配置文件:

  • 先殺掉prometheus:pkill prometheus
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:668 msg="Stopping scrape discovery manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:682 msg="Stopping notify discovery manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:704 msg="Stopping scrape manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:664 msg="Scrape discovery manager stopped"
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:678 msg="Notify discovery manager stopped"
level=info ts=2021-05-11T05:22:10.102Z caller=manager.go:934 component="rule manager" msg="Stopping rule manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=manager.go:944 component="rule manager" msg="Rule manager stopped"
level=info ts=2021-05-11T05:22:10.103Z caller=main.go:698 msg="Scrape manager stopped"
level=info ts=2021-05-11T05:22:10.110Z caller=notifier.go:601 component=notifier msg="Stopping notification manager..."
level=info ts=2021-05-11T05:22:10.110Z caller=main.go:872 msg="Notifier manager stopped"
level=info ts=2021-05-11T05:22:10.111Z caller=main.go:884 msg="See you next time!"
  • 然后vim prometheus.yml,在最后面添加:
[root@iZwz9ga2spyeb5u9tdq8t5Z prometheus]# vim prometheus.yml 
# 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']

  - job_name: 'xxx.xx.xxx.xxx'
    static_config:
    - targets: ['xxx.xx.xxx.xx:9100']

參考https://blog.csdn.net/qq_43417559/article/details/109012296

7.重啟服務(wù):./prometheus --config.file=prometheus.yml &
8.訪問IP:9090,點擊導(dǎo)航欄中的status→targets。顯示如下圖說明配置成功
※如果狀態(tài)位DOWN,需要檢查下防火墻是否關(guān)閉

配置結(jié)果

9.在Grafana中配置prometheus

  • 添加prometheus的data sources
  • Import Dashboard,方法跟Influxdb類似,不做過多介紹

10.Jmeter非GUI命令運行
jmeter -n -t file.jmx -l result.jtl -e -o reopot

  • -n:非GUI模式運行
  • -t:指定jmx文件位置
  • -l:指定生成jtl的格式結(jié)果
  • -e:生成html報告
  • -o:指定html報告文件夾(必須是空目錄)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容