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

Commit 34470a2

Browse files
authored
Merge pull request #1635 from andyxning/add_cluster_name_to_influxdb_sink
add cluster_name to influxdb sink
2 parents a381ace + 7445ccf commit 34470a2

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

common/influxdb/influxdb.go

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type InfluxdbConfig struct {
4040
WithFields bool
4141
InsecureSsl bool
4242
RetentionPolicy string
43+
ClusterName string
4344
}
4445

4546
func NewClient(c InfluxdbConfig) (InfluxdbClient, error) {
@@ -79,6 +80,7 @@ func BuildConfig(uri *url.URL) (*InfluxdbConfig, error) {
7980
WithFields: false,
8081
InsecureSsl: false,
8182
RetentionPolicy: "0",
83+
ClusterName: "default",
8284
}
8385

8486
if len(uri.Host) > 0 {
@@ -121,5 +123,9 @@ func BuildConfig(uri *url.URL) (*InfluxdbConfig, error) {
121123
config.InsecureSsl = val
122124
}
123125

126+
if len(opts["cluster_name"]) >= 1 {
127+
config.ClusterName = opts["cluster_name"][0]
128+
}
129+
124130
return &config, nil
125131
}

docs/sink-configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following options are available:
3535
* `secure` - Connect securely to InfluxDB (default: `false`)
3636
* `insecuressl` - Ignore SSL certificate validity (default: `false`)
3737
* `withfields` - Use [InfluxDB fields](storage-schema.md#using-fields) (default: `false`)
38+
* `cluster_name` - cluster name for different Kubernetes clusters. (default: `default`)
3839

3940
### Google Cloud Monitoring
4041
This sink supports monitoring metrics only.

events/sinks/influxdb/influxdb.go

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func (sink *influxdbSink) ExportEvents(eventBatch *core.EventBatch) {
131131
if err != nil {
132132
glog.Warningf("Failed to convert event to point: %v", err)
133133
}
134+
135+
point.Tags["cluster_name"] = sink.c.ClusterName
136+
134137
dataPoints = append(dataPoints, *point)
135138
if len(dataPoints) >= maxSendBatchSize {
136139
sink.sendData(dataPoints)

metrics/sinks/influxdb/influxdb.go

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ func (sink *influxdbSink) ExportData(dataBatch *core.DataBatch) {
9393
point.Tags[key] = value
9494
}
9595
}
96+
97+
point.Tags["cluster_name"] = sink.c.ClusterName
98+
9699
dataPoints = append(dataPoints, point)
97100
if len(dataPoints) >= maxSendBatchSize {
98101
sink.sendData(dataPoints)
@@ -131,6 +134,7 @@ func (sink *influxdbSink) ExportData(dataBatch *core.DataBatch) {
131134
},
132135
Time: dataBatch.Timestamp.UTC(),
133136
}
137+
134138
for key, value := range metricSet.Labels {
135139
if value != "" {
136140
point.Tags[key] = value
@@ -141,6 +145,7 @@ func (sink *influxdbSink) ExportData(dataBatch *core.DataBatch) {
141145
point.Tags[key] = value
142146
}
143147
}
148+
point.Tags["cluster_name"] = sink.c.ClusterName
144149

145150
dataPoints = append(dataPoints, point)
146151
if len(dataPoints) >= maxSendBatchSize {

0 commit comments

Comments
 (0)