Prometheus + Consul 自动发现服务监控
一、Prometheus支持的多种服务发现机制(常用如下)
- static_configs: 静态服务发现
- file_sd_configs: 文件服务发现
- dns_sd_configs: DNS 服务发现
- kubernetes_sd_configs: Kubernetes 服务发现
- 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 自动发现服务监控的更多相关文章
- Prometheus基于consul自动发现监控对象 https://www.iloxp.com/archive/11/
Prometheus 监控目标为什么要自动发现 频繁对Prometheus配置文件进行修改,无疑给运维人员带来很大的负担,还有可能直接变成一个“配置小王子”,即使是配置小王子也会存在人为失误的情况 ...
- Prometheus Operator 自动发现和持久化
Prometheus Operator 自动发现和持久化 之前在 Prometheus Operator 下面自定义一个监控选项,以及自定义报警规则的使用.那么我们还能够直接使用前面课程中的自动发现功 ...
- zabbix主机自动发现和监控
在主机较多的时候,配置主机自动发现并加入监控可以代替手动的添加主机,减轻工作量,自动发现由服务端主动发起,Zabbix Server开启发现进程,定时扫描局域网中IP服务器.设备.可以根据需要,在对主 ...
- Zabbix自动发现并监控磁盘IO、报警
本文转载自: https://www.93bok.com 引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务 ...
- Zabbix整合MegaCLI实现物理硬盘的自动发现和监控
MegaCLI是LSI提供的用户空间管理RAID卡(LSI芯片)工具,适用于大多数的Dell服务器. MegaCLI介绍: http://zh.community.dell.com/techcente ...
- 添加zabbix自动发现(监控多tomcat实例)
说明 何为自动发现?首先我们监控多tomcat实例,如果一个个实例地添加或许可以完成当前需求.但是日后随着实例的增多,再手动一个个去添加就十分不方便了.这时候需要自动发现这个功能,来帮助我们自动添加监 ...
- zabbix_agent自动发现服务端口
应用背景: zabbix监控系统介绍及安装,参考大牛运维生存时间,在这儿就不啰嗦了 为了zabbix-agent端能自动把服务器端的服务端口汇报给 zabbix server端,监控其端口 ...
- Zabbix 自动发现并监控磁盘IO、报警 引言
引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务集群达到几十那就非常麻烦,因此需要利用自动发现这个功能,自 ...
- 使用Prometheus搞定微服务监控
最近对服务进行监控,而当前监控最流行的数据库就是 Prometheus,同时 go-zero 默认接入也是这款数据库.今天就对 go-zero 是如何接入 Prometheus ,以及开发者如何自己定 ...
随机推荐
- Sql 分页语句
select * from (select *,ROW_NUMBER()over(order by [ID]) as rowindex from product ) tb where rowinde ...
- C#给企业微信中的成员发送消息
先去企业微信门户网站获得密钥和应用ID 创建一个静态工具类 using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using ...
- moodle3.7上传中文文件,无法引用,图片不显示
初始安装moodle3.7 上传图片,名称为中文时,无法引用图片,图片不显示.这里采用修改moodle根目录下的config.php文件, 添加了变量$CFG->slasharguments = ...
- js计算数组中元素出现的次数,并实现去重
function getCount(arr, rank,ranktype){ var obj = {}, k, arr1 = []; for (var i = 0, len = arr.length; ...
- Android源码分析(十四)----如何使用SharedPreferencce保存数据
一:SharedPreference如何使用 此文章只是提供一种数据保存的方式, 具体使用场景请根据需求情况自行调整. EditText添加saveData点击事件, 保存数据. diff --git ...
- 0,'0','\0',NULL的区别
0,'0','\0',NULL的区别 1,0是一个值,可以是char ,int ,float,double等类型: 2,'0'是一个字符(char)类型,它的ASCII码值是48: 3,'\0'也是一 ...
- 【软件工程第二次作业】个人项目:WordCountPy
一.GitHub 地址 项目 GitHub 地址为:https://github.com/bytemo/WordCountTool 二.PSP表格 PSP2.1 Personal Software P ...
- Spark GraphX图计算核心源码分析【图构建器、顶点、边】
一.图构建器 GraphX提供了几种从RDD或磁盘上的顶点和边的集合构建图形的方法.默认情况下,没有图构建器会重新划分图的边:相反,边保留在默认分区中.Graph.groupEdges要求对图进行重新 ...
- Django框架(十一)-- 补充:inclusion_tag、defer、only、choice、事务、创建多对多的第三张表、mvc和mtv模式
一.inclusion_tag 1.作用 用于生成HTML片段,是数据由参数传入而变成动态 2.使用 # 1.app下新建一个模块,templatetags # 2.创建一个py文件(mytag.py ...
- 面向对象(五)--isinstance与issubclass方法、反射、内置方法(部分)、异常处理
一.isinstance与issubclass方法 1.isinstance是用来判断对象是否是某个类 isinstance(obj,class) 2.issubclass是用来判断一个类是否为另一个 ...