记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。
 
0

Prometheus基于文件的服务发现


一,prometheus的服务发现简介。

服务发现支持: endpoints,ingress,kubernetes,node,pod,service。
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

二、具体过程。

    1,环境介绍:

      1),IP: 192.168.1.20,docker主机安装prometheus,node-exporter.

       2),IP: 192.168.1.41

     2,prometheus安装说明,docker容器的具体安装命令不再说了,比较简单,我这里修改了端口,其它的不变

具体可以看下图。





3,prometheus容器中的/etc/prometheus/prometheus.yml配置文件,具体内容如下:

         编写配置文件:vim prometheus.yml


# my global config
global:
  scrape_interval: 15s
  evaluation_interval: 15s
  # scrape_timeout is set to the global default (10s).


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


rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
  #- "/etc/prometheus/rules/*.rules"
scrape_configs:
  - job_name: "prometheus"					#prometheus容器的监控
    static_configs:
      - targets: ["192.168.1.20:9099"]
        labels:
          instance: prometheus
          service: prometheus-service


  - job_name: "nodes"							#node节点通过node-exporter监控
    file_sd_configs:
      - files: ["/etc/prometheus/targets/node*.yaml"]	#文件服务发现的配置文件路径
        refresh_interval: 2m						#2分钟刷新一次配置文件

    4、不存的相关目录,需要创建,然后把prometheus.yml配置文件上传到相关的docker挂载目录中。


ansible 192.168.1.20 -m copy -a 'src=/home/Administrator/prometheus.yml dest=/opt/prometheus/config/prometheus.yml'


  5,添加相关节点的配置文件。

我这里添加了两个配置文件,内容如下。


6,上传相关配置文件到prometheus的挂载目录。

ansible 192.168.1.20 -m copy -a 'src=/home/Administrator/prometheus/node-41.yaml dest=/opt/prometheus/targets/node-41.yaml'

ansible 192.168.1.20 -m copy -a 'src=/home/Administrator/prometheus/node-docker.yaml dest=/opt/prometheus/targets/node-docker.yaml'


7,最后检查相关监控节点metrics信息。






转载请标明出处【Prometheus基于文件的服务发现】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论