一、Prometheus支持的多种服务发现机制(常用如下)

  1. static_configs: 静态服务发现
  2. file_sd_configs: 文件服务发现
  3. dns_sd_configs: DNS 服务发现
  4. kubernetes_sd_configs: Kubernetes 服务发现
  5. consul_sd_configs: Consul 服务发现

二、Prometheus主要配置prometheus.yml中的scrape_configs以及consul_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: 'consul'
consul_sd_configs:
- server: 'localhost:8500'
relabel_configs:
- source_labels: [__meta_consul_tags]
regex: .*,prome,.*
action: keep
- source_labels: [__meta_consul_service]
target_label: job

通过重新加载prometheus.yml配置添加

./prometheus --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9090" --web.enable-admin-api --web.enable-lifecycle &

--web.enable-admin-api 运行通过web方式管理prometheus(删除清空数据等操作)
--web.enable-lifecycle 运行通过web方式重新加载prometheus配置(相当于reload)

三、k8s环境实现

将配置制作成secret挂在到prometheus中

1、编写prometheus-additional-consul.yaml

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: 'consul'
consul_sd_configs:
- server: 'localhost:8500'
relabel_configs:
- source_labels: [__meta_consul_tags]
regex: .*,prome,.*
action: keep
- source_labels: [__meta_consul_service]
target_label: job

2、制作secret

kubectl create secret generic additional-consul-configs --from-file=prometheus-additional-consul.yaml -n monitoring

3、添加配置到prometheus的pod中,修改prometheus-prometheus.yaml,并更新资源

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
labels:
prometheus: k8s
name: k8s
namespace: monitoring
spec:
alerting:
alertmanagers:
- name: alertmanager-main
namespace: monitoring
port: web
baseImage: quay.io/prometheus/prometheus
nodeSelector:
kubernetes.io/os: linux
podMonitorNamespaceSelector: {}
podMonitorSelector: {}
replicas:
resources:
requests:
memory: 400Mi
ruleSelector:
matchLabels:
prometheus: k8s
role: alert-rules
securityContext:
fsGroup:
runAsNonRoot: true
runAsUser:
serviceAccountName: prometheus-k8s
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector: {}
version: v2.11.0
additionalScrapeConfigs:
name: additional-consul-configs
key: prometheus-additional-consul.yaml

4、注意事项:权限不够(配置更新,但是没有对应的监控任务生成)

修改名为prometheus-k8s的ClusterRole权限,并更新资源

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: prometheus-k8s
rules:
- apiGroups:
- ""
resources:
- nodes
- services
- endpoints
- pods
- nodes/proxy
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- configmaps
- nodes/metrics
verbs:
- get
- nonResourceURLs:
- /metrics
verbs:
- get

Prometheus + Consul 自动发现服务监控的更多相关文章

  1. Prometheus基于consul自动发现监控对象 https://www.iloxp.com/archive/11/

      Prometheus 监控目标为什么要自动发现 频繁对Prometheus配置文件进行修改,无疑给运维人员带来很大的负担,还有可能直接变成一个“配置小王子”,即使是配置小王子也会存在人为失误的情况 ...

  2. Prometheus Operator 自动发现和持久化

    Prometheus Operator 自动发现和持久化 之前在 Prometheus Operator 下面自定义一个监控选项,以及自定义报警规则的使用.那么我们还能够直接使用前面课程中的自动发现功 ...

  3. zabbix主机自动发现和监控

    在主机较多的时候,配置主机自动发现并加入监控可以代替手动的添加主机,减轻工作量,自动发现由服务端主动发起,Zabbix Server开启发现进程,定时扫描局域网中IP服务器.设备.可以根据需要,在对主 ...

  4. Zabbix自动发现并监控磁盘IO、报警

    本文转载自: https://www.93bok.com 引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务 ...

  5. Zabbix整合MegaCLI实现物理硬盘的自动发现和监控

    MegaCLI是LSI提供的用户空间管理RAID卡(LSI芯片)工具,适用于大多数的Dell服务器. MegaCLI介绍: http://zh.community.dell.com/techcente ...

  6. 添加zabbix自动发现(监控多tomcat实例)

    说明 何为自动发现?首先我们监控多tomcat实例,如果一个个实例地添加或许可以完成当前需求.但是日后随着实例的增多,再手动一个个去添加就十分不方便了.这时候需要自动发现这个功能,来帮助我们自动添加监 ...

  7. zabbix_agent自动发现服务端口

    应用背景:       zabbix监控系统介绍及安装,参考大牛运维生存时间,在这儿就不啰嗦了 为了zabbix-agent端能自动把服务器端的服务端口汇报给 zabbix server端,监控其端口 ...

  8. Zabbix 自动发现并监控磁盘IO、报警 引言

    引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务集群达到几十那就非常麻烦,因此需要利用自动发现这个功能,自 ...

  9. 使用Prometheus搞定微服务监控

    最近对服务进行监控,而当前监控最流行的数据库就是 Prometheus,同时 go-zero 默认接入也是这款数据库.今天就对 go-zero 是如何接入 Prometheus ,以及开发者如何自己定 ...

随机推荐

  1. C#反射_两合并更新实体

    #region 更新实体模型 /// <summary> /// 更新实体模型 /// </summary> /// <typeparam name="T&qu ...

  2. 阿里云Centos7用putty ssh链接掉线

    解决方法:修改云服务器 ssh 配置文件(修改前一定要先备份) (1)打开配置文件: vim /etc/ssh/sshd_config 1 (2)找到下面两行: ClientAliveInterval ...

  3. Salesforce LWC学习(一)Salesforce DX配置

    LWC: Create a Salesforce DX Project and Lightning Web Component:https://www.youtube.com/watch?v=p268 ...

  4. Python基础13

    <玩1>中关于病假.事假的问题,说得不完全正确. 实际为哑变量. 有关看待问题的维度.出发点(即屁股在哪里) 转哑变量后可以提高模型精度. 机器学习不怕字段过多. 转哑变量是在增维.

  5. css层叠规则(层叠样式表)

    CSS层叠规则: 1.找出所有相关的规则,这些规则都包含与一个给定元素匹配的选择器. 2.按权重(!important)和来源对应用到给定元素的所有声明进行排序. 3.按特殊性对应用到给定元素的所有声 ...

  6. JavaScript 总结[目录]

    ECMAScript 基础 一.JavaScript 基础 1.1 JavaScript 简介 1.2 JavaScript 书写位置 二.JavaScript 数据类型 2.1 JavaScript ...

  7. 移动4G插卡注网

    本文根据插入移动4G单卡到注册4G网络过程的mtklog分析. 插卡动作: 从以上信息无法区分单卡还是双卡,通过ATR参数判断: 注网流程,此过程未开启4G数据连接: [MS->NW] ESM_ ...

  8. Nginx 核心配置-可优化配置参数

    Nginx 核心配置-可优化配置参数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.nginx的官网查看指令帮助信息方法 1>.打开nginx的官网(https://ng ...

  9. 201871010110-李华《面向对象程序设计(java)》第6-7周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  10. woocommerce直接调取产品描述内容

    最近一位客户想让woocommerce产品页直接调取描述内容,不想太多的tab切换,太复杂,这个蛮简单的,woocommerce是在wordpress基础开发的,产品也是post的一种类型,直接调用c ...