forked from kubernetes-retired/heapster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
95 lines (82 loc) · 2.99 KB
/
driver.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gcm
import (
kube_api "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/heapster/extpoints"
sink_api "github.com/GoogleCloudPlatform/heapster/sinks/api/v1"
"github.com/golang/glog"
)
type gcmSink struct {
core *GcmCore
}
// Adds the specified metrics or updates them if they already exist.
func (self gcmSink) Register(metrics []sink_api.MetricDescriptor) error {
for _, metric := range metrics {
if err := self.core.Register(metric.Name, metric.Description, metric.Type.String(), metric.ValueType.String(), metric.Labels); err != nil {
return err
}
if rateMetric, exists := gcmRateMetrics[metric.Name]; exists {
if err := self.core.Register(rateMetric.name, rateMetric.description, sink_api.MetricGauge.String(), sink_api.ValueDouble.String(), metric.Labels); err != nil {
return err
}
}
}
return nil
}
// Stores events into the backend.
func (self gcmSink) StoreEvents([]kube_api.Event) error {
// No-op, Google Cloud Monitoring doesn't store events
return nil
}
// Pushes the specified metric values in input. The metrics must already exist.
func (self gcmSink) StoreTimeseries(input []sink_api.Timeseries) error {
// Build a map of metrics by name.
metrics := make(map[string][]Timeseries)
for _, entry := range input {
metric := entry.Point
metricTimeseries, err := self.core.GetMetric(metric)
if err != nil {
return err
}
metrics[metric.Name] = append(metrics[metric.Name], *metricTimeseries)
// TODO(vmarmol): Stop doing this when GCM supports graphing cumulative metrics.
// Translate cumulative to gauge by taking the delta over the time period.
rateMetricTimeseries, err := self.core.GetEquivalentRateMetric(metric)
if err != nil {
return err
}
if rateMetricTimeseries == nil {
continue
}
rateMetricName := rateMetricTimeseries.TimeseriesDescriptor.Metric
metrics[rateMetricName] = append(metrics[rateMetricName], *rateMetricTimeseries)
}
return self.core.StoreTimeseries(metrics)
}
func (self gcmSink) DebugInfo() string {
return "Sink Type: GCM"
}
func (self gcmSink) Name() string {
return "Google Cloud Monitoring Sink"
}
func init() {
extpoints.SinkFactories.Register(CreateGCMSink, "gcm")
}
func CreateGCMSink(_ string, _ map[string][]string) ([]sink_api.ExternalSink, error) {
core, err := NewCore()
sink := gcmSink{core: core}
glog.Infof("created GCM sink")
return []sink_api.ExternalSink{sink}, err
}