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操作
标签:
【云原生 • Prometheus】Prometheus 注册中心Eureka服务发现原理
Eureka服务发现协议允许使用EurekaRestAPI检索出Prometheus需要监控的targets,Prometheus会定时周期性的从Eurek
【热闻】新加坡旅游局与微信支付签订 3 年战略合作
感谢亚汇网网友航空先生、亚汇网从微信公开课RO获取到,微信的跨境支付业务已覆盖全世界69个国家和地区,境外合作机构总计超过1000家,已连接
商务部:一季度我国在线销售旅游产品、景点门票同比增长115.8%
【商务部:一季度我国在线销售旅游产品、景点门票同比增长115 8%】商务部4月21日发布的数据显示,一季度,我国在线销售的旅游产品和景点门票、
凯盛科技:4月21日融资买入2310.11万元,融资融券余额5.44亿元
4月21日,凯盛科技(600552)融资买入2310 11万元,融资偿还1803 31万元,融资净买入506 8万元,融资余额5 41亿元。
视焦点讯!肋软骨隆鼻到底好不好_肋软骨隆鼻是终身的吗 肋软骨隆鼻是不是终身的
1、肋软骨隆鼻是目前最流行的外科隆鼻方法,适用于鼻短严重、多次隆鼻失败、人工材料排斥的求美者。2、临床上只有没有钙化的肋
天天速读:2023上海车展大嘴余承东去了哪里?
他就是华为常务董事智能汽车解决方案的CEO余承东,因为本次车展他也参加了。当然,2023上海车展,华为也有参加。因为在华为问界新车的发布会上
光伏电池龙头重磅投资!拟360亿新建生产基地,与这一市签下合作协议
在2022年报中,爱旭股份(600732)...
当前速递!隔夜外盘:美股三大指数小幅收涨 热门中概股多数走低
证券时报e公司讯,美股三大指数小...
新加坡铁矿石指数期货大跌7%,真实原因是……
本周铁矿石期货价格大幅下挫,截至...
欣旺达成为全球电池联盟(GBA)新成员
证券时报e公司讯,4月19日,全球电...
超乎想象!4个月"暴赚"14600亿,这10人"手握"印钞机!他"包"下全球首富
奢侈品巨头老板成全球首富!2023年...
美国不必在债务上限问题上犯险
熊德志美国众议院计划在下周(4月2...
全球热门:金徽酒首季净利增一成 今年营收目标25亿
证券时报记者曹晨4月21日晚间,金徽...
中央决定:他任中国人保一把手!总裁出现空缺
中国人保“一把手”空缺2个多月后...
环球快报:一季度国内旅游总人次同比增长46.5%
证券时报网讯,据新华社,文化和旅...
【世界新要闻】中融基金75.5%股权变更获证监会批准通过
证券时报券中社讯,4月21日国联证...
世界速看:越南大学生踊跃体验中国文化
“在我看来,中文是一门优雅的语言...
天天速看:爱旭股份:拟360亿元投建太阳能电池及其配套组件项目
证券时报e公司讯,爱旭股份(600732...
【环球新要闻】传闻成真!天合光能筹划控股子公司天合智慧分拆上市
天合光能(688599)分拆分布式光伏业...
中达安中标医院智慧工程项目管理平台系统采购项目
证券时报e公司讯,中达安消息,近...
环球速读:不止于带货 业内探讨直播电商如何更好助推消费、赋能国货
近日,一场围绕直播电商如何助力消...
天天观察:各地花样“焕新”消费 消费市场实现一季度“开门红”
海报新闻记者孙杰报道一季度以来,...
全球今头条!从七旬姐妹到少先队员,烟台人喜迎“烟台舰”回家
记者于洋我的家乡,我的烟台舰,70...
简述麦格雷戈的y理论的思想基础 简答题 -10 分-简述麦格雷戈的y理论的思想基础
1、麦格雷戈称之为“Y理论”的人性...
快资讯:中国黄金:一季度归母净利润3亿元,同比增19.13%
中国黄金4月21日公告,一季度公司...