小白求问:问个关于 Prometheus 指标统计的问题

172 天前
 coderth

现在有个需求需要通过一些现有指标做一些逻辑判断,然后生成一个新的指标暴露出来类似下述的伪代码

func GetGPUModel() []Metrics {
	result := []Metrics{}
	// 获取所有 Node
	nodes := []string{"node1", "node2"}
	for _, node := range nodes {
		metrics := GetMetrics("DCGM_FI_DEV_MIG_MODE", map[string]string{
			"node": node,
		})
		var isMig bool
		for _, metric := range metrics {
			//说明开启了 MIG ,当前节点 GPU 为 MIG 模式
			if metric.Value == "1" {
				isMig = true
				break
			}
		}
		// 如果节点有 GPU 开启了 MIG ,那么节点模式为 MIG 模式
		if isMig {
			result = append(result, Metrics{
				Name:  "DCE_GPU_MODEL",
				Value: "1", // 节点模式为 MIG 模式
				Label: map[string]string{
					"node": node,
				},
			})
			continue
		}
		// 节点没有开启 MIG 模式,那么需要判断是否存在 vgpu 指标,如果存在说明是 VGPU 模式,不存在则是整卡模式
		// 获取 VGPU 指标
		vgpuMetrics := GetMetrics("nodeGPUOverview", map[string]string{
			"node": node,
		})
		// 判断是否存在
		if len(vgpuMetrics) != 0 {
			// 如果存在则是 VGPU 模式
			result = append(result, Metrics{
				Name:  "DCE_GPU_MODEL",
				Value: "2", // 节点模式为 VGPU 模式
				Label: map[string]string{
					"node": node,
				},
			})
			continue
		} else {
			// 不存在则是整卡模式
			result = append(result, Metrics{
				Name:  "GPU_MODEL",
				Value: "3", //节点模式为整卡模式
				Label: map[string]string{
					"node": node,
				},
			})
		}
	}
	return result
}

这种需求的话有什么最佳事件吗.....小白求问

简单研究了一下通过 Prometheus 的 rule 生成新的指标,但是貌似只能使用 promql ,promql 不知道是否能完成上述这种复杂的逻辑

580 次点击
所在节点    问与答
2 条回复
coderth
172 天前
求助大佬!!!
coderth
172 天前
本来是想自研 exporter 组件来实现的,但是可能领导觉得为了几个指标做个 exporter 组件成本太高,所以想依赖 Prometheus 原生的能力,不知道是不是有办法实现

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1000108

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX