(self, *args, **kwargs)
The base class for any Prometheus-based integration.
The base class for any Prometheus-based integration.
The base class for any Prometheus - based integration .
def __init__(self, *args, **kwargs):
        """
        The base class for any Prometheus-based integration.
        """
        args = list(args)
        default_instances = kwargs.pop('default_instances', None) or {}
        default_namespace = kwargs.pop('default_namespace', None)

        legacy_kwargs_in_args = args[4:]
        del args[4:]

        if len(legacy_kwargs_in_args) > 0:
            default_instances = legacy_kwargs_in_args[0] or {}
        if len(legacy_kwargs_in_args) > 1:
            default_namespace = legacy_kwargs_in_args[1]

        super(OpenMetricsBaseCheck, self).__init__(*args, **kwargs)
        self.config_map = {}
        self._http_handlers = {}
        self.default_instances = default_instances
        self.default_namespace = default_namespace

        # pre-generate the scraper configurations

        if 'instances' in kwargs:
            instances = kwargs['instances']
        elif len(args) == 4:
            # instances from agent 5 signature
            instances = args[3]
        elif isinstance(args[2], (tuple, list)):
            # instances from agent 6 signature
            instances = args[2]
        else:
            instances = None

        if instances is not None:
            for instance in instances:
                possible_urls = instance.get('possible_prometheus_urls')
                if possible_urls is not None:
                    for url in possible_urls:
                        try:
                            new_instance = deepcopy(instance)
                            new_instance.update({'prometheus_url': url})
                            scraper_config = self.get_scraper_config(new_instance)
                            response = self.send_request(url, scraper_config)
                            response.raise_for_status()
                            instance['prometheus_url'] = url
                            self.get_scraper_config(instance)
                            break
                        except (IOError, requests.HTTPError, requests.exceptions.SSLError) as e:
                            self.log.info("Couldn't connect to %s: %s, trying next possible URL.", url, str(e))
                    else:
                        self.log.error(
                            "The agent could connect to none of the following URL: %s.",
                            possible_urls,
                        )
                else:
                    self.get_scraper_config(instance)
def __init__ ( self , * args , * * kwargs ) : args = list ( args ) default_instances = kwargs . pop ( 'default_instances' , None ) or { } default_namespace = kwargs . pop ( 'default_namespace' , None ) legacy_kwargs_in_args = args [ 4 : ] del args [ 4 : ] if len ( legacy_kwargs_in_args ) > 0 : default_instances = legacy_kwargs_in_args [ 0 ] or { } if len ( legacy_kwargs_in_args ) > 1 : default_namespace = legacy_kwargs_in_args [ 1 ] super ( OpenMetricsBaseCheck , self ) . __init__ ( * args , * * kwargs ) self . config_map = { } self . _http_handlers = { } self . default_instances = default_instances self . default_namespace = default_namespace # pre-generate the scraper configurations if 'instances' in kwargs : instances = kwargs [ 'instances' ] elif len ( args ) == 4 : # instances from agent 5 signature instances = args [ 3 ] elif isinstance ( args [ 2 ] , ( tuple , list ) ) : # instances from agent 6 signature instances = args [ 2 ] else : instances = None if instances is not None : for instance in instances : possible_urls = instance . get ( 'possible_prometheus_urls' ) if possible_urls is not None : for url in possible_urls : try : new_instance = deepcopy ( instance ) new_instance . update ( { 'prometheus_url' : url } ) scraper_config = self . get_scraper_config ( new_instance ) response = self . send_request ( url , scraper_config ) response . raise_for_status ( ) instance [ 'prometheus_url' ] = url self . get_scraper_config ( instance ) break except ( IOError , requests . HTTPError , requests . exceptions . SSLError ) as e : self . log . info ( "Couldn't connect to %s: %s, trying next possible URL." , url , str ( e ) ) else : self . log . error ( "The agent could connect to none of the following URL: %s." , possible_urls , ) else : self . get_scraper_config ( instance )