Skip to content

Commit

Permalink
Add stripped-mount-point-paths argument
Browse files Browse the repository at this point in the history
* accepts a regex pattern to be removed from the mountpoints
exported by the filesystem collector.
* addresses issue prometheus#66
  • Loading branch information
dan-cleinmark committed Mar 21, 2016
1 parent bce2e0c commit e707514
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ docker pull prom/node-exporter

docker run -d -p 9100:9100 --net="host" prom/node-exporter
```

Note that Docker (and containers in general) is designed to separate a container's runtime from the
host. If you are running the node_exporter inside of Docker to export statistics about the host,
use a command similar to:

docker run -d -p 9100:9100 -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --net="host" prom/node-exporter -collector.procfs /host/proc -collector.sysfs /host/proc -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc|rootfs/sys|rootfs/var/lib|)($|/)" -collector.filesystem.stripped-mount-point-paths "^/rootfs"

See [Setting up the Node Exporter (in Docker)](https://www.digitalocean.com/community/tutorials/how-to-install-prometheus-using-docker-on-ubuntu-14-04#step-2-—-setting-up-node-exporter)
for more details.
27 changes: 18 additions & 9 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

// Arch-dependent implementation must define:
// * defIgnoredMountPoints
// * defStrippedMountPointPaths
// * filesystemLabelNames
// * filesystemCollector.GetStats

Expand All @@ -34,11 +35,17 @@ var (
defIgnoredMountPoints,
"Regexp of mount points to ignore for filesystem collector.")

strippedMountPointPaths = flag.String(
"collector.filesystem.stripped-mount-point-paths",
defStrippedMountPointPaths,
"Regexp of mount point paths to remove for filesystem collector.")

filesystemLabelNames = []string{"device", "mountpoint", "fstype"}
)

type filesystemCollector struct {
ignoredMountPointsPattern *regexp.Regexp
ignoredMountPointsPattern *regexp.Regexp
strippedMountPointPathsPattern *regexp.Regexp
sizeDesc, freeDesc, availDesc,
filesDesc, filesFreeDesc, roDesc *prometheus.Desc
}
Expand All @@ -56,7 +63,8 @@ func init() {
// Filesystems stats.
func NewFilesystemCollector() (Collector, error) {
subsystem := "filesystem"
pattern := regexp.MustCompile(*ignoredMountPoints)
ignoredMountPointsPattern := regexp.MustCompile(*ignoredMountPoints)
strippedMountPointPathsPattern := regexp.MustCompile(*strippedMountPointPaths)

sizeDesc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "size"),
Expand Down Expand Up @@ -95,13 +103,14 @@ func NewFilesystemCollector() (Collector, error) {
)

return &filesystemCollector{
ignoredMountPointsPattern: pattern,
sizeDesc: sizeDesc,
freeDesc: freeDesc,
availDesc: availDesc,
filesDesc: filesDesc,
filesFreeDesc: filesFreeDesc,
roDesc: roDesc,
ignoredMountPointsPattern: ignoredMountPointsPattern,
strippedMountPointPathsPattern: strippedMountPointPathsPattern,
sizeDesc: sizeDesc,
freeDesc: freeDesc,
availDesc: availDesc,
filesDesc: filesDesc,
filesFreeDesc: filesFreeDesc,
roDesc: roDesc,
}, nil
}

Expand Down
18 changes: 15 additions & 3 deletions collector/filesystem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ package collector
import (
"bufio"
"os"
"regexp"
"strings"
"syscall"

"github.com/prometheus/common/log"
)

const (
defIgnoredMountPoints = "^/(sys|proc|dev)($|/)"
ST_RDONLY = 0x1
defIgnoredMountPoints = "^/(sys|proc|dev)($|/)"
defStrippedMountPointPaths = ""
ST_RDONLY = 0x1
)

var (
rDoubleSlash = regexp.MustCompile("//")
)

type filesystemDetails struct {
Expand Down Expand Up @@ -60,7 +66,13 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
ro = 1
}

labelValues := []string{mpd.device, mpd.mountPoint, mpd.fsType}
mountPoint := rDoubleSlash.ReplaceAllString(
c.strippedMountPointPathsPattern.ReplaceAllString(mpd.mountPoint, "/"),
"/")
labelValues := []string{
mpd.device,
mountPoint,
mpd.fsType}
stats = append(stats, filesystemStats{
labelValues: labelValues,
size: float64(buf.Blocks) * float64(buf.Bsize),
Expand Down

3 comments on commit e707514

@zerthimon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dan-cleinmark Howdy!
Would you like to do a PR to the upstream node-exporter ?

@dan-cleinmark
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @zerthimon - we actually abandoned this because of confusion between the host and container when running the node_exporter as a container. Feel free to use it, but we ended up keeping the monitoring agent on the host.

@zerthimon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dan-cleinmark thanks a lot for the info and the code!

Could you please elaborate on what problems have you faced when running patched node-exporter in a container (having '/rootfs' stripped from mounts). What exactly made you switch to a host-based monitoring agent ?
I'm currently in the process of decision which path to take, so your experience would be most valuable!
Thanks!

Please sign in to comment.