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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?