1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-04 22:17:59 +08:00
Drasko DRASKOVIC 199a44b0a0 Change writer message format - accept raw messages
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
2017-09-29 16:18:41 +02:00

36 lines
794 B
Go

package api
import (
"time"
"github.com/go-kit/kit/metrics"
"github.com/mainflux/mainflux/http"
"github.com/mainflux/mainflux/writer"
)
var _ http.Service = (*metricService)(nil)
type metricService struct {
counter metrics.Counter
latency metrics.Histogram
http.Service
}
// NewMetricService instruments adapter by tracking request count and latency.
func NewMetricService(counter metrics.Counter, latency metrics.Histogram, s http.Service) http.Service {
return &metricService{
counter: counter,
latency: latency,
Service: s,
}
}
func (ms *metricService) Send(msg writer.RawMessage) {
defer func(begin time.Time) {
ms.counter.With("method", "send").Add(1)
ms.latency.With("method", "send").Observe(time.Since(begin).Seconds())
}(time.Now())
ms.Service.Send(msg)
}