Specify host mount prefix with envvar.

This commit is contained in:
John Engelman 2016-04-28 14:24:09 -05:00
parent 1390c22004
commit 5657ccf851
3 changed files with 16 additions and 2 deletions

View File

@ -48,6 +48,10 @@ based on _prefix_ in addition to globs. This means that a filter like
- disque: `host -> disque_host` - disque: `host -> disque_host`
- rethinkdb: `host -> rethinkdb_host` - rethinkdb: `host -> rethinkdb_host`
- The `disk` input plugin can now be configured with the `HOST_MOUNT_PREFIX` environment variable.
This value is prepended to any mountpaths discovered before retrieving stats.
It is not included on the report path. This is necessary for reporting host disk stats when running from within a container.
### Features ### Features
- [#1031](https://github.com/influxdata/telegraf/pull/1031): Jolokia plugin proxy mode. Thanks @saiello! - [#1031](https://github.com/influxdata/telegraf/pull/1031): Jolokia plugin proxy mode. Thanks @saiello!

View File

@ -16,6 +16,14 @@ https://en.wikipedia.org/wiki/Df_(Unix) for more details.
# mount_points = ["/"] # mount_points = ["/"]
``` ```
Additionally, the behavior of resolving the `mount_points` can be configured by using the `HOST_MOUNT_PREFIX` environment variable.
When present, this variable is prepended to the mountpoints discovered by the plugin before retrieving stats.
The prefix is stripped from the reported `path` in the measurement.
This settings is useful when running `telegraf` inside a docker container to report host machine metrics.
In this case, the host's root volume should be mounted into the container and the `HOST_MOUNT_PREFIX` and `HOST_ETC` environment variables set.
`docker run -v /:/hostfs:ro -e HOST_MOUNT_PREFIX=/hostfs -e HOST_ETC=/hostfs/etc telegraf-docker`
### Measurements & Fields: ### Measurements & Fields:
- disk - disk

View File

@ -81,8 +81,10 @@ func (s *systemPS) DiskUsage(
continue continue
} }
} }
if _, err := os.Stat(p.Mountpoint); err == nil { mountpoint := os.Getenv("HOST_MOUNT_PREFIX") + p.Mountpoint
du, err := disk.DiskUsage(p.Mountpoint) if _, err := os.Stat(mountpoint); err == nil {
du, err := disk.DiskUsage(mountpoint)
du.Path = p.Mountpoint
if err != nil { if err != nil {
return nil, err return nil, err
} }