forked from ory/hydra
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* OData no longer defaulted, using header to cause it * Simpler value * Add Prometheus endpoint Based on ory#827 JIRA: WAP-1891
- Loading branch information
1 parent
95d1755
commit f8ef740
Showing
9 changed files
with
104 additions
and
20 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package prometheus | ||
|
||
// 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 { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package prometheus | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type MetricsManager struct { | ||
prometheusMetrics *Metrics | ||
} | ||
|
||
func NewMetricsManager(version, hash, buildTime string) *MetricsManager { | ||
return &MetricsManager{ | ||
prometheusMetrics: NewMetrics(version, hash, buildTime), | ||
} | ||
} | ||
|
||
// Main middleware method to collect metrics for Prometheus. | ||
// Example: | ||
// start := time.Now() | ||
// next(rw, r) | ||
// Request counter metric | ||
// pmm.prometheusMetrics.Counter.WithLabelValues(r.URL.Path).Inc() | ||
// Response time metric | ||
// pmm.prometheusMetrics.ResponseTime.WithLabelValues(r.URL.Path).Observe(time.Since(start).Seconds()) | ||
func (pmm *MetricsManager) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { | ||
next(rw, r) | ||
} |
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
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
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