Skip to content

Commit

Permalink
Added filesystem filter
Browse files Browse the repository at this point in the history
  • Loading branch information
bcakipp committed Aug 24, 2011
1 parent 2859e22 commit 79480f5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
15 changes: 14 additions & 1 deletion conf/diamond.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,20 @@ path = vmstat
[[DiskSpaceCollector]]
## Options for the Disk Space Collector
path = diskspace
filesystems = ext2, ext3, xfs, glusterfs, nfs

# filesystems to examine
filesystems = ext2, ext3, ext4, xfs, glusterfs, nfs

# exclude_filters
# A list of regex patterns
# A filesystem matching any of these patterns will be excluded from disk space
# metrics collection.
#
# Examples:
# exclude_filters = , # no exclude filters at all
# exclude_filters = ^/boot, ^/mnt # exclude everything that begins /boot or /mnt
# exclude_filters = m, # exclude everything that includes the letter "m"
exclude_filters = '^/export/home',

[[TCPStatsCollector]]
## Options for the TCP Stats Collector
Expand Down
14 changes: 14 additions & 0 deletions dist/diamond.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,22 @@ path = vmstat
[[DiskSpaceCollector]]
## Options for the Disk Space Collector
path = diskspace

# filesystems
# A list of file systems types to examine
# A filesystem type not in this list will be excluded from the disk space collector
filesystems = ext2, ext3, ext4, xfs, glusterfs, nfs

# exclude_filters
# A list of regex patterns
# A filesystem matching any of these patterns will be excluded from the disk space collector
#
# Examples:
# exclude_filters = , # no exclude filters at all
# exclude_filters = ^/boot, ^/mnt # exclude everything that begins /boot or /mnt
# exclude_filters = m, # exclude everything that includes the letter "m"
exclude_filters = '^/export/home',

[[TCPStatsCollector]]
## Options for the TCP Stats Collector
path = tcp
25 changes: 24 additions & 1 deletion src/collectors/systemcollectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,29 @@ class DiskSpaceCollector(diamond.collector.Collector):
# Call os.statvfs to get filesystme stats
STATVFS= [ 'block_size', 'block_size', 'blocks_used', 'blocks_free', 'blocks_avail', 'inodes_used', 'inodes_free', 'inodes_avail' ]

def is_filtered(self, mountpoint):
"""
Checks whether a given filesystem should be filtered from having metrics
gathered.
Returns True if the filesystem should be ignored.
Returns False if the filesystem should be considered.
"""
if 'exclude_filters' in self.config and len(self.config['exclude_filters']) > 0:

# Catch the most likely error, giving a string value in the config instead of a list
if isinstance(self.config['exclude_filters'], str):
self.config['exclude_filters'] = [ self.config['exclude_filters'] ]

# Loop through the list of filters, and for each check if the given mountpoint matches. Return True if so.
for f in self.config['exclude_filters']:
if re.search(f, mountpoint):
return True

# Return False if no filters matched, or no filters are defined
return False

def get_filesystem_list(self):
"""
Create a list of the mounted filesystems on the machine
Expand All @@ -420,7 +443,7 @@ def get_filesystem_list(self):
fd = open('/proc/mounts', 'r')
for line in fd:
l = line.split()
if l[2] in self.config['filesystems']:
if l[2] in self.config['filesystems'] and not self.is_filtered(l[1]):
s = os.stat(l[1])
major = str(os.major(s.st_dev))
minor = str(os.minor(s.st_dev))
Expand Down

0 comments on commit 79480f5

Please sign in to comment.