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

Commit

Permalink
add cluster_name to influxdb sink
Browse files Browse the repository at this point in the history
  • Loading branch information
andyxning committed May 9, 2017
1 parent b109f11 commit f55b10c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type InfluxdbConfig struct {
WithFields bool
InsecureSsl bool
RetentionPolicy string
ClusterName string
}

func NewClient(c InfluxdbConfig) (InfluxdbClient, error) {
Expand Down Expand Up @@ -79,6 +80,7 @@ func BuildConfig(uri *url.URL) (*InfluxdbConfig, error) {
WithFields: false,
InsecureSsl: false,
RetentionPolicy: "0",
ClusterName: "default",
}

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

if len(opts["cluster_name"]) >= 1 {
config.ClusterName = opts["cluster_name"][0]
}

return &config, nil
}
1 change: 1 addition & 0 deletions docs/sink-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following options are available:
* `secure` - Connect securely to InfluxDB (default: `false`)
* `insecuressl` - Ignore SSL certificate validity (default: `false`)
* `withfields` - Use [InfluxDB fields](storage-schema.md#using-fields) (default: `false`)
* `cluster_name` - cluster name for different Kubernetes clusters. (default: `default`)

### Google Cloud Monitoring
This sink supports monitoring metrics only.
Expand Down
3 changes: 3 additions & 0 deletions events/sinks/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func (sink *influxdbSink) ExportEvents(eventBatch *core.EventBatch) {
if err != nil {
glog.Warningf("Failed to convert event to point: %v", err)
}

point.Tags["cluster_name"] = sink.c.ClusterName

dataPoints = append(dataPoints, *point)
if len(dataPoints) >= maxSendBatchSize {
sink.sendData(dataPoints)
Expand Down
5 changes: 5 additions & 0 deletions metrics/sinks/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (sink *influxdbSink) ExportData(dataBatch *core.DataBatch) {
},
Time: dataBatch.Timestamp.UTC(),
}

point.Tags["cluster_name"] = sink.c.ClusterName

dataPoints = append(dataPoints, point)
if len(dataPoints) >= maxSendBatchSize {
sink.sendData(dataPoints)
Expand Down Expand Up @@ -126,12 +129,14 @@ func (sink *influxdbSink) ExportData(dataBatch *core.DataBatch) {
},
Time: dataBatch.Timestamp.UTC(),
}

for key, value := range metricSet.Labels {
point.Tags[key] = value
}
for key, value := range labeledMetric.Labels {
point.Tags[key] = value
}
point.Tags["cluster_name"] = sink.c.ClusterName

dataPoints = append(dataPoints, point)
if len(dataPoints) >= maxSendBatchSize {
Expand Down

0 comments on commit f55b10c

Please sign in to comment.