zoukankan      html  css  js  c++  java
  • Prometheus配置文件(二)

     一、Prometheus主配置文件

    # cat prometheus.yml 
    # my global config
    global:                    # 全局配置
      scrape_interval:     15s # 设置抓取数据时间为15秒,默认为1分钟抓取一次
      evaluation_interval: 15s # 估算规则的时间为15秒,默认为1分钟
      # scrape_timeout is set to the global default (10s). 抓取超时时间默认为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:            # 抓取配置,prometheus的数据采集通过此片段配置
      # 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']

     二、使用scrape_configs定义采集目标

    配置一系列的目标,以及如何抓取它们的参数。一般情况下,每个scrape_config对应单个Job。目标可以在scrape_config中静态的配置,也可以使用某种服务发现机制动态发现。

    # 任务名称,自动作为抓取到的指标的一个标签
    job_name: <job_name>
     
    # 抓取周期
    [ scrape_interval: <duration> | default = <global_config.scrape_interval> ]
    # 每次抓取的超时
    [ scrape_timeout: <duration> | default = <global_config.scrape_timeout> ]
    # 从目标抓取指标的URL路径
    [ metrics_path: <path> | default = /metrics ]
    # 当添加标签发现指标已经有同名标签时,是否保留原有标签不覆盖
    [ honor_labels: <boolean> | default = false ]
    # 抓取协议
    [ scheme: <scheme> | default = http ]
    # HTTP请求参数
    params:
      [ <string>: [<string>, ...] ]
     
    # 身份验证信息
    basic_auth:
      [ username: <string> ]
      [ password: <secret> ]
      [ password_file: <string> ]
    # Authorization请求头取值 [ bearer_token:
    <secret> ]
    # 从文件读取Authorization请求头 [ bearer_token_file:
    /path/to/bearer/token/file ] # TLS配置 tls_config: [ <tls_config> ] # 代理配置 [ proxy_url: <string> ] # DNS服务发现配置 dns_sd_configs: [ - <dns_sd_config> ... ]
    # 文件服务发现配置 file_sd_configs: [
    - <file_sd_config> ... ]
    # K8S服务发现配置 kubernetes_sd_configs: [
    - <kubernetes_sd_config> ... ] # 此Job的静态配置的目标列表 static_configs: [ - <static_config> ... ] # 目标重打标签配置 relabel_configs: [ - <relabel_config> ... ]
    # 指标重打标签配置 metric_relabel_configs: [
    - <relabel_config> ... ] # 每次抓取允许的最大样本数量,如果在指标重打标签后,样本数量仍然超过限制,则整个抓取认为失败 # 0表示不限制 [ sample_limit: <int> | default = 0

    三、基于文件的服务发现

    Prometheus也提供了服务发现功能,可以从consul,dns,kubernetes,file等等多种来源发现新的目标。其中最简单的是从文件发现服务。

    支持服务发现的来源:

    azure_sd_configs
    consul_sd_configs
    dns_sd_configs
    ec2_sd_configs
    openstack_sd_configs
    file_sd_configs
    gce_sd_configs
    kubernetes_sd_configs
    marathon_sd_configs
    nerve_sd_configs
    serverset_sd_configs
    triton_sd_configs

    配置基于文件发现的服务:

    # vim prometheus.yml
    scrape_configs:
      - job_name: 'prometheus'
    
        static_configs:
        - targets: ['localhost:9090']
    
      - job_name: "node"
        file_sd_configs:
        - refresh_interval: 30s
          files: 
          - "/usr/local/prometheus/sd_config/node*.yml"
    
    # mkdir /usr/local/prometheus/sd_config

     五、relabel_configs 允许在采集之前对任何目标及其标签进行修改

    重新标签的意义:重命名标签、删除标签、过滤标签

  • 相关阅读:
    Servlet编程实例1
    Servlet
    JDBC之代码优化
    JDBC数据库编程
    数据库常识
    数据库基本操作
    STM32CUBEMX入门学习笔记3:HAL库以及STM32CUBE相关资料
    QT入门学习笔记2:QT例程
    爬虫制作入门学习笔记2:[转]python爬虫实例项目大全
    中移物联网onenet入门学习笔记2:中移物联的通信格式
  • 原文地址:https://www.cnblogs.com/cyleon/p/12821836.html
Copyright © 2011-2022 走看看