Prometheus 导出器客户端在源停止后继续发送最后一个值

Prometheus exporter client keeps sending the last value after the source stops

我使用 Prometheus 客户端编写了一个导出器来导出一些数据,例如 CPU 和我的应用程序中不同进程的内存使用情况。一切正常,然后我注意到当我终止一个进程时,只要导出器启动,客户端就会继续发送它收到的最后一个值。

我使用了 gaugevec 和 Set 方法。我怀疑由于 Set 客户端已设置为该值,并且由于它没有收到任何新值,它只是继续发送最后一个值。下面是我的代码:

var CpuPercentValue = prometheus.NewGaugeVec(
    prometheus.GaugeOpts{
        Namespace: "MyExporter",
        Name:      "CpuPercentValue",
        Help:      "CpuPercentValue",
    },
    []string{
        "namespace",
        "proc_qID",
        "opID",
    },
)

var MemoryValue = prometheus.NewGaugeVec(
    prometheus.GaugeOpts{
        Namespace: "MyExporter",
        Name:      "MemoryValue",
        Help:      "MemoryValue",
    },
    []string{
        "namespace",
        "proc_qID",
        "opID",
    },
)

var RunThreadsValue = prometheus.NewGaugeVec(
    prometheus.GaugeOpts{
        Namespace: "MyExporter",
        Name:      "RunThreadsValue",
        Help:      "RunThreadsValue",
    },
    []string{
        "namespace",
        "proc_qID",
        "opID",
    },
)

prometheus.MustRegister(CpuPercentValue)
prometheus.MustRegister(MemoryValue)
prometheus.MustRegister(RunThreadsValue)

go func() {
    for d := range msgs {
        // I get the labels from the RabbitMQ routingkey
        routingkey = strings.Split(d.RoutingKey, ".")
        procid = routingkey[0]
        opid = routingkey[1]

        // get the data
        err := json.Unmarshal([]byte(d.Body), opst)
        failOnError(err, "failed to Unmarshal the opstat")

        // set the values
        // namespace here is the different namespaces in a Kubernetes cluster
        CpuPercentValue.With(prometheus.Labels{"namespace": namespace, "proc_qID": procid, "opID": opid}).Set(opst.CpuPercent.Value)
        MemoryValue.With(prometheus.Labels{"namespace": namespace, "proc_qID": procid, "opID": opid}).Set(opst.Memory.Value)
        RunThreadsValue.With(prometheus.Labels{"namespace": namespace, "proc_qID": procid, "opID": opid}).Set(opst.NumThreads.Value)
    }
}()

我该如何解决这个问题?

问题是我没有删除未发布的标签。我希望 Prometheus 客户端在收到新值时才导出,但 assumption/expectation 是错误的。