-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
health: Adds new prometheus metrics and metrics endpoint (ory#827)
Signed-off-by: Dmitry Dolbik <[email protected]>
- Loading branch information
Showing
11 changed files
with
164 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
* @license Apache-2.0 | ||
*/ | ||
|
||
package metrics | ||
package telemetry | ||
|
||
import ( | ||
"runtime" | ||
|
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
* @license Apache-2.0 | ||
*/ | ||
|
||
package metrics | ||
package telemetry | ||
|
||
import ( | ||
"net/url" | ||
|