(self, section=None)
Collect HAProxy Stats
Collect HAProxy Stats
Collect HAProxy Stats
def _collect(self, section=None):
        """
        Collect HAProxy Stats
        """
        if self.config['method'] == 'http':
            csv_data = self.http_get_csv_data(section)
        elif self.config['method'] == 'unix':
            csv_data = self.unix_get_csv_data()
        else:
            self.log.error("Unknown collection method: %s",
                           self.config['method'])
            csv_data = []

        data = list(csv.reader(csv_data))
        headings = self._generate_headings(data[0])
        section_name = section and self._sanitize(section.lower()) + '.' or ''

        for row in data:
            if ((self._get_config_value(section, 'ignore_servers') and
                 row[1].lower() not in ['frontend', 'backend'])):
                continue

            part_one = self._sanitize(row[0].lower())
            part_two = self._sanitize(row[1].lower())
            metric_name = '%s%s.%s' % (section_name, part_one, part_two)

            for index, metric_string in enumerate(row):
                try:
                    metric_value = float(metric_string)
                except ValueError:
                    continue

                stat_name = '%s.%s' % (metric_name, headings[index])
                self.publish(stat_name, metric_value, metric_type='GAUGE')
def _collect ( self , section = None ) : if self . config [ 'method' ] == 'http' : csv_data = self . http_get_csv_data ( section ) elif self . config [ 'method' ] == 'unix' : csv_data = self . unix_get_csv_data ( ) else : self . log . error ( "Unknown collection method: %s" , self . config [ 'method' ] ) csv_data = [ ] data = list ( csv . reader ( csv_data ) ) headings = self . _generate_headings ( data [ 0 ] ) section_name = section and self . _sanitize ( section . lower ( ) ) + '.' or '' for row in data : if ( ( self . _get_config_value ( section , 'ignore_servers' ) and row [ 1 ] . lower ( ) not in [ 'frontend' , 'backend' ] ) ) : continue part_one = self . _sanitize ( row [ 0 ] . lower ( ) ) part_two = self . _sanitize ( row [ 1 ] . lower ( ) ) metric_name = '%s%s.%s' % ( section_name , part_one , part_two ) for index , metric_string in enumerate ( row ) : try : metric_value = float ( metric_string ) except ValueError : continue stat_name = '%s.%s' % ( metric_name , headings [ index ] ) self . publish ( stat_name , metric_value , metric_type = 'GAUGE' )