My bad for the mistake, I have look into the imports and had an issues. this my new code however, still I am not able to see the metrics: //imports *"github.com/prometheus/client_golang/prometheus"* * "github.com/prometheus/client_golang/prometheus/collectors"* * "github.com/prometheus/client_golang/prometheus/promauto"*
*// below code somewhere in the main func* *prometheus.NewRegistry().MustRegister(collectors.NewDBStatsCollector(db.GetConnection(), "postgres"))* On Wednesday, 18 August 2021 at 13:38:52 UTC+2 afridi wrote: > > Hey everyone, > > Need some help regarding the usage for the collector for > database/sql(DBStats). I am instrumenting my go code and want to get > metrics for connection pool. > > I was planning to use this awesome nice library > <http://github.com/dlmiddlecote/sqlstats>by dlmiddlecote dbstates. I > created a demo and it works fine. > > > > *//sample code for above librarycollector := > sqlstats.NewStatsCollector(conf.DB.Type, db.GetConnection())// Register it > with Prometheus // prometheus.MustRegister(collector)* > > However, recently I have notice that client_go(already using this) have > this new same feature in latest release version 1.11.0 > <https://github.com/prometheus/client_golang/releases/tag/v1.11.0> and it > was merged in this PR > <https://github.com/prometheus/client_golang/pull/866>. > > > *//sample code for client_go* > *reg := prometheus.NewRegistry()* > * reg.MustRegister(prometheus.NewDBStatsCollector(db.GetConnection(), > "db_A"))* > > Now my question, can someone provide me POC for this feature like how to > instrument my code. I tried but due lake of experience I am failing, you > can see the error in the subject of this post that I am getting. Any help > would be appreciated. > > Regards, > Afr > -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/c9ad9ea4-56a0-445b-9861-10b3d194091cn%40googlegroups.com.

