Skip to content

Conversation

@snowlyg
Copy link

@snowlyg snowlyg commented Apr 28, 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()

#25

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

Successfully merging this pull request may close these issues.

1 participant