Prometheus简单使用

安装

下载地址: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的界面要好看得多。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值