dongyi7513 2019-07-22 01:33 采纳率: 100%
浏览 6308
已采纳

正则表达式:Grafana变量将连字符分隔的IP转换为点分隔的IP

我正在尝试使用自定义查询在Grafana中创建变量来扫描EKS群集中的节点。 当前,节点变量存储为“连字符”分隔的字符串(例如10-109-22-102); 我打算将其报告为“点”分隔的字符串(例如10.109.22.102)。 正则表达式是否有可能? Grafana变量支持通过抓取给定指标然后使用正则表达式提取报告的指标中的值来创建活动变量。 我目前正在抓取一个指标:

kube_node_info{container_runtime_version="docker://18.6.1",endpoint="http",instance="10.11.111.111:8080",job="kube-state-metrics",kernel_version="xxxxx",kubelet_version="xxxx",kubeproxy_version="xxxx",namespace="infra",node="ip-10-11-111-111.us-sdlls-as.compute.internal",os_image="Amazon Linux 2",pod="prometheus-operator-kube-state-metrics-sdfgsjdkgl-saldjl",service="prometheus-operator-kube-state-metrics"}

我目前正在使用正则表达式: /.*node="ip-([^"]*).us-*/ 来提取“连字符”分隔的IP。 我也尝试过使用其他比赛组,例如:([\d]{2,3})-([\d]{2,3})-([\d]{2,3})-([\d]{2,3})然而,这只返回第一匹配组在grafana(在这种情况下)10) 作为唯一的选择。

预期输出应为:

10.11.111.111
  • 写回答

3条回答 默认 最新

  • dt2015 2019-07-23 06:50
    关注

    The actual intent was to capture the IP of the instance and list all of them as a dynamic variable via a query and then enable all the node metrics via the IPs. This was a bad approach since lot of prometheus node-metrics are exported with label node=ip-XX-XX-XXX-XXX-<region>-.compute.internal (where XX are digits). Also grafana variables reports match of only the 1st sub-group - ideally it should be all the subgroups.

    However, even if i were to capture the subgroup say XX.XX.XXX.XXX this would mean for every metric that I need to capture and graph I would need to address for matches for all the IPs in the EKS nodes - this is not possible especially if we want to enable "All" variable in which grafana replaces the variable call with regex of all the variables matches. Ex. if my k8s node had following IPs: * 10.10.0.1 * 10.10.0.2 * 10.10.0.3 and I call this variable as Node Grafana will list following variables: * All * 10.10.0.1 * 10.10.0.2 * 10.10.0.3 On selecting All grafana will do replace of $Node to ./*(10.10.0.1|10.10.0.2|10.10.0.3)*/ However if i had a Query for getting the node info : kube_pod_info{node=~"$Node"} -> this would fail because node name is in a different format we may try and solve it by using label_replace but again we cannot address using $Node in case All variable is used.

    Conclusion : use the variable $Node (i.e. * ip-10-10-0-1.us-sdlls-as.compute.internal * ip-10-10-0-2.us-sdlls-as.compute.internal * ip-10-10-0-3.us-sdlls-as.compute.internal ) - as-is this would make all other panels much more convenient and easy to configure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)