Eureka服务发现协议允许使用EurekaRestAPI检索出Prometheus需要监控的targets,Prometheus会定时周期性的从Eurek
腾讯云 2023-04-21 12:57:07
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
债券简称23滨建投SCP011,发行金额为10亿元,票面利率6 73%,发行期限为160天。
4月21日,加泰媒体《每日体育报》继续聚焦梅西可能回归巴萨的传闻。《每日体育报》头版标题为“梅西,OK”,意思是更衣室赞同梅西回归。《每日
1、中国经济新闻联播网是中国经济报刊协会新媒体合作部为团结500余家新媒体机构。2、共同致力打造的中国产经资讯交互合作平
今日NBA季后赛,篮网半场以47-58暂时落后76人。上半场比赛,布里奇斯出战21分22秒,投篮12中4,两分球8中1,三分球4中3,罚球2中2,得到13分3
新华社休斯敦4月19日电(记者徐剑梅)美国中南部俄克拉何马州小镇科尔19日夜间遭遇龙卷风袭击,造成至少两人死亡。综合当
中新网湖州7月18日电(记者施紫楠)“嘿、哈!”当武术教练口令响起,在一阵阵呐喊助威声中,参赛选手劈、砍、斩、刺……时
4月20日,中成股份(000151)融资买入1442 07万元,融资偿还1561 77万元,融资净卖出119 7万元,融资余额1 77亿元。
格隆汇4月20日丨昨日集体活跃的有色金属板块今日盘中整体回落,园城黄金跌停,丰华股份、西部矿业、东方锆业跌超6%,横店东
宁德时代一季度净利98亿元,同比增逾5倍,超去年上半年净利总和,宁德时代,公司股东,资产负债率
一、云南省大理白族自治州宾川县天气预报1、宾川县气象台2023年4月20日10时30分继续发布干旱橙色预警信号。2、根据
1、中国的美食有蒸羊羔儿、蒸熊掌、蒸鹿尾儿、烧花鸭、烧雏鸡、烧子鹅、卤猪、卤鸭、酱鸡、腊肉、松花小肚儿、晾肉、香肠儿、什
每经AI快讯:北京时间4月20日11:30,上证指数早盘下跌23 23点,跌幅为0 69%,报收3346 9点,成交额2
截至2023年4月20日收盘,瑞斯康达(603803)报收于9 18元,上涨2 23%,换手率4 59%,成交量19 33万手,成交额1 75亿元。
直播吧4月20日讯德媒Sport1记者KerryHau消息,图赫尔对于拜仁现有的阵容并不完全感到满意。记者表示,尽管俱乐部还没有就阵容规划与图赫尔进行