-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
sent.go
29 lines (24 loc) · 852 Bytes
/
sent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package amprom
import (
"context"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/LordMoMA/Intelli-Mall/internal/am"
)
func SentMessagesCounter(serviceName string) am.MessagePublisherMiddleware {
counter := promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: serviceName,
Name: "sent_messages_count",
Help: fmt.Sprintf("The total number of messages sent by %s", serviceName),
}, []string{"message"})
return func(next am.MessagePublisher) am.MessagePublisher {
return am.MessagePublisherFunc(func(ctx context.Context, topicName string, msg am.Message) (err error) {
defer func() {
counter.WithLabelValues("all").Inc()
counter.WithLabelValues(msg.MessageName()).Inc()
}()
return next.Publish(ctx, topicName, msg)
})
}
}