Created
April 16, 2019 03:07
-
-
Save zhangli2946/05d0a60bf11b4f7bf53c3721d30acf22 to your computer and use it in GitHub Desktop.
prometheus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prometheus 监控部署指南 | |
## 1 JMX Exporter | |
### 1.1 安装 jmx_agent | |
- 下载 | |
- jmx_prometheus_javaagent-0.9.jar | |
```bash | |
wget -c https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.9/jmx_prometheus_javaagent-0.9.jar | |
mv jmx_prometheus_javaagent-0.9.jar kafka/libs | |
``` | |
- kafka-0-8-2.yml | |
```bash | |
wget -c https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-0-8-2.yml | |
mv kafka-0-8-2.yml kafka/config | |
``` | |
- 配置 kafka-server-start.sh | |
```patch | |
+ export JMX_PORT=${JMX_PORT:-9999} | |
+ export PROMETHEUS_PORT=${PROMETHEUS_PORT:-7072} | |
COMMAND=$1 | |
... | |
- exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka "$@" | |
+ exec $base_dir/kafka-run-class.sh $EXTRA_ARGS -javaagent:$base_dir/../libs/jmx_prometheus_javaagent-0.9.jar=$PROMETHEUS_PORT:$base_dir/../config/kafka-0-8-2.yml kafka.Kafka "$@" | |
``` | |
- 配置采集任务 | |
```bash | |
SERV_NAME=KAFKA | |
SERV_ENDPOINT=localhost:7072 | |
cat >> prometheus/prometheus.yml << EOF | |
- job_name: '$SERV_NAME' | |
static_configs: | |
- targets: ['$SERV_ENDPOINT'] | |
EOF | |
``` | |
## 2 EMQ Exporter | |
### 2.1 安装 emq_exporter | |
```bash | |
VERSION=0.4.1 | |
DIR=emq_exporter-$VERSION-linux | |
wget -c https://github.com/nuvo/emq_exporter/releases/download/v$VERSION/$DIR.tar.gz | |
tar zxvf $DIR.tar.gz | |
ln -s $DIR emq_exporter | |
mv $DIR.tar.gz $DIR | |
``` | |
### 2.2 配置 emq_exporter | |
- 用户名和密码使用 emqtt 管理 dashboard 账号密码 (默认是 admin/public) | |
```bash | |
EMQ_USERNAME=admin | |
EMQ_PASSWORD=public | |
cat > emq_exporter/auth.json << EOF | |
{ | |
"username":$EMQ_USERNAME, | |
"password":$EMQ_PASSWORD | |
} | |
``` | |
### 2.3 启动 emq_exporter | |
- 前台启动 | |
```bash | |
EMQ_USERNAME=admin EMQ_PASSWORD=public emq_exporter/emq_exporter | |
``` | |
- 后台启动 | |
```bash | |
BIN=emq_exporter | |
nohup $BIN/$BIN > /tmp/$BIN.stdout 2>&1 & | |
``` | |
## 3 Node Exporter | |
### 3.1 安装 node_exporter | |
```bash | |
VERSION=0.17.0 | |
DIR=node_exporter-$VERSION-linux-amd64 | |
wget -c https://github.com/prometheus/node_exporter/releases/download/v$VERSION/$DIR.tar.gz | |
tar zxvf $DIR.tar.gz | |
ln -s $DIR node_exporter | |
mv $DIR.tar.gz $DIR | |
``` | |
### 3.2 启动 node_exporter | |
- 前台启动 | |
```bash | |
node_exporter/node_exporter | |
``` | |
- 后台启动 | |
```bash | |
BIN=node_exporter | |
nohup $BIN/$BIN > /tmp/$BIN.stdout 2>&1 & | |
``` | |
## 4 Prometheus | |
### 4.1 安装 prometheus | |
```bash | |
VERSION=2.8.0 | |
DIR=prometheus-$VERSION.linux-amd64 | |
wget -c https://github.com/prometheus/prometheus/releases/download/v2.8.0/prometheus-2.8.0.linux-amd64.tar.gz | |
tar zxvf $DIR.tar.gz | |
ln -s $DIR prometheus | |
mv $DIR.tar.gz prometheus | |
``` | |
### 4.2 配置采集任务 | |
```bash | |
SERV_NAME=EMQ | |
SERV_ENDPOINT=localhost:9540 | |
cat >> prometheus/prometheus.yml << EOF | |
- job_name: '$SERV_NAME' | |
static_configs: | |
- targets: ['$SERV_ENDPOINT'] | |
EOF | |
``` | |
### 4.3 启动 prometheus | |
- 前台启动 | |
```bash | |
prometheus/prometheus | |
``` | |
- 后台启动 | |
```bash | |
BIN=prometheus | |
nohup $BIN/$BIN > /tmp/$BIN.stdout 2>&1 & | |
``` | |
## 5 Grafana | |
### 5.1 安装 grafana | |
```bash | |
VERSION=5.4.2 | |
DIR=grafana-$VERSION | |
wget -c https://dl.grafana.com/oss/release/grafana-$VERSION.linux-amd64.tar.gz | |
tar zxvf grafana-$VERSION.linux-amd64.tar.gz | |
ln -s $DIR grafana | |
mv grafana-$VERSION.linux-amd64.tar.gz $DIR | |
``` | |
### 5.2 启动 grafana | |
- 前台启动 | |
```bash | |
grafana/bin/grafana-server -homepath grafana/ | |
``` | |
- 后台启动 | |
```bash | |
BIN=grafana | |
nohup $BIN/bin/$BIN-server > /tmp/$BIN.stdout 2>&1 & | |
``` | |
### 5.3 添加 Prometheus 数据源 | |
- 新建数据源[Prometheus类型] -> 填写服务地址 -> 测试连接 -> 保存并返回 | |
### 5.4 导入 Kafka Dashboard | |
- 公网 | |
- 导入 Dashboard -> 选择 Dashboard ID : 7589 -> 选择数据源 | |
- 私网 | |
- 导入 Dashboard -> 选择 Json Model -> 选择数据源 [7589.json](https://gist.githubusercontent.com/zhangli2946/5138f537ea328610aa26b674c6b0c9ae/raw/4fde05979950ac2e64698c2d1ea871894547ea0e/7589.json) | |
### 5.5 导入 EMQ Dashboard | |
- 公网 | |
- 导入 Dashboard -> 选择 Dashboard ID : 9963 -> 选择数据源 | |
- 私网 | |
- 导入 Dashboard -> 选择 Json Model -> 选择数据源 [9963.json](https://gist.githubusercontent.com/zhangli2946/b20e7f4921d77b3a4885707dfa506e0d/raw/244f9b6d865b48aea4a9065d0228e2f54d75fb41/9963.json) | |
### 5.6 导入 Node Dashboard | |
- 公网 | |
- 导入 Dashboard -> 选择 Dashboard ID : 8919 -> 选择数据源 | |
- 私网 | |
- 导入 Dashboard -> 选择 Json Model -> 选择数据源 [8919.json](https://gist.githubusercontent.com/zhangli2946/b20e7f4921d77b3a4885707dfa506e0d/raw/244f9b6d865b48aea4a9065d0228e2f54d75fb41/9963.json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment