安装
下载地址:https://prometheus.io/download/
#下载prometheus,这里/home/prometheus是我的用户目录
cd /home/prometheus/apps
wget https://github.com/prometheus/prometheus/releases/download/v2.7.1/prometheus-2.7.1.linux-amd64.tar.gz
tar xf prometheus-2.7.1.linux-amd64.tar.gz
mv prometheus-2.7.1.linux-amd64/ prometheus
#创建目录,用于存放log信息
mkdir /home/prometheus/log/prometheus
启动
创建 prometheus 系统服务启动文件 /usr/lib/systemd/system/prometheus.service:
请注意,我这里的用户是prometheus,用户目录是/home/prometheus,配置的时候要注意改成自己的用户。
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=prometheus
Restart=on-failure
ExecStart=/home/prometheus/apps/prometheus/prometheus \
--config.file=/home/prometheus/apps/prometheus/prometheus.yml \
--storage.tsdb.path=/home/prometheus/log/prometheus
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
修改配置文件: prometheus.yml(配置文件在/home/prometheus/apps/prometheus下面)
scrape_configs:
- job_name: 'web'
# 采集数据的间隔时间
scrape_interval: 15s
# 采集数据的超时时间
scrape_timeout: 10s
# 采集数据的api路径
metrics_path: '/monitor/prometheus'
#权限验证,使用之前security配置的用户名密码,如果你的不需要验证的话,忽略
basic_auth:
username: 'admin'
password: '123456'
# 采集服务的地址,设置成上面Spring Boot应用所在服务器的具体地址。
static_configs:
- targets: ['localhost:28080']
启动服务:
systemctl daemon-reload
systemctl start prometheus.service
systemctl enable prometheus.service
systemctl status prometheus.service
Prometheus 服务启动完成后,可以通过http://localhost:9090访问 Prometheus 的 UI 界面。
界面如下:
这个界面看起来不太好看,一般会使用grafana来分析prometheus数据,grafana的界面要好看得多。