Prometheus安装部署

DevOps Prometheus评论2,891字数 4092阅读13分38秒阅读模式

一、介绍

Prometheus 是一个开源的监控软件。非常适合用来监控docker容器,k8s标配。
优点特性看官方文档吧:https://prometheus.io/docs

二、安装部署

1、二进制包部署

下载地址:https://prometheus.io/download/

Prometheus安装部署

[root@iZ8vb623n6mbyx9d66w0a9Z tmp]# tar -xf prometheus-2.40.2.linux-amd64.tar.gz  -C /usr/local/
[root@iZ8vb623n6mbyx9d66w0a9Z tmp]# mv /usr/local/prometheus-2.40.2.linux-amd64 /usr/local/prometheus
启动脚本
[root@iZ8vb623n6mbyx9d66w0a9Z tmp]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
After=syslog.target

[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml

[Install]
WantedBy=multi-user.target
启动服务
[root@iZ8vb623n6mbyx9d66w0a9Z tmp]# systemctl daemon-reload 
[root@iZ8vb623n6mbyx9d66w0a9Z tmp]# systemctl start prometheus
[root@iZ8vb623n6mbyx9d66w0a9Z tmp]# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.
[root@iZ8vb623n6mbyx9d66w0a9Z tmp]# systemctl status prometheus
● prometheus.service - prometheus
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-11-22 17:21:25 CST; 20s ago
 Main PID: 12720 (prometheus)
   CGroup: /system.slice/prometheus.service
           └─12720 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml

Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.586Z caller=head.go:606 level=info….149µs
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.586Z caller=head.go:612 level=info...ile"
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.586Z caller=head.go:683 level=info...nt=0
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.586Z caller=head.go:720 level=info….342µs
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.587Z caller=main.go:1014 level=inf...AGIC
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.587Z caller=main.go:1017 level=inf...ted"
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.587Z caller=main.go:1197 level=inf....yml
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.587Z caller=main.go:1234 level=info ms…µs
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.587Z caller=main.go:978 level=info...ts."
Nov 22 17:21:25 iZ8vb623n6mbyx9d66w0a9Z prometheus[12720]: ts=2022-11-22T09:21:25.588Z caller=manager.go:944 level=i......"
Hint: Some lines were ellipsized, use -l to show in full.

配置文件

默认配置文件
[root@devops ~]# cat /usr/local/prometheus/prometheus.yml
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 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"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

默认配置文件中定义了四个部分,分别是 global、alerting、rule_files 和 scrape_configs。
以下只是简单描述下,详情请查阅官方文档:https://prometheus.io/docs/prometheus/latest/configuration/configuration/

1、global

全局配置:

scrape_interval:抓取数据的时间间隔。 evaluation_interval: 评估规则的的频率,主要有两种记录规则和报警规则 • 记录规则:允许预先计算使用频繁且开销大的表达式,并将结果保存为一个新的时间序列数据。 • 报警规则:允许定义报警条件。

2、alerting

报警配置。preometheus 报警由 Alertmanager 的独立工具进行管理的,它是一个可以集群化的独立报警管理工具。

alertmanagers:这个块表示 Prometheus 服务器使用的 Alertmanager static_configs:这个块表示手动指定在 targets 数组中配置的 Alertmanager 地址

3、rule_files

规则文件配置。用来指定包含记录规则或者警报规则的文件列表。

4、scrape_configs

抓取配置。用来指定 Prometheus 抓取数据的目标。
Prometheus 将它抓取的指标数据源称为端点。为了抓取这些端点的数据,Prometheus 定义了一个目标,这个目标里包含的信息是抓取数据所必需的。比如用到的标签、建立连接的所需的的身份验证或者其它定义数据抓取的信息。若干目标构成的组称为作业,作业里每个目标都有一个名为实例(instance)的标签(默认),用来唯一标识这个目标。

job_name:作业名称 static_configs:这个块表示手动指定在 targets 数组中配置的目标地址和 labels 标签。

继续阅读
DevOps
  • 本文由 发表于 2022年11月22日 17:23:46
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
  • Prometheus
Prometheus监控kafka Prometheus

Prometheus监控kafka

前言 Kafka现有开源的集群监控方案:kafka-manager、kafka-monitor、kafka-eagle、KafkaOffsetMonitor,但有所限制监控指标被固化,不易扩展、预警...
Prometheus Prometheus

Prometheus

版本 CentOS Linux release 7.9 Prometheus:prometheus-2.52.0.linux-amd64 Alertmanager:alertma...
评论  0  访客  0

发表评论