Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use custom metrics? #25

Open
thisroot opened this issue Oct 3, 2018 · 5 comments
Open

How to use custom metrics? #25

thisroot opened this issue Oct 3, 2018 · 5 comments

Comments

@thisroot
Copy link

thisroot commented Oct 3, 2018

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?

@nizarayari
Copy link

Any update on this issue? It seems you can add custom metrics but the question is how to trigger them?

Thanks in advance!

@thisroot
Copy link
Author

thisroot commented Nov 20, 2018

@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

And you will see this example

@lmcdasm
Copy link

lmcdasm commented Aug 28, 2021

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):

image

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:
image

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

@snowlyg
Copy link

snowlyg commented Apr 26, 2022

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

@lmcdasm
Copy link

lmcdasm commented Jun 10, 2022

Thanks @snowlyg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants