def collect(self):
        """Collect statistics from /proc/self/mountstats.

        Currently, we do fairly naive parsing and do not actually check
        the statvers value returned by mountstats.
        """

        if str_to_bool(self.config['use_sudo']):
            if not os.access(self.config['sudo_cmd'], os.X_OK):
                self.log.error("Cannot find or exec %s"
                               % self.config['sudo_cmd'])
                return None

            command = [self.config['sudo_cmd'], '/bin/cat', self.MOUNTSTATS]
            p = subprocess.Popen(command,
                                 stdout=subprocess.PIPE).communicate()[0][:-1]
            lines = p.split("\n")

        else:
            if not os.access(self.MOUNTSTATS, os.R_OK):
                self.log.error("Cannot read path %s" % self.MOUNTSTATS)
                return None

            f = open(self.MOUNTSTATS)
            lines = f.readlines()
            f.close()

        path = None
        for line in lines:
            tokens = line.split()
            if len(tokens) == 0:
                continue

            if tokens[0] == 'device':
                path = tokens[4]

                skip = False
                if self.exclude_reg:
                    skip = self.exclude_reg.match(path)
                if self.include_reg:
                    skip = not self.include_reg.match(path)

                if skip:
                    self.log.debug("Ignoring %s", path)
                else:
                    self.log.debug("Keeping %s", path)

                path = path.replace('.', '_')
                path = path.replace('/', '_')
            elif skip:
                # If we are in a skip state, don't pay any attention to
                # anything that isn't the next device line
                continue
            elif tokens[0] == 'events:':
                for i in range(0, len(self.EVENTS_MAP)):
                    metric_name = "%s.events.%s" % (path, self.EVENTS_MAP[i])
                    metric_value = long(tokens[i + 1])
                    self.publish_counter(metric_name, metric_value)
            elif tokens[0] == 'bytes:':
                for i in range(0, len(self.BYTES_MAP)):
                    metric_name = "%s.bytes.%s" % (path, self.BYTES_MAP[i])
                    metric_value = long(tokens[i + 1])
                    self.publish_counter(metric_name, metric_value)
            elif tokens[0] == 'xprt:':
                proto = tokens[1]
                if not self.XPRT_MAP[proto]:
                    self.log.error("Unknown protocol %s", proto)
                    continue

                for i in range(0, len(self.XPRT_MAP[proto])):
                    metric_name = "%s.xprt.%s.%s" % (path, proto,
                                                     self.XPRT_MAP[proto][i])
                    metric_value = long(tokens[i + 2])
                    self.publish_counter(metric_name, metric_value)
            elif tokens[0][:-1] in self.RPCS_MAP:
                rpc = tokens[0][:-1]
                ops = long(tokens[1])
                rtt = long(tokens[7])
                exe = long(tokens[8])

                metric_fmt = "%s.rpc.%s.%s"
                ops_name = metric_fmt % (path, rpc.lower(), 'ops')
                rtt_name = metric_fmt % (path, rpc.lower(), 'rtt')
                exe_name = metric_fmt % (path, rpc.lower(), 'exe')

                self.publish_counter(ops_name, ops)
                self.publish_counter(rtt_name, rtt)
                self.publish_counter(exe_name, exe)
Collect statistics from /proc/self/mountstats.

        Currently, we do fairly naive parsing and do not actually check
        the statvers value returned by mountstats.
        
src/collectors/mountstats/mountstats.py