def check(self, instance):
        if rrdtool is None:
            raise Exception("Unable to import python rrdtool module")

        # Load the instance config
        config = self._get_config(instance)

        connection = pymysql.connect(config.host, config.user, config.password, config.db)

        self.log.debug("Connected to MySQL to fetch Cacti metadata")

        # Get whitelist patterns, if available
        patterns = self._get_whitelist_patterns(config.whitelist)

        # Fetch the RRD metadata from MySQL
        rrd_meta = self._fetch_rrd_meta(connection, config.rrd_path, patterns, config.field_names)

        # Load the metrics from each RRD, tracking the count as we go
        metric_count = 0
        for hostname, device_name, rrd_path in rrd_meta:
            m_count = self._read_rrd(rrd_path, hostname, device_name)
            metric_count += m_count

        self.gauge('cacti.metrics.count', metric_count)
dataset/ETHPy150Open serverdensity/sd-agent/checks.d/cacti.py/Cacti.check/original