Skip to content

Commit

Permalink
Add a metric for total FCM messags send
Browse files Browse the repository at this point in the history
  • Loading branch information
jayme-github committed Jun 14, 2020
1 parent 5d7f02d commit 5eda5b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func genericHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Para
topic := getParamTopic(ps)
message := NewMessage(topic, data.Title, data.Body)
msg, err := fcmClient.Send(req.Context(), message)
fcmMessages.WithLabelValues(ps.MatchedRoutePath(), topic).Inc()

if err != nil {
fcmErrors.WithLabelValues(ps.MatchedRoutePath(), topic).Inc()
Expand Down Expand Up @@ -115,6 +116,7 @@ func processFcmMessage(ctx context.Context, routePath, topic string, m *template

// Send a message to the devices subscribed to the topic.
fcmResponse, err := fcmClient.Send(ctx, message)
fcmMessages.WithLabelValues(routePath, topic).Inc()
if err != nil {
fcmErrors.WithLabelValues(routePath, topic).Inc()
}
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ var (
},
[]string{"type"},
)
fcmMessages = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "alertmanager_webhook_fcm_messages_total",
Help: "Total number of messages seind to Firebase Cloud Messaging API.",
},
[]string{"handler", "topic"},
)
fcmErrors = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "alertmanager_webhook_fcm_errors_total",
Expand All @@ -45,7 +52,7 @@ func main() {

fcmClient, err = NewMessaging()
if err != nil {
log.Fatalf("error getting Messaging client. Do you have GOOGLE_APPLICATION_CREDENTIALS set?: %v\n", err)
log.Fatalf("error getting Messaging client: %v\nDo you have GOOGLE_APPLICATION_CREDENTIALS set?\n", err)
}

router := httprouter.New()
Expand Down

0 comments on commit 5eda5b6

Please sign in to comment.