From 5da59358fb5832e577705af88812cb5830c0a971 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Mon, 3 Aug 2020 00:34:43 +1000 Subject: [PATCH] Add svg generation time --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 2cac0db..ebc87b5 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,11 @@ var ( Name: "badge_requested_total", Help: "The total request number of badges", }) + + badgeGenerationTime = promauto.NewHistogram(prometheus.HistogramOpts{ + Name: "badge_generation_time", + Help: "The time consumed for badge generation", + }) ) type Metric struct { @@ -99,6 +104,8 @@ func main() { } func generateSVG(client api.Client, c *gin.Context) error { + startTime := time.Now() + queryName := c.Param("name") query, ok := queriesMap[queryName] if !ok { @@ -124,6 +131,7 @@ func generateSVG(client api.Client, c *gin.Context) error { valueText := strconv.Itoa(int(metric.Value)) canvas.Text(badgeWidth*0.7, 15, valueText, textStyle) canvas.End() + badgeGenerationTime.Observe(float64(time.Now().Sub(startTime).Microseconds())) badgeRequested.Inc() return nil