How do I create labeled metrics with different labels in a threaded environment?

9 views
Skip to first unread message

Derek Chadwell

unread,
Jun 15, 2020, 11:05:04 PM6/15/20
to Prometheus Users
I have an application that spawns many worker threads.  In the main application I create a PrometheusMetrics() helper class that registers the metrics the threads will report on with the appropriate label names.  I pass the PrometheusMetrics class into each thread, and then create local variables in each thread with the labels filled out differently per thread.

I start the server and I see the #HELP and #TYPE text per metric I've registered, but I don't see any of the metrics outputs.

class PrometheusMetrics() {
    lateinit var iterations = Counter.build()
         .name("a_metric")
        .labelNames("a","b","c")
          .help("some help")
}

class main(){
 prometheusMetrics =PrometheusMetrics()
    forEach (iterator){
        spawnWorker(prometheusMetrics)
    }
}


Worker(prometheusMetrics: PrometheusMetrics){
    val localMetric = prometheusMetrics.iterations.labels('different","per","worker")
     localMetric.inc()
}




Is there something fundamentally wrong with this approach?

Thanks,

Derek 
Reply all
Reply to author
Forward
0 new messages