This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
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.
* add metrics option * add metrics * update readme * add examples
- Loading branch information
Showing
14 changed files
with
278 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3' | ||
services: | ||
prometheus: | ||
image: prom/prometheus:latest | ||
ports: | ||
- 9090:9090 | ||
command: | ||
- --config.file=/etc/prometheus/prometheus.yml | ||
volumes: | ||
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro |
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,45 @@ | ||
package marudor | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
// APIMetrics Registry | ||
type APIMetrics struct { | ||
RequestsTotal *prometheus.CounterVec | ||
RequestDurationSeconds *prometheus.HistogramVec | ||
RequestsByTrainNameTotal *prometheus.CounterVec | ||
} | ||
|
||
// NewAPIMetrics return a new metric registry | ||
func NewAPIMetrics() *APIMetrics { | ||
marudorPrefix := "marudor_" | ||
|
||
buckets := []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10} | ||
|
||
total := prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Name: marudorPrefix + "requests_total", | ||
Help: "How many HTTP requests processed, partitoned by status code and endpoint", | ||
}, []string{"status_code", "endpoint"}) | ||
|
||
duration := prometheus.NewHistogramVec(prometheus.HistogramOpts{ | ||
Name: marudorPrefix + "duration_seconds", | ||
Help: "request duration", | ||
Buckets: buckets, | ||
}, []string{"status_code", "endpoint"}) | ||
|
||
trainNames := prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Name: marudorPrefix + "requests_by_trainname_total", | ||
Help: "How many requests processed, partitoned by status code and train name", | ||
}, []string{"status_code", "trainname"}) | ||
|
||
register := &APIMetrics{ | ||
RequestsTotal: total, | ||
RequestDurationSeconds: duration, | ||
RequestsByTrainNameTotal: trainNames, | ||
} | ||
|
||
prometheus.MustRegister(register.RequestsTotal) | ||
prometheus.MustRegister(register.RequestDurationSeconds) | ||
prometheus.MustRegister(register.RequestsByTrainNameTotal) | ||
|
||
return register | ||
} |
Oops, something went wrong.