2018-04-17 16:25:41 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// MonitoringConfiguration allows you to configure how record processing metrics are exposed
|
|
|
|
|
type MonitoringConfiguration struct {
|
|
|
|
|
MonitoringService string // Type of monitoring to expose. Supported types are "prometheus"
|
2018-04-20 15:30:24 +00:00
|
|
|
Region string
|
2018-04-17 16:25:41 +00:00
|
|
|
Prometheus PrometheusMonitoringService
|
|
|
|
|
CloudWatch CloudWatchMonitoringService
|
|
|
|
|
service MonitoringService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MonitoringService interface {
|
|
|
|
|
Init() error
|
2018-04-21 04:07:11 +00:00
|
|
|
Start() error
|
2018-04-17 16:25:41 +00:00
|
|
|
IncrRecordsProcessed(string, int)
|
|
|
|
|
IncrBytesProcessed(string, int64)
|
|
|
|
|
MillisBehindLatest(string, float64)
|
|
|
|
|
LeaseGained(string)
|
|
|
|
|
LeaseLost(string)
|
|
|
|
|
LeaseRenewed(string)
|
|
|
|
|
RecordGetRecordsTime(string, float64)
|
|
|
|
|
RecordProcessRecordsTime(string, float64)
|
2018-04-21 04:07:11 +00:00
|
|
|
Shutdown()
|
2018-04-17 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MonitoringConfiguration) Init(nameSpace, streamName string, workerID string) error {
|
|
|
|
|
if m.MonitoringService == "" {
|
|
|
|
|
m.service = &noopMonitoringService{}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch m.MonitoringService {
|
|
|
|
|
case "prometheus":
|
|
|
|
|
m.Prometheus.Namespace = nameSpace
|
|
|
|
|
m.Prometheus.KinesisStream = streamName
|
|
|
|
|
m.Prometheus.WorkerID = workerID
|
2018-04-20 15:30:24 +00:00
|
|
|
m.Prometheus.Region = m.Region
|
2018-04-17 16:25:41 +00:00
|
|
|
m.service = &m.Prometheus
|
|
|
|
|
case "cloudwatch":
|
2018-04-20 15:30:24 +00:00
|
|
|
m.CloudWatch.Namespace = nameSpace
|
2018-04-17 16:25:41 +00:00
|
|
|
m.CloudWatch.KinesisStream = streamName
|
|
|
|
|
m.CloudWatch.WorkerID = workerID
|
2018-04-20 15:30:24 +00:00
|
|
|
m.CloudWatch.Region = m.Region
|
2018-04-17 16:25:41 +00:00
|
|
|
m.service = &m.CloudWatch
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("Invalid monitoring service type %s", m.MonitoringService)
|
|
|
|
|
}
|
|
|
|
|
return m.service.Init()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MonitoringConfiguration) GetMonitoringService() MonitoringService {
|
|
|
|
|
return m.service
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type noopMonitoringService struct{}
|
|
|
|
|
|
2018-04-21 04:07:11 +00:00
|
|
|
func (n *noopMonitoringService) Init() error { return nil }
|
|
|
|
|
func (n *noopMonitoringService) Start() error { return nil }
|
|
|
|
|
func (n *noopMonitoringService) Shutdown() {}
|
2018-04-17 16:25:41 +00:00
|
|
|
|
|
|
|
|
func (n *noopMonitoringService) IncrRecordsProcessed(shard string, count int) {}
|
|
|
|
|
func (n *noopMonitoringService) IncrBytesProcessed(shard string, count int64) {}
|
|
|
|
|
func (n *noopMonitoringService) MillisBehindLatest(shard string, millSeconds float64) {}
|
|
|
|
|
func (n *noopMonitoringService) LeaseGained(shard string) {}
|
|
|
|
|
func (n *noopMonitoringService) LeaseLost(shard string) {}
|
|
|
|
|
func (n *noopMonitoringService) LeaseRenewed(shard string) {}
|
|
|
|
|
func (n *noopMonitoringService) RecordGetRecordsTime(shard string, time float64) {}
|
|
|
|
|
func (n *noopMonitoringService) RecordProcessRecordsTime(shard string, time float64) {}
|