add server hostname for each measurements

This commit is contained in:
aaronjheng 2016-08-08 10:17:38 +08:00
parent 49988b15a3
commit 8955f54266
1 changed files with 9 additions and 6 deletions

View File

@ -28,7 +28,8 @@ type Docker struct {
PerDevice bool `toml:"perdevice"` PerDevice bool `toml:"perdevice"`
Total bool `toml:"total"` Total bool `toml:"total"`
client DockerClient client DockerClient
server_name string
} }
// DockerClient interface, useful for testing // DockerClient interface, useful for testing
@ -147,6 +148,7 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
if err != nil { if err != nil {
return err return err
} }
d.server_name = info.Name
fields := map[string]interface{}{ fields := map[string]interface{}{
"n_cpus": info.NCPU, "n_cpus": info.NCPU,
@ -159,11 +161,11 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
// Add metrics // Add metrics
acc.AddFields("docker", acc.AddFields("docker",
fields, fields,
nil, map[string]string{"server_name": d.server_name},
now) now)
acc.AddFields("docker", acc.AddFields("docker",
map[string]interface{}{"memory_total": info.MemTotal}, map[string]interface{}{"memory_total": info.MemTotal},
map[string]string{"unit": "bytes"}, map[string]string{"unit": "bytes", "server_name": d.server_name},
now) now)
// Get storage metrics // Get storage metrics
for _, rawData := range info.DriverStatus { for _, rawData := range info.DriverStatus {
@ -177,7 +179,7 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
// pool blocksize // pool blocksize
acc.AddFields("docker", acc.AddFields("docker",
map[string]interface{}{"pool_blocksize": value}, map[string]interface{}{"pool_blocksize": value},
map[string]string{"unit": "bytes"}, map[string]string{"unit": "bytes", "server_name": d.server_name},
now) now)
} else if strings.HasPrefix(name, "data_space_") { } else if strings.HasPrefix(name, "data_space_") {
// data space // data space
@ -192,13 +194,13 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
if len(dataFields) > 0 { if len(dataFields) > 0 {
acc.AddFields("docker_data", acc.AddFields("docker_data",
dataFields, dataFields,
map[string]string{"unit": "bytes"}, map[string]string{"unit": "bytes", "server_name": d.server_name},
now) now)
} }
if len(metadataFields) > 0 { if len(metadataFields) > 0 {
acc.AddFields("docker_metadata", acc.AddFields("docker_metadata",
metadataFields, metadataFields,
map[string]string{"unit": "bytes"}, map[string]string{"unit": "bytes", "server_name": d.server_name},
now) now)
} }
return nil return nil
@ -225,6 +227,7 @@ func (d *Docker) gatherContainer(
imageVersion = imageParts[1] imageVersion = imageParts[1]
} }
tags := map[string]string{ tags := map[string]string{
"server_name": d.server_name,
"container_name": cname, "container_name": cname,
"container_image": imageName, "container_image": imageName,
"container_version": imageVersion, "container_version": imageVersion,