侧边栏壁纸
  • 累计撰写 14 篇文章
  • 累计创建 14 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Prometheus监控服务部署

AlanM
2024-01-17 / 0 评论 / 0 点赞 / 32 阅读 / 0 字
温馨提示:
本文最后更新于2024-01-17,若内容或图片失效,请留言反馈。 部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

Prometheus

项目地址
安装步骤
  • 下载、解压及目录指定
wget https://github.com/prometheus/prometheus/releases/download/v2.49.1/prometheus-2.49.1.linux-amd64.tar.gz

tar -xvf prometheus-2.49.1.linux-amd64.tar.gz

mv prometheus-2.49.1.linux-amd64 /etc/prometheus
  • 创建service服务
vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/etc/prometheus/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries \
  --web.listen-address=0.0.0.0:9090 \

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
# 参数解释

1.指定Prometheus配置文件的路径
--config.file=/etc/prometheus/prometheus.yml

2.指定Prometheus时间序列数据库的存储路径
--storage.tsdb.path=/var/lib/prometheus

3.指定Prometheus控制台模板的路径,控制台模板用于呈现和可视化指标数据
--web.console.templates=/etc/prometheus/consoles

4.指定Prometheus控制台库的路径,控制台库包含用于控制台模板的共享库文件。
--web.console.libraries=/etc/prometheus/console_libraries:

5.指定Prometheus Web界面的监听地址为0.0.0.0:9090
--web.listen-address=0.0.0.0:9090
  • 配置prometheus.yml
global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# A scrape configuration containing exactly one endpoint to scrape:
# 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'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
# 参数解释

global:全局配置
scrape_interval:设置prometheus守护进程拉取agent信息时间间隔
evaluation_interval:设置根据后面rule_files字段定义的规则计算的时间间隔

alerting:告警配置
用于配置告警信息,需要通过alertmanagers插件实现,这里暂时未配置

rule_files:规则配置
主要用于触发告警,这里也暂未配置

scrape_configs:抓取目标机器配置
job_name:标识这条记录,也就是这个配置内的记录都会添加上该字段
targets:设置目标机地址
  • 重新载入daemon-raload
systemctl daemon-reload
  • 启动服务&设置开机自启
systemctl start prometheus.service
systemctl enable prometheus.service
  • 查看运行状态
systemctl status prometheus.service
0

评论区