1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
Dejan Mijic 26a2ea1ce1
Integrate http adapter service
Moved main method to top-level 'cmd' directory. Extracted the dockerfile
to the root as well.

Signed-off-by: Dejan Mijic <dejan@mainflux.com>
2017-09-23 01:57:14 +02:00

36 lines
795 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(msgs []writer.Message) {
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(msgs)
}