在prometheus监控系统,prometheus的职责是采集,查询和存储和推送报警到alertmanager。本文主要介绍下prometheus的配置文件。

全局配置文件简介

默认配置文件

[root@node00 prometheus]# cat prometheus.yml.default
# 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: 此片段指定的是prometheus的全局配置, 比如采集间隔,抓取超时时间等。
  • rule_files: 此片段指定报警规则文件, prometheus根据这些规则信息,会推送报警信息到alertmanager中。
  • scrape_configs: 此片段指定抓取配置,prometheus的数据采集通过此片段配置。
  • alerting: 此片段指定报警配置, 这里主要是指定prometheus将报警规则推送到指定的alertmanager实例地址。
  • remote_write: 指定后端的存储的写入api地址。
  • remote_read: 指定后端的存储的读取api地址。

global片段主要参数

  # How frequently to scrape targets by default.
[ scrape_interval: <duration> | default = 1m ] # 抓取间隔 # How long until a scrape request times out.
[ scrape_timeout: <duration> | default = 10s ] # 抓取超时时间 # How frequently to evaluate rules.
[ evaluation_interval: <duration> | default = 1m ] # 评估规则间隔 # The labels to add to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels: # 外部一些标签设置
[ <labelname>: <labelvalue> ... ]

scrapy_config片段主要参数

一个scrape_config 片段指定一组目标和参数, 目标就是实例,指定采集的端点, 参数描述如何采集这些实例, 主要参数如下

  • scrape_interval: 抓取间隔,默认继承global值。
  • scrape_timeout: 抓取超时时间,默认继承global值。
  • metric_path: 抓取路径, 默认是/metrics
  • scheme: 指定采集使用的协议,http或者https。
  • params: 指定url参数。
  • basic_auth: 指定认证信息。
  • *_sd_configs: 指定服务发现配置
  • static_configs: 静态指定服务job。
  • relabel_config: relabel设置。

static_configs样例

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']
- job_name: "node"
static_configs:
- targets:
- "192.168.100.10:20001"
- "192.168.100.11:20001
- "192.168.100.12:20001"

file_sd_configs样例

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']
- job_name: "node"
file_sd_configs:
- refresh_interval: 1m
files:
- "/usr/local/prometheus/prometheus/conf/node*.yml" # 独立文件配置如下
cat conf/node-dis.conf
- targets:
- "192.168.100.10:20001"
- "192.168.100.11:20001"
- "192.168.100.12:20001" 或者可以这样配置
[root@node00 conf]# cat node-dis.yml
- targets:
- "192.168.100.10:20001"
labels:
hostname: node00
- targets:
- "192.168.100.11:20001"
labels:
hostname: node01
- targets:
- "192.168.100.12:20001"
labels:
hostname: node02

通过file_fd_files 配置后我们可以在不重启prometheus的前提下, 修改对应的采集文件(node_dis.yml), 在特定的时间内(refresh_interval),prometheus会完成配置信息的载入工作。

consul_sd_file样例

由于consul的配置需要有consul的服务提供, 这里简单部署下consul的服务。

# 进入下载目录
[root@node00 prometheus]# cd /usr/src/
# 下载
[root@node00 src]# wget https://releases.hashicorp.com/consul/1.6.1/consul_1.6.1_linux_amd64.zip
# 解压
[root@node00 src]# unzip consul_1..1_linux_amd64.zip
Archive: consul_1..1_linux_amd64.zip
inflating: consul
# 查看
[root@node00 src]# ls
consul consul_1..1_linux_amd64.zip debug kernels node_exporter-0.18..linux-amd64.tar.gz prometheus-2.12..linux-amd64.tar.gz
# 查看文件类型
[root@node00 src]# file consul
consul: ELF -bit LSB executable, x86-, version (SYSV), statically linked, not stripped
# 防止到系统bin目录
[root@node00 src]# mv consul /usr/local/bin/
# 确保环境变量包含
[root@node00 src]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

# 运行测试
[root@node00 consul.d]# consul agent -dev
# 测试获取成员
[root@node00 ~]# consul members
# 创建配置目录
[root@node00 ~]#mkdir /etc/consul.d
[root@node00 consul.d]# cat prometheus-node.json
{
  "addresses": {
                        "http": "0.0.0.0",
                        "https": "0.0.0.0"
           },
  "services": [{
                "name": "prometheus-node",
                "tags": ["prometheus","node"],
                "port": 20001
             }]
 
}
# 指定配置文件运行
consul  agent -dev -config-dir=/etc/consul.d

打开web管理界面 192.169.100.10:8500,查看相应的服务信息。

上面我们可以看到有2个service , 其中prometheus-node是我们定义的service。

和prometheus集成样例:

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']   - job_name: "node"
    consul_sd_configs:
    - server: localhost:8500
      services:
      - prometheus-node
    #  tags:
    #  - prometheus
    #  - node
    #- refresh_interval: 1m

在prometheus的target界面上我们看到服务注册发现的结果。

我们通过api接口给该service添加一个节点, 看看是否可以同步过来。

[root@node00 ~]# curl -XPUT -d@node01.json  127.0.0.1:8500/v1/catalog/register
true
[root@node00 ~]# cat node01.json
{
        "id":"0cc931ea-9a3a-a6ff-3ef5-e0c99371d77d",
        "Node": "node01",
        "Address": "192.168.100.11",
        "Service":
                {
                        "Port": 20001,
                        "ID": "prometheus-node",
                        "Service": "prometheus-node"
                }
}

在consul和prometheus中查看

可以发现通过向consul中特定服务加入节点, 就可以在prometheus动态变动采集的实例地址。

prometheus学习系列五: Prometheus配置文件的更多相关文章

  1. scrapy爬虫学习系列五:图片的抓取和下载

    系列文章列表: scrapy爬虫学习系列一:scrapy爬虫环境的准备:      http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_python_00 ...

  2. Prometheus学习系列(五)之Prometheus 规则(rule)、模板配置说明

    前言 本文来自Prometheus官网手册1.2.3.4和 Prometheus简介1.2.3.4 记录规则 一.配置规则 Prometheus支持两种类型的规则,这些规则可以定期配置,然后定期评估: ...

  3. Prometheus学习系列(六)之Prometheus 查询说明

    前言 本文来自Prometheus官网手册和 Prometheus简介 Prothetheus查询 Prometheus提供一个函数式的表达式语言PromQL (Prometheus Query La ...

  4. Prometheus学习系列(二)之Prometheus FIRST STEPS

    前言 本文来自Prometheus官网手册 和 Prometheus简介 说明 Prometheus是一个监控平台,通过在监控目标上的HTTP端点来收集受监控目标的指标.本指南将向您展示如何使用Pro ...

  5. Prometheus学习系列(九)之Prometheus 联盟、迁移

    前言 本文来自Prometheus官网手册 和 Prometheus简介 FEDERATION 允许Prometheus服务器从另一台Prometheus服务器抓取选定的时间序列. 一,用例 联盟有不 ...

  6. prometheus学习系列九: Prometheus AlertManager使用

    在Prometheus的报警系统中,是分为2个部分的, 规则是配置是在prometheus中的, prometheus组件完成报警推送给alertmanager的, alertmanager然后管理这 ...

  7. prometheus学习系列三:node_exporter安装部署

    node_exporter简介 node_exporter安装部署 [root@node00 ~]# cd /usr/src/ [root@node00 src]# wget https://gith ...

  8. prometheus学习系列二: Prometheus安装

    下载 在prometheus的官网的download页面,可以找到prometheus的下载二进制包. [root@node00 src]# cd /usr/src/ [root@node00 src ...

  9. Prometheus学习系列(一)之Prometheus简介

    前言 本文来自Prometheus官网手册 和 Prometheus简介 什么是prometheus? Prometheus是一个最初在SoundCloud上构建的开源系统监视和警报工具包.自2012 ...

随机推荐

  1. 洛谷P1531 I Hate It题解

    题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...

  2. 近年NOI题目总结

    NOI2015D1T1 题目大意:$T$ 组数据.在一个程序中有无数个变量 $x_i$.现在有 $n$ 条限制,形如 $x_i=x_j$ 或者 $x_i\ne x_j$.(对于每个限制 $i,j$ 给 ...

  3. Scopus数据库简介

    ScienceDirect数据库1. Elsevier简介荷兰Elsevier 是全球最大的科学文献出版发行商,已有180多年的历史.其产品涵盖科学.技术和医学等各个领域,包括1800多种学术期刊(大 ...

  4. cad.net 依照旧样条曲线数据生成一条新样条曲线的代码段. spline生成

    Spline spl = entity as Spline; //拿到旧的spline图元... //样条曲线生成条件 var controlPoints = new Point3dCollectio ...

  5. python数据分析5 数据转换

    1数据转换 数据转换时数据准备的重要环节,它通过数据平滑,数据聚集,数据概化,规范化等凡是将数据转换成适用于数据挖掘的形式 1.1 数据平滑 去除数据中的噪声,将连续数据离散化.这里可以采用分箱.聚类 ...

  6. 【C++】const,static和static const类型成员变量声明及其初始化

    1)const定义的常量在超出其作用域之后其空间会被释放,而static定义的静态常量在函数执行后不会释放其存储空间 void f1() { ; cout<<x<<endl; ...

  7. 命令(Command)模式

    命令模式又称为行动(Action)模式或者交易(Transaction)模式. 命令模式把一个请求或者操作封装到一个对象中.命令模式允许系统使用不同的请求把客户端参数化,对请求排队或者记录请求日志,可 ...

  8. php redis扩展安装步骤

    因为redis不是php技术自带的技术,因此我们如果要通过php程序来操作redis,需要redis设计者提供对应的操作接口(函数类)我们使用phpredis.tar.gz文件在源码编译生成一个red ...

  9. 「雅礼集训 2017 Day1」字符串 SAM、根号分治

    LOJ 注意到\(qk \leq 10^5\),我们很不自然地考虑根号分治: 当\(k > \sqrt{10^5}\),此时\(q\)比较小,与\(qm\)相关的算法比较适合.对串\(s\)建S ...

  10. MQTTv5.0 ---AUTH – 认证交换

    AUTH报文被从客户端发送给服务端,或从服务端发送给客户端,作为扩展认证交换的一部分,比如质询/ 响应认证.如果CONNECT报文不包含相同的认证方法,则客户端或服务端发送AUTH报文将造成协议错 误 ...