【云原生 • Prometheus】Prometheus 注册中心Eureka服务发现原理|世界快看点
Prometheus 注册中心Eureka服务发现原理
概述
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 #刷新间隔,默认30s
eureka_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协议实现
基于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服务发现原理|世界快看点
- 金牛座男生喜欢一个女生的表现_一个女生暗恋你的表现 环球关注
- 天天讯息:五部《蜘蛛侠》电影登陆迪士尼+:托比、加菲版今日上线
- 打造场景化解决方案 绿盾中天门窗引领美学、智能、高奢三大趋势|焦点播报
- 官方:攻防俱佳,德里赫特以40%得票率当选拜仁3月最佳球员
- 截图!长按保存分享!Cocos Creator
- 焦点报道:鹤壁市鹤山区开展“铸牢中华民族共同体意识暨民族宗教政策法规宣传月”活动
- 天天百事通!乳源瑶族自治县气象台发布暴雨红色预警【I级/特别严重】【2023-04-19】
- 曝白敬亭宋轶即将分手,两人此前还被传领证结婚 动态
- 稳步提升粮食产能 全面推进乡村振兴——一季度农业农村经济运行情况观察
- 天天头条:差评率高出对手一倍,《灌篮高手》不该再营销情怀了
- 联想笔记本摄像头打不开怎么办?
- 《流浪地球2》等校园路演,一场观众和电影人的“双向奔赴”
- 天天新资讯:好评中国丨融通古今,点亮中华文化自信之灯
- 冬季海竿钓鱼技巧_冬季海竿钓鱼技巧介绍-全球热消息
- 世卫组织拟更新重点病原体目录,加强防范未来大流行病|全球今热点
- 世界热议:卓翼科技:4月20日融资买入330.74万元,融资融券余额1.93亿元
- 焦点精选!华西股份:4月20日融资买入9123.22万元,融资融券余额4.02亿元
- 北京丰台区晓月苑一里、二里公交站候车亭“问题座椅”修复一新
- 瀚川智能:4月20日融券卖出8200股,融资融券余额2.41亿元 焦点热闻
- 即时焦点:单场狂砍22+13!限制浓眉14中4!年薪也才178万,灰熊又捡到宝了
- 今日热讯:上海苏州河半程马拉松赛周六开跑,这些路段将临时交通管控
- 84烧不烧塑料袋?
- 牙结石可以自己抠掉吗_牙齿上有牙结石怎么办 世界快播
- 俄罗斯新型坦克“黑鹰”即将投入战场
- 东营最新停水通知!涉及这些单位_全球通讯
- 阚清子纪凌尘几年感情_阚清子纪凌尘分手真正原因是什么 环球快报
- 上海24家未来车产业链企业签倡议书,打造友好的产业朋友圈 快资讯
- 鸿星科技2022年净利1751.73万同比增长66.78% 订单增加、销售量增加-当前速读
- 焦点精选!降幅达到800元!华为Mate50系列遭遇背刺了吗?其实是更值了
- 黄渤监制主演电影《学爸》定档8月18日 现实主义笔触描摹亲子双向成长_焦点精选
- 《灌篮高手》热映_你为青春补票吗 一大波中年男人已在凌晨冲进影院
- 公安机关2022年共侦破侵权假冒刑事案件2.7万起 典型案例公布
- 如何调出阿宝色_阿宝色调
- 今亮点!垫付宝最新判决书(垫付宝)
- 世界动态:三门核电4号机组常规岛底板施工完成
- 天天微资讯!林肯品牌焕新登陆上海车展 全新一代航海家同步上市
- 阿奇霉素肠溶片怎么吃的_阿奇霉素肠溶片怎么吃 全球百事通
- 全国肿瘤防治宣传周丨HPV疫苗接种率还不足1%?专家建议青少年接种HPV|每日热闻
- weatherproof是什么意思_weatherproof是品牌吗|全球热点
- 即时看!2023五一广州长隆野生动物园特惠活动一览
- 西安曲江公租房公示名单怎么查_短讯
- 世界观焦点:美图秀秀 iOS 端 9.8.60 版本发布:AI 玩法以及美图配方上线!
- 关于杭州分数低的二本院校2023
- 广东自贸试验区去年实现进出口总值5350.8万亿元_焦点播报
- 有研粉材: 2023年第一季度报告
- 新一股强冷空气来袭 中央气象台发布三项预警-环球观速讯
- 黄头侧颈龟怎么养
- 每日看点!《速度与激情10》5月17日上映, 路易斯·莱特里尔继续执导《速11》
- 美银证券:重申新东方-S买入评级 目标价升至42.7港元
- 新萨博卷土重来 萨博94X全球首发亮相-播报
- 世界资讯:汪峰被黑了!洛阳演唱会“大获成功”,被无脑黑“卖不出票”
- 焦点速递!成都购车补贴怎么申请?
- 焦点播报:夏天手上起的小水泡怎么回事儿_夏天手上起的小水泡怎么回事
- 三大协会联合抖音直播发起行业倡议:规范发展 促进文化传播和消费-消息
- 【天天聚看点】初尝茅台冰淇淋甜果后,茅台酒酿酸奶恐难复制其成功
- 劳务公司名称大全集最新 劳务公司名称
- 香港“文化艺术盛事基金”开始接受申请
- 世界关注:华策影视拟溢价1.2倍收购两家无营收公司 积极拥抱AIGC时代一季度净利预增超10%
- AI军备竞赛瞄准硬件!芯片设备需求激增
- 外卖员身绑树枝挂吊瓶送外卖 网友:太心疼了
- 能“吸水”、会“变身”……“绿色办赛 智慧大运”从场馆开始 全球热闻
- 焦点报道:Meta和Pico加速垒墙
- 公主嫁人3天自杀,掀开她裙子才找到原因,几万人送葬-世界讯息
- 精彩看点:蓬莱大柳行镇:凝心聚力织牢森林防火网
- 全球即时看!王导:黄金日线中轨已经破位,1992下空
- LPR息率维持不变 策略师:当前信贷重点是结构
- 虚假宣传、价格欺诈,三亚这些海鲜店、婚纱摄影企业下架整改
- 苹果被指窃取商业秘密,Masimo 公司索赔 31 亿美元_全球消息
- 法媒:黄金价格飙升预示着什么 全球快消息
- 天天微动态丨比特矿业美股跌13.43%
- 古代及笄之年是多少岁 及笄之年是几岁
- 大同区高台子镇温室草莓柿子成熟正当时 全球播报
- 全球观察:原神3.6版本陪跑四星角色
- 【环球热闻】湖北襄阳全国征集城市宣传语 最高奖10万元
- 主战场 电影_战场 2012年Neil Mackay执导加拿大电影
- 澳门冠军赛第4日:国乒7人争8强席位,钱天一打头阵,小胖战强敌 焦点热文
- 天天短讯!多囊卵巢怎么调理最快_多囊卵巢怎么调理怀孕
- 环球最新:山东泗水两货车相撞十余人受伤
- “五一”返程火车票今起开售 这些线路车票或紧张
- 服装_世界时讯
- 翔宇医疗:股东拟减持不超过5.25%-全球视讯
- 四川通报“甘孜稻城森林火情”:整体可控,投入1100余人参与扑救
- 注意!晨鸣纸业将于5月8日召开股东大会 焦点播报
- 华翔股份:公司将于2023年4月26日披露《2022年年度报告》_环球快看
- 今日时讯:布克杜兰特是两届FMVP已证明一切 布克38+9KD25+6小卡31+9+7威少28分太阳逆转快船扳成1-1-每日观察
- 【独家焦点】临颍县:“书记带头行”察民情解民忧
- 手工馒头的做法大揭秘
- Dyuans是哪个国家的品牌_什么档次怎么样
- 【环球新要闻】广西钦州市委书记林冠同志逝世,享年56岁
- 恒烁股份:公司CiNOR存算一体AI芯片目前处于研发阶段 当前消息
- A股市场午后放量下行收跌,成交连续12个交易日超万亿元
- 世界今头条!露营产业三年走完十年路:进来很多、死掉很多、壮大很多
- 张本智和逆转林诗栋,比赛经验丰富,钱天一首轮横扫木原美优|天天新动态
- 环球热点!继续看跌金价。
- 2023上海车展:全新一代日产逍客正式亮相
- 阵风7、8级伴有扬沙 北京发布大风蓝色预警
- 中微公司(688012)4月19日主力资金净卖出9202.72万元
- 诺辉健康发布首份常卫清用户数据报告 83.2%阳性且肠镜检出异常者为癌前病变
- 昔日的“电信诈骗村”,如何走上乡村振兴的正道? 当前关注
广告
广告
- 长治襄垣县增收11517万元 提前15天实现首季“开门红”
- 黑龙江讷河新增1例确诊4例无症状 病例详情公布
- 浙江宁波余姚奉化宁海三地开展核酸检测 结果均为阴性
- 浙江湖州南浔三处棋牌室经营者被行拘
- 那年今日 | 一张漫画涨知识之12月13日
- 在宁波乘火车跨省出行须持48小时内核酸阴性证明
- 浙江温州一地发现核酸弱阳性?复采复检结果均为阴性
- 浙江三门发现一名密接者:二次核酸检测结果均为阴性
- 贱卖的发电机 新买的制茶机——安徽水电供区改革两周年回访见闻
- 浙江杭州新增1例新冠肺炎确诊病例 为集中隔离人员
- 2022年研考在即,学硕缩招,专硕时代真的来了?
- 探访杭州核酸检测点:排队高峰多在夜间 医院24小时运转
- 浙江发挥零售药店“哨点”作用 织就疫情防控监测网
- 哈尔滨市本轮疫情首批1名确诊患者出院
- 宁波镇海第三轮全员核酸检测574181人 结果均为阴性
- 陕西新增本土确诊病例1例、境外输入无症状感染者2例
- 齐齐哈尔讷河一地调整为中风险地区
- 浙江新增新冠肺炎确诊病例75例 其中本土74例
- 内蒙古新增本土确诊病例5例 均在呼伦贝尔满洲里市
- 黑龙江无新增确诊病例 新增本土核酸检测初筛阳性人员5例