Eureka服务发现协议允许使用Eureka Rest API检索出Prometheus需要监控的targets,Prometheus会定时周期性的从Eureka调用Eureka Rest API,并将每个应用实例创建出一个target。
Eureka服务发现协议支持对如下元标签进行relabeling:
__meta_eureka_app_name: the name of the app__meta_eureka_app_instance_id: the ID of the app instance__meta_eureka_app_instance_hostname: the hostname of the instance__meta_eureka_app_instance_homepage_url: the homepage url of the app instance__meta_eureka_app_instance_statuspage_url: the status page url of the app instance__meta_eureka_app_instance_healthcheck_url: the health check url of the app instance__meta_eureka_app_instance_ip_addr: the IP address of the app instance__meta_eureka_app_instance_vip_address: the VIP address of the app instance__meta_eureka_app_instance_secure_vip_address: the secure VIP address of the app instance__meta_eureka_app_instance_status: the status of the app instance__meta_eureka_app_instance_port: the port of the app instance__meta_eureka_app_instance_port_enabled: the port enabled of the app instance__meta_eureka_app_instance_secure_port: the secure port address of the app instance__meta_eureka_app_instance_secure_port_enabled: the secure port of the app instance__meta_eureka_app_instance_country_id: the country ID of the app instance__meta_eureka_app_instance_metadata_: app instance metadata__meta_eureka_app_instance_datacenterinfo_name: the datacenter name of the app instance__meta_eureka_app_instance_datacenterinfo_: the datacenter metadataeureka_sd_configs常见配置如下:
(资料图片)
- job_name: "eureka" eureka_sd_configs: - server: http://localhost:8761/eureka #eureka server地址 refresh_interval: 1m #刷新间隔,默认30seureka_sd_configs官网支持主要配置如下:
server: basic_auth: [ username: ] [ password: ] [ password_file: ]# Configures the scrape request"s TLS settings.tls_config: [ ]# Optional proxy URL.[ proxy_url: ]# Configure whether HTTP requests follow HTTP 3xx redirects.[ follow_redirects: | default = true ]# Refresh interval to re-read the app instance list.[ refresh_interval: | default = 30s ] 基于Eureka服务发现协议核心逻辑都封装在discovery/eureka.go的func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error)方法中:
func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { // 通过Eureka REST API接口从eureka拉取元数据:http://ip:port/eureka/apps apps, err := fetchApps(ctx, d.server, d.client) if err != nil { return nil, err } tg := &targetgroup.Group{ Source: "eureka", } for _, app := range apps.Applications {//遍历app // targetsForApp()方法将app下每个instance部分转成target targets := targetsForApp(&app) //解析的采集点合入一起 tg.Targets = append(tg.Targets, targets...) } return []*targetgroup.Group{tg}, nil}refresh方法主要有两个流程:
1、fetchApps():从eureka-server的/eureka/apps接口拉取注册服务信息;
2、targetsForApp():遍历app下instance,将每个instance解析出一个target,并添加一堆元标签数据。
如下示例从eureka-server的/eureka/apps接口拉取的注册服务信息:
1 UP_1_ SERVICE-PROVIDER-01 localhost:service-provider-01:8001 192.168.3.121 SERVICE-PROVIDER-01 192.168.3.121 UP UNKNOWN 8001 443 1 MyOwn 30 90 1629385562130 1629385682050 0 1629385562132 8001 true 8080 http://192.168.3.121:8001/ http://192.168.3.121:8001/actuator/info http://192.168.3.121:8001/actuator/health service-provider-01 service-provider-01 false 1629385562132 1629385562039 ADDED instance信息会被解析成采集点target:
func targetsForApp(app *Application) []model.LabelSet { targets := make([]model.LabelSet, 0, len(app.Instances)) // Gather info about the app"s "instances". Each instance is considered a task. for _, t := range app.Instances { var targetAddress string // __address__取值方式:instance.hostname和port,没有port则默认port=80 if t.Port != nil { targetAddress = net.JoinHostPort(t.HostName, strconv.Itoa(t.Port.Port)) } else { targetAddress = net.JoinHostPort(t.HostName, "80") } target := model.LabelSet{ model.AddressLabel: lv(targetAddress), model.InstanceLabel: lv(t.InstanceID), appNameLabel: lv(app.Name), appInstanceHostNameLabel: lv(t.HostName), appInstanceHomePageURLLabel: lv(t.HomePageURL), appInstanceStatusPageURLLabel: lv(t.StatusPageURL), appInstanceHealthCheckURLLabel: lv(t.HealthCheckURL), appInstanceIPAddrLabel: lv(t.IPAddr), appInstanceVipAddressLabel: lv(t.VipAddress), appInstanceSecureVipAddressLabel: lv(t.SecureVipAddress), appInstanceStatusLabel: lv(t.Status), appInstanceCountryIDLabel: lv(strconv.Itoa(t.CountryID)), appInstanceIDLabel: lv(t.InstanceID), } if t.Port != nil { target[appInstancePortLabel] = lv(strconv.Itoa(t.Port.Port)) target[appInstancePortEnabledLabel] = lv(strconv.FormatBool(t.Port.Enabled)) } if t.SecurePort != nil { target[appInstanceSecurePortLabel] = lv(strconv.Itoa(t.SecurePort.Port)) target[appInstanceSecurePortEnabledLabel] = lv(strconv.FormatBool(t.SecurePort.Enabled)) } if t.DataCenterInfo != nil { target[appInstanceDataCenterInfoNameLabel] = lv(t.DataCenterInfo.Name) if t.DataCenterInfo.Metadata != nil { for _, m := range t.DataCenterInfo.Metadata.Items { ln := strutil.SanitizeLabelName(m.XMLName.Local) target[model.LabelName(appInstanceDataCenterInfoMetadataPrefix+ln)] = lv(m.Content) } } } if t.Metadata != nil { for _, m := range t.Metadata.Items { // prometheus label只支持[^a-zA-Z0-9_]字符,其它非法字符都会被替换成下划线_ ln := strutil.SanitizeLabelName(m.XMLName.Local) target[model.LabelName(appInstanceMetadataPrefix+ln)] = lv(m.Content) } } targets = append(targets, target) } return targets}解析比较简单,就不再分析,解析后的标签数据如下图:
标签中有两个特别说明下:
1、__address__:这个取值instance.hostname和port(默认80),所以要注意注册到eureka上的hostname准确性,不然可能无法抓取;
2、metadata-map数据会被转成__meta_eureka_app_instance_metadata_格式标签,prometheus进行relabeling一般操作metadata-map,可以自定义metric_path、抓取端口等;
3、prometheus的label只支持[a-zA-Z0-9_],其它非法字符都会被转换成下划线,具体参加:strutil.SanitizeLabelName(m.XMLName.Local);但是eureka的metadata-map标签含有下划线时,注册到eureka-server上变成双下划线,如下配置:
eureka: instance: metadata-map: scrape_enable: true scrape.port: 8080通过/eureka/apps获取如下:
基于Eureka服务发现原理如下图:
基于eureka_sd_configs服务发现协议配置创建Discoverer,并通过协程运行Discoverer.Run方法,Eureka服务发现核心逻辑封装discovery/eureka.go的func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error)方法中。
refresh方法中主要调用两个方法:
1、fetchApps:定时周期从Eureka Server的/eureka/apps接口拉取注册上来的服务元数据信息;
2、targetsForApp:解析上步骤拉取的元数据信息,遍历app下的instance,将每个instance解析成target,并将其它元数据信息转换成target元标签可以用于relabel_configs操作
Eureka服务发现协议允许使用EurekaRestAPI检索出Prometheus需要监控的targets,Prometheus会定时周期性的从Eurek
连台戏《雷雨》《雷雨·后》深圳见面会,跨越时代的剧作互文
连续3个赛季晋级四强的曼城队,将与近13个赛季11次晋级四强的皇马在半决赛遭遇。北京时间凌晨,本赛季欧冠
美国“枪支暴力档案”网站4月20日发布的数据显示,美国2023年已发生165起造成4人或以上伤亡的大规模枪击事件
中式台球超级大奖赛开杆
京东方A4月19日在投资者互动平台表示,2022年全球宏观环境异常严峻复杂,半导体显示市场整体消费信心不足,
甘泉县气象台继续发布大风蓝色预警【Ⅳ级 一般】
今天来聊聊关于小说中逃离女主下半身被塞酒瓶的段落是什么?的文章,现在就为大家来简单介绍下小说中逃离女
4月20日,记者从安徽银保监局获悉,安徽银保监局指导推动徽商银行积极探索创新举措,深化与安徽省工业互联
山东省淄博市临淄大院某烧烤店店主马丽娜:中午和晚上大概有一百桌,周末翻台基本要翻三遍。很多烧烤店都在
新华社北京4月20日电(记者赵文君)今年市场监管总局开展的民生领域案件查办“铁拳”行动将重点打击8类违法
广西钦州市委书记林冠逝世,享年56岁
在台湾民间信仰中,妈祖是最重要的神祇之一。每年从农历二月初开始至三月廿三日妈祖生日之后,台湾从南到北
2023年成考网上报名时间在几月份?满足什么条件可以参加成考?以下是小编为您整理的内容,希望对您有所帮助。2023年成考网上报名时间在几月份
自学考试报考有什么限制?报名自考有哪些意义?以下是小编为您整理的内容,希望对您有所帮助。自学考试报考有什么限制?自考生不受性别、年龄
4月20日电,佳力图公告,公司控股股东楷得投资拟通过集中竞价交易方式,减持不超过386 9万股(占公司总股本
自学考试2023年报名时间在什么时候?自考可以报名的专业有哪些?以下是小编为您整理的内容,希望对您有所帮助。自学考试2023年报名时间在什么
自考一年可以报名几次?自考报名流程有什么?以下是小编为您整理的内容,希望对您有所帮助。自考一年可以报名几次?自考一年大概有2-4次的报
浙江自考报名费是多少?自学考试可以报名哪些理工类专业?以下是小编为您整理的内容,希望对您有所帮助。浙江自考报名费是多少?浙江自考实践
自考大专报名步骤有哪些?自考报名后怎么备考?以下是小编为您整理的内容,希望对您有所帮助。自考大专报名步骤有哪些?1、自考生在规定时间
成人自考大专需要什么条件?自学考试2023年大专报名时间在什么时候?以下是小编为您整理的内容,希望对您有所帮助。成人自考大专需要什么条件
10月份浙江自考报名时间是什么时候?浙江自考报名流程是什么?以下是小编为您整理的内容,希望对您有所帮助。10月份浙江自考报名时间是什么时
挖贝网4月21日,美麟文化(831951)近日发布2022年度报告,报告期内公司实现营业收入11,205,919 41元,同比
浙江4月自考成绩查询时间是什么时候?浙江自考成绩多少分及格?以下是小编为您整理的内容,希望对您有所帮助。浙江4月自考成绩查询时间是什么
大专学历怎么自考报名?报考自学考试大专大概需要花多少钱?以下是小编为您整理的内容,希望对您有所帮助。大专学历怎么自考报名?报考自学考
哪些是见义勇为?要满足这些条件
网络教育统考考试时间是什么时候?远程教育报名流程是什么?以下是小编为您整理的内容,希望对您有所帮助。网络教育统考考试时间是什么时候?
网络教育报名时间是什么时候?哪些人适合报考网络教育?以下是小编为您整理的内容,希望对您有所帮助。网络教育报名时间是什么时候?网络教育
网络教育每年可以报考几次?网络教育是怎样报名的?以下是小编为您整理的内容,希望对您有所帮助。网络教育每年可以报考几次?网络教育报名一
2023年1月,浙江省宁波市教育科学研究所发布了“2022年度宁波教育科研十大关键词”候选名单,“啃读挑战推