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
中新网甘肃新闻4月21日电为庆祝第14个“联合国中文日”,近日,兰州资源环境职业技术大学举办“中文+职...
快科技4月21日消息,昨晚vivo正式发布旗下第二款平板电脑vivoPad2,售价2399元起,实现两大行业首发:UI自
要说哪个更好吃的话,当然是油丝瓜更好吃。首先,油丝瓜的口感是细腻光滑的,很嫩很嫩。炒这种丝瓜的时候更
从地图上回忆:回忆一下自己大概是在哪里办理的银行卡,打开地图,根据大概位置查到附近是否有相关对应的银
多区道路施工驾车注意减速慢行
不仅仅是礼盒、配色上的联名设计,一加Ace2在手机UI主题方面也进行了深度定制,从手机壁纸到游戏助手界面、
12日,市东泰物业管理有限公司花园分公司王女士来到市水务集团掇刀营业厅,工作人员询问办理什么业务,王女
国新办20日举行一季度农业农村经济运行情况新闻发布会,农业农村部相关负责人表示,今年将通过扩大豆、扩油
今天来聊聊关于学生社会实践记录表高中,学生社会实践记录表的文章,现在就为大家来简单介绍下学生社会实践
石景山区卫健委加强医疗卫生机构安全检查
4月4日,安徽财经大学与紫光股份旗下新华三集团签订战略合作协议并举办授牌仪式。安徽财经大学校党委副书记
4月20日消息,在今天中午前后发生了一次日全环食(混合食)。专家指出,日全环食非常罕见,以21世纪为例,
坚持通过创新研发走在行业最前沿,就能在激烈的市场竞争中站稳脚跟、勇立潮头打火机虽小,却能占领全球大市
郑渊洁称21年维权生活像吃苍蝇今天的热度非常高,现在也是在热搜榜上了,那么具体的郑渊洁称21年维权生活像
碗窑村的陶艺“蝶变”
安徽宿州杂技演员坠亡事件追踪
4月21日,生意社涤纶FDY基准价为8446 00元 吨,与本月初(8394 00元 吨)相比,上涨了0 62%。涤纶FDY年度统计(2022-04-21--
里夫斯:灰熊今天比我们更拼但无论对手是谁我们都有机会赢,湖人,里夫斯,美国篮球,孟菲斯灰熊队,nba季后赛,
每经AI快讯,东信和平(SZ002017,收盘价:15 41元)4月20日晚间发布一季度业绩公告称,2023年第一季度
亚汇网获悉,周四,ATaT(T U)股价走低,截至发稿,该股跌超8%,报18 005美元。此前公布的财报显示,ATaT第
1、香蕉水又名天那水,主要成分是二甲苯,挥发性极强易燃易爆有毒,是危险品,主要是因为有较浓的香蕉气味
泰康保险拟向泰康养老增资10亿元,直接持股比例增至99%,持股,泰康保险,保险集团,泰康养老
日前,据央视网报道,教育部印发《关于推开教职员工准入查询工作的通知》,要求依法推开准入查询制度,严格
据湖北省纪委监委消息:日前,经湖北省委批准,湖北省纪委监委对湖北长江出版传媒集团有限公司、长江出版传
看欧冠切尔西打皇马坎特的表现后,我们发现他更适合在防守型的位置,但球队却让他扮演前锋的角色,这让他有
这一国首都,突发踩踏事件→来源:央视财经(ID:cctvyscj)监制:柯成韵记者:王惠卿本文编辑:龚新语持续
遂宁市医疗保障局致全市公立医疗机构的一封信全市各公立医疗机构:一直以来,全市各级公立口腔医疗机构作为
【所有人给我站一边因为超人强我要出现是什么梗】今天的关注度非常高,直接上了热搜榜,那么具体的是什么情
广期所发〔2023〕87号各会员单位:根据《关于2023年部分节假日放假和休市安排的通知》(广期所发〔2022〕25
Copyright @ 2015-2018 现在it网版权所有 备案号:粤ICP备18023326号-5 联系邮箱:855 729 8@qq.com