-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace go-gin-prometheus for better control over metrics
- Loading branch information
Showing
6 changed files
with
76 additions
and
17 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
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,61 @@ | ||
package metrics | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
var ( | ||
apiLatencySec *prometheus.HistogramVec | ||
dbErrorCount *prometheus.CounterVec | ||
) | ||
|
||
const ( | ||
appName = "fleetdb" | ||
apiSub = "api" | ||
dbSub = "database" | ||
) | ||
|
||
func init() { | ||
apiLatencySec = promauto.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: appName, | ||
Subsystem: apiSub, | ||
Name: "latency_seconds", | ||
Help: "api latency measurements in seconds", | ||
// XXX: These buckets will likely need some tuning | ||
Buckets: []float64{0.025, 0.05, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0, 15.0, 20.0}, | ||
}, | ||
[]string{ | ||
"code", | ||
"endpoint", | ||
}, | ||
) | ||
|
||
dbErrorCount = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: appName, | ||
Subsystem: dbSub, | ||
Name: "error_count", | ||
Help: "total count of database errors", | ||
}, | ||
[]string{ | ||
"operation", | ||
}, | ||
) | ||
} | ||
|
||
// APICallEpilog observes the response and elapsed time of a call to a given endpoint | ||
func APICallEpilog(start time.Time, endpoint string, responseCode int) { | ||
code := strconv.Itoa(responseCode) | ||
elapsed := time.Since(start).Seconds() | ||
apiLatencySec.WithLabelValues(endpoint, code).Observe(elapsed) | ||
} | ||
|
||
// DBError observes errors arising from an attempt to read or write data to the remote database | ||
func DBError(op string) { | ||
dbErrorCount.WithLabelValues(op).Inc() | ||
} |