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

查看 49|回复 2
作者: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 不知道是否能完成上述这种复杂的逻辑

string, Node, metrics, result

coderth
OP
  
求助大佬!!!
coderth
OP
  
本来是想自研 exporter 组件来实现的,但是可能领导觉得为了几个指标做个 exporter 组件成本太高,所以想依赖 Prometheus 原生的能力,不知道是不是有办法实现
您需要登录后才可以回帖 登录 | 立即注册

返回顶部