本文主要讲述使用Go编写的强大的监控组件Prometheus的搭建过程,复制粘贴即可!
1.Prometheus简介
Prometheus基于Go语言写的监控组件,其优点在于不依赖于其他的的第三方依赖。我们只需要下载对应平台的二进制包,解压缩后添加基本的配置就可以正常的启动Prometheus组件。
2. 下载Prometheus安装包
Prometheus官方网站地址:prometheus.io/download/
下载安装步骤:
mkdir -p /opt/work/
wget https://github.com/prometheus/prometheus/releases/download/v2.37.0-rc.1/prometheus-2.37.0-rc.1.linux-amd64.tar.gz -P /opt/work/
cd /opt/work/ && tar -zxvf prometheus-2.37.0-rc.1.linux-amd64.tar.gz
ln -nfs prometheus-2.37.0-rc.1.linux-amd64 prometheus
3. Prometheus配置
配置文件修改
vim /opt/work/prometheus/prometheus.yml
配置文件详解:
# 全局配置
global:
scrape_interval: 15s # 设置指标抓取的时间间隔,默认为1min
evaluation_interval: 15s #对告警规则做定期计算,默认1min
scrape_timeout #默认数据收集的超时时间,默认为10s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# 规则文件列表,使用'evaluation_interval' 参数去抓取
rule_files: #告警规则的设置
# - "first_rules.yml"
# - "second_rules.yml"
# 数据收集配置的列表
scrape_configs:
- job_name: 'prometheus' #必须配置且必须唯一,job labels的标签
static_configs:
- targets: ['localhost:9090'] #目标的列表,可配置多个ip
4. 创建组件启动的用户
生成环境中我们尽量不使用root用户启动进程,这里我们新建prometheus用户用来进行prometheus的启动
创建prometheus用户
useradd -s /sbin/nologin -M prometheus\
5. 将prometheus添加至Systemd服务启动项
vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/\
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/work/prometheus/prometheus --config.file=/opt/work/prometheus/prometheus.yml --storage.tsdb.path=/opt/work/prometheus/data
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl启动命令
systemctl start prometheus
systemctl enable prometheus
6. web方式查看prometheus界面
浏览器通过ip+默认端口9090的方式打开
http://localhost:9090/ ps:(localhost换成本机ip)
好啦,到这里基于go语言编写的强大的监控组件prometheus已经安装完成了
本文正在参加技术专题18期-聊聊Go语言框架