go-gin-prometheus
go-gin-prometheus copied to clipboard
How to use custom metrics?
Hi, i read sourse code and could not understand how to use custom metrics? Does exist way do it, or i should rewrite this library?
Any update on this issue? It seems you can add custom metrics but the question is how to trigger them?
Thanks in advance!
@nizarayari Yes, you should use gin metrics with you custom mectrics build with standart prometheus library methods. Gin prometheus library collect base metrics and bind it into common metrics report
ok.. so im a bit stumped here.
i have the custom metrics implemented (so i can see them show up when i have my server running):
However, even with looking with the answer provided to nizarayari, i dont see how to apply the .Inc() method to the custom metric.
Here is my code snippet:
I have tried as well looking at the other example, however the prometheus.Register(numErrors) example never ends up showing up in the gin metrics list (as the test ones outlined above are).
any pointers would be wonderful! D
I change MetricsList []*Metric
to MetricsList map[string]*Metric
, when i use the custom metrics. Make a easy way to get custom metric.
customMetrics := []*ginprometheus.Metric{
&ginprometheus.Metric{
ID: "1234", // optional string
Name: "test_metric", // required string
Description: "Counter test metric", // required string
Type: "counter", // required string
},
&ginprometheus.Metric{
ID: "1235", // Identifier
Name: "test_metric_2", // Metric Name
Description: "Summary test metric", // Help Description
Type: "summary", // type associated with prometheus collector
},
// Type Options:
// counter, counter_vec, gauge, gauge_vec,
// histogram, histogram_vec, summary, summary_vec
}
p := ginprometheus.NewPrometheus("gin", customMetrics)
// add data to custom metrics
m := p.MetricsList["1234"].MetricCollector.(prometheus.Counter)
m.Inc()
#53
Thanks @snowlyg