

def _read_rrd(self, rrd_path, hostname, device_name):
    ' Main metric fetching method '
    metric_count = 0
    try:
        info = rrdtool.info(rrd_path)
    except Exception:
        self.log.exception(('Unable to read RRD file at %s' % rrd_path))
        return metric_count
    c_funcs = set([v for (k, v) in info.items() if k.endswith('.cf')])
    for c in list(c_funcs):
        last_ts_key = ('%s.%s' % (rrd_path, c))
        if (last_ts_key not in self.last_ts):
            self.last_ts[last_ts_key] = int(time.time())
            continue
        start = self.last_ts[last_ts_key]
        last_ts = start
        try:
            fetched = rrdtool.fetch(rrd_path, c, '--start', str(start))
        except rrdtool.error:
            self.log.warn(('Time %s out of range for %s' % (rrd_path, start)))
            return metric_count
        (start_ts, end_ts, interval) = fetched[0]
        metric_names = fetched[1]
        points = fetched[2]
        for (k, m_name) in enumerate(metric_names):
            m_name = self._format_metric_name(m_name, c)
            for (i, p) in enumerate(points):
                ts = (start_ts + (i * interval))
                if (p[k] is None):
                    continue
                val = self._transform_metric(m_name, p[k])
                self.gauge(m_name, val, hostname=hostname, device_name=device_name, timestamp=ts)
                metric_count += 1
                last_ts = (ts + interval)
        c_funcs.last_ts[last_ts_key] = last_ts
    return metric_count

dataset/ETHPy150Open serverdensity/sd-agent/checks.d/cacti.py Cacti._read_rrd/VarMisuse@345/505 `self`->`c_funcs`