Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit cbc2b02

Browse files
committed
Set the name of k8s cluster in Stackdriver sink.
1 parent b7884da commit cbc2b02

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/sink-configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ The following options are available:
3737
* `withfields` - Use [InfluxDB fields](storage-schema.md#using-fields) (default: `false`)
3838
* `cluster_name` - cluster name for different Kubernetes clusters. (default: `default`)
3939

40+
### Stackdriver
41+
42+
This sink supports monitoring metrics only.
43+
To use the Stackdriver sink add following flag:
44+
45+
--sink=stackdriver[:?<STACKDRIVER_OPTIONS>]
46+
47+
The following options are available:
48+
* `workers` - The number of workers. (default: `1`)
49+
* `cluster_name` - Cluster name for different Kubernetes clusters. (default: ``)
50+
4051
### Google Cloud Monitoring
4152
This sink supports monitoring metrics only.
4253
To use the GCM sink add the following flag:

metrics/sinks/stackdriver/stackdriver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838

3939
type StackdriverSink struct {
4040
project string
41+
cluster string
4142
zone string
4243
stackdriverClient *sd_api.Service
4344
requestQueue chan *sd_api.CreateTimeSeriesRequest
@@ -223,6 +224,11 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
223224
workers = 1
224225
}
225226

227+
cluster_name := ""
228+
if len(opts["cluster_name"]) >= 1 {
229+
cluster_name = opts["cluster_name"][0]
230+
}
231+
226232
if err := gce_util.EnsureOnGCE(); err != nil {
227233
return nil, err
228234
}
@@ -250,6 +256,7 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
250256

251257
sink := &StackdriverSink{
252258
project: projectId,
259+
cluster: cluster_name,
253260
zone: zone,
254261
stackdriverClient: stackdriverClient,
255262
requestQueue: requestQueue,
@@ -408,7 +415,7 @@ func (sink *StackdriverSink) TranslateMetric(timestamp time.Time, labels map[str
408415
func (sink *StackdriverSink) getResourceLabels(labels map[string]string) map[string]string {
409416
return map[string]string{
410417
"project_id": sink.project,
411-
"cluster_name": "",
418+
"cluster_name": sink.cluster,
412419
"zone": sink.zone,
413420
"instance_id": labels[core.LabelHostID.Key],
414421
"namespace_id": labels[core.LabelPodNamespaceUID.Key],

0 commit comments

Comments
 (0)