• prometheus2.0 联邦的配置


    https://blog.51cto.com/lee90/2062252

    联邦有不同的用例。它通常用于实现可扩展的prometheus,或者将metrics从一个服务的prometheus拉到另一个Prometheus上用于展示。

     

    分层联邦:

    分层联邦允许普罗米修斯扩展到数十个数据中心和数百万个节点的环境。在这种用例中,联邦拓扑类似于一棵树,更高级别的普罗米修斯服务器从大量的从属服务器收集汇总的时间序列数据。

    跨服务联邦:

    In cross-service federation, a Prometheus server of one service is configured to scrape selected data from another service's Prometheus server to enable alerting and queries against both datasets within a single server.

    在跨服务联合中,一个服务的普罗米修斯服务器被配置为从另一个服务的普罗米修斯服务器中刮取选定的数据,以使得能够针对单个服务器内的两个数据集进行警报和查询。

    For example, a cluster scheduler running multiple services might expose resource usage information (like memory and CPU usage) about service instances running on the cluster. On the other hand, a service running on that cluster will only expose application-specific service metrics. Often, these two sets of metrics are scraped by separate Prometheus servers. Using federation, the Prometheus server containing service-level metrics may pull in the cluster resource usage metrics about its specific service from the cluster Prometheus, so that both sets of metrics can be used within that server.

    例如,运行多个服务的集群调度程序可能会暴露有关在集群上运行的服务实例的资源使用情况信息(如内存和CPU使用情况)。另一方面,在该群集上运行的服务将仅公开特定于应用程序的服务度量标准。通常,这两套指标是由单独的普罗米修斯服务器来抓取的。使用联邦,包含服务级别度量的普罗米修斯服务器可以从集群普罗米修斯拉入有关其特定服务的集群资源使用度量,以便这两组度量可以在该服务器内使用。

    【举个例子:我们要监控mysqld的运行状态,可以使用1个主Prometheus+2个分片Prometheus(一个用来采集node_exporter的metrics、一个用来采集mysql_exporter的metrics),然后在主Prometheus上做汇总】

    安装prometheus和mysqld_exporter、postgres_exporter的步骤也不写了,很简单的,exporter的部署我们通常用ansible或saltstack之类的工具批量分发。

    我这里实验起见,在一台机器上跑了3个shard节点,1个global节点。

    Node1: 10.0.20.25 (跑了老版本的prometheus1.7、mysql_exporter、postgres_exporter,这是之前做实验搭建的环境)

    Node2: 10.0.20.26 (跑了prometheus2.0、mysql_exporter、postgres_exporter)

    下面开始在Node2上开始我们的联邦的配置吧。

    注意: 我这里做实验的时候,跨服务联邦的配置还不太规范,照官方的说法是 采用多个独立的Prometheus节点分别采集node_exporter、mysql_exporter、postgres_exporter 这些metrics,然后再在GLOBAL节点做汇总。

     

    cd /usr/local/prometheus

    编写存放要采集主机的文件:

    cat mysqld.json 

    [
        {
            "targets": [
                "10.0.20.26:9104",
                "10.0.20.26:9100",
                "10.0.20.25:9104",
                "10.0.20.25:9100"
            ],
            "labels": {
                "services": "dba_test",
            }
        }
    ] 

    cat pgsql.json

    [
        {
            "targets": [
                "10.0.20.26:9187",
                "10.0.20.25:9187"
            ],
            "labels": {
                "services": "dba_test_pgsql",
            }
        }
    ]

    3个Shard节点配置文件如下:

     

    节点1,搜集的是mysql的信息

    cat prometheus1.yml

     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).
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    scrape_configs:
      - job_name: 'mysql'
        file_sd_configs:
          - files: ['./mysqld.json']

    节点2,搜集的是pgsql的信息

    cat prometheus2.yml

    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).
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    scrape_configs:
      - job_name: 'pgsql'
        file_sd_configs:
          - files: ['./pgsql.json']

    节点3,搜集的是prometheus节点的信息

    cat prometheus3.yml

    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).
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    scrape_configs:
      - job_name: 'prometheus25'
        static_configs:
          - targets: ['10.0.20.25:9090']
      - job_name: 'prometheus26'
        static_configs:
          - targets: ['10.0.20.26:9090']

    然后,启动3个分片节点:

    ./prometheus --web.listen-address="0.0.0.0:9091" --storage.tsdb.path="data1/" --config.file="prometheus1.yml" --web.enable-admin-api
    
    ./prometheus --web.listen-address="0.0.0.0:9092" --storage.tsdb.path="data2/" --config.file="prometheus2.yml" --web.enable-admin-api 
    
    ./prometheus --web.listen-address="0.0.0.0:9093" --storage.tsdb.path="data3/" --config.file="prometheus3.yml" --web.enable-admin-api

    再来配置GLOBAL节点:

    cat prometheus.yml 内容如下:

    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).
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    scrape_configs:
      - job_name: 'federate'
        scrape_interval: 15s
        honor_labels: true
        metrics_path: '/federate'
        params:
          'match[]':
            - '{job=~"prometheus.*"}'
            - '{job="mysql"}'
            - '{job="pgsql"}'
        static_configs:
          - targets:
            - '10.0.20.26:9091'
            - '10.0.20.26:9092'
            - '10.0.20.26:9093'

    启动GLOBAL节点:

    ./prometheus --web.listen-address="0.0.0.0:9090" --storage.tsdb.path="data_global/" --config.file="prometheus.yml" --web.enable-admin-api

    配好后,整个目录 如下图:

    image.png

    然后,在浏览器访问http://10.0.20.26:9090/targets  这个GLOBAL节点,效果如下图:

    image.png

    可以访问原先的3个shard节点,获取到对应的mysql、pgsql、prometheus的采集信息:

    http://10.0.20.26:9091/graph

    http://10.0.20.26:9092/graph

    http://10.0.20.26:9093/graph

    我们可以自测下,在http://10.0.20.26:9090/graph 这里可以采集到后端3个shard节点的全部数据的。

    这样,我们就配好了prometheus的联邦啦。是不是很简单??

    注意: 有些时候 ,我们要求告警信息实时性特别高,这种情况下,告警的采集(以granfana为例)不建议使用连接到联邦GLOBAL节点的方式,建议直连后端对应的Shard节点,以免因为GLOBAL采集数据延迟,而导致发送告警的延迟情况出现。

    结合grafana:

    然后,可以在grafana里面做展示了,直接上图:

    image.png

    这里填instance 的时候,我用了个通配符,一次性列出符合条件的全部主机,但是唯一的缺点是,这样就不能用grafana自带的告警啦,因为目前grafana的告警还不支持动态写法,除非我们写死了node_load5{instance=~'10.0.20.26:9100'} 这样才行。

    image.png

    image.png

    下面是我配好的部分截图:

    image.png

  • 相关阅读:
    failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected 排坑指南
    使用labelme制作自己的数据集
    linux安装anaconda3 conda: command not found
    windows端运行.sh脚本
    安装easydict
    tensorflow安装排坑笔记
    Dev怎么调试,怎么调试不了???
    NameError: name 'QApplication' is not defined 的解决办法
    绝对路径和相对路径
    关于Pycharm总是Indexing很久的问题
  • 原文地址:https://www.cnblogs.com/momoyan/p/11027498.html
Copyright © 2020-2023  润新知