-
-
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
Signed-off-by: Dmitry Dolbik <dolbik@gmail.com>
- Loading branch information
Showing
11 changed files
with
155 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,37 @@ | ||
package prometheus | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
type Metrics struct { | ||
Counter *prometheus.CounterVec | ||
ResponseTime *prometheus.HistogramVec | ||
} | ||
|
||
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) | ||
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,23 @@ | ||
package prometheus | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type MetricsManager struct { | ||
prometheusMetrics *Metrics | ||
} | ||
|
||
func NewMetricsManager(version, hash, buildTime string) *MetricsManager { | ||
return &MetricsManager{ | ||
prometheusMetrics: NewMetrics(version, hash, buildTime), | ||
} | ||
} | ||
|
||
func (pmm *MetricsManager) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { | ||
start := time.Now() | ||
next(rw, r) | ||
pmm.prometheusMetrics.Counter.WithLabelValues(r.URL.Path).Inc() | ||
pmm.prometheusMetrics.ResponseTime.WithLabelValues(r.URL.Path).Observe(time.Since(start).Seconds()) | ||
} |
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" | ||
|