-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Prometheus] Add new prometheus metrics and metrics endpoint
- Loading branch information
Showing
2 changed files
with
44 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
package prometheus | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
type Metrics struct { | ||
Counter *prometheus.CounterVec | ||
ResponseTime *prometheus.HistogramVec | ||
} | ||
// Metrics prototypes | ||
// Example: | ||
// Counter *prometheus.CounterVec | ||
// ResponseTime *prometheus.HistogramVec | ||
type Metrics struct{} | ||
|
||
// Method for creation new custom Prometheus metrics | ||
// Example: | ||
// pm := &Metrics{ | ||
// Counter: prometheus.NewCounterVec( | ||
// prometheus.CounterOpts{ | ||
// Name: "servicename_requests_total", | ||
// Help: "Description", | ||
// ConstLabels: map[string]string{ | ||
// "version": version, | ||
// "hash": hash, | ||
// "buildTime": buildTime, | ||
// }, | ||
// }, | ||
// []string{"endpoint"}, | ||
// ), | ||
// ResponseTime: prometheus.NewHistogramVec( | ||
// prometheus.HistogramOpts{ | ||
// Name: "servicename_response_time_seconds", | ||
// Help: "Description", | ||
// ConstLabels: map[string]string{ | ||
// "version": version, | ||
// "hash": hash, | ||
// "buildTime": buildTime, | ||
// }, | ||
// }, | ||
// []string{"endpoint"}, | ||
// ), | ||
// } | ||
// prometheus.Register(pm.Counter) | ||
// prometheus.Register(pm.ResponseTime) | ||
func NewMetrics(version, hash, buildTime string) *Metrics { | ||
labels := map[string]string{ | ||
"version": version, | ||
"hash": hash, | ||
"buildTime": buildTime, | ||
} | ||
pm := &Metrics{ | ||
Counter: prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "sts_requests_total", | ||
Help: "Secure token service requests served per endpoint", | ||
ConstLabels: labels, | ||
}, | ||
[]string{"endpoint"}, | ||
), | ||
ResponseTime: prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Name: "sts_response_time_seconds", | ||
Help: "Secure token service response time served per endpoint", | ||
ConstLabels: labels, | ||
}, | ||
[]string{"endpoint"}, | ||
), | ||
} | ||
prometheus.Register(pm.Counter) | ||
prometheus.Register(pm.ResponseTime) | ||
pm := &Metrics{} | ||
return pm | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters