(self, instance)
Collect metrics for the given gunicorn instance.
Collect metrics for the given gunicorn instance.
Collect metrics for the given gunicorn instance .
def check(self, instance):
        """Collect metrics for the given gunicorn instance."""
        self.log.debug("Running instance: %s", instance)
        custom_tags = instance.get('tags', [])

        # Validate the config.
        if not instance or self.PROC_NAME not in instance:
            raise GUnicornCheckError("instance must specify: %s" % self.PROC_NAME)

        # Load the gunicorn master procedure.
        proc_name = instance.get(self.PROC_NAME)
        master_procs = self._get_master_proc_by_name(proc_name)

        if master_procs:
            # Fetch the worker procs and count their states.
            worker_procs = self._get_workers_from_procs(master_procs)
            working, idle = self._count_workers(worker_procs)

            # if no workers are running, alert CRITICAL, otherwise OK
            msg = "%s working and %s idle workers for %s" % (working, idle, proc_name)
            tags = ['app:' + proc_name] + custom_tags
            if working == 0 and idle == 0:
                status = AgentCheck.CRITICAL
            else:
                status = AgentCheck.OK
                msg = None

            self.service_check(self.IS_RUNNING_SVC, status, tags=tags, message=msg)

            # Submit the data.
            self.log.debug("instance %s procs - working:%s idle:%s", proc_name, working, idle)
            self.gauge("gunicorn.workers", working, tags + self.WORKING_TAGS)
            self.gauge("gunicorn.workers", idle, tags + self.IDLE_TAGS)
        else:
            # process not found, it's dead.
            msg = "No gunicorn process with name %s found, skipping worker metrics" % proc_name
            self.service_check(
                self.IS_RUNNING_SVC,
                AgentCheck.CRITICAL,
                tags=['app:' + proc_name] + custom_tags,
                message=msg,
            )
            self.warning(msg)

        self._collect_metadata()
def check ( self , instance ) : self . log . debug ( "Running instance: %s" , instance ) custom_tags = instance . get ( 'tags' , [ ] ) # Validate the config. if not instance or self . PROC_NAME not in instance : raise GUnicornCheckError ( "instance must specify: %s" % self . PROC_NAME ) # Load the gunicorn master procedure. proc_name = instance . get ( self . PROC_NAME ) master_procs = self . _get_master_proc_by_name ( proc_name ) if master_procs : # Fetch the worker procs and count their states. worker_procs = self . _get_workers_from_procs ( master_procs ) working , idle = self . _count_workers ( worker_procs ) # if no workers are running, alert CRITICAL, otherwise OK msg = "%s working and %s idle workers for %s" % ( working , idle , proc_name ) tags = [ 'app:' + proc_name ] + custom_tags if working == 0 and idle == 0 : status = AgentCheck . CRITICAL else : status = AgentCheck . OK msg = None self . service_check ( self . IS_RUNNING_SVC , status , tags = tags , message = msg ) # Submit the data. self . log . debug ( "instance %s procs - working:%s idle:%s" , proc_name , working , idle ) self . gauge ( "gunicorn.workers" , working , tags + self . WORKING_TAGS ) self . gauge ( "gunicorn.workers" , idle , tags + self . IDLE_TAGS ) else : # process not found, it's dead. msg = "No gunicorn process with name %s found, skipping worker metrics" % proc_name self . service_check ( self . IS_RUNNING_SVC , AgentCheck . CRITICAL , tags = [ 'app:' + proc_name ] + custom_tags , message = msg , ) self . warning ( msg ) self . _collect_metadata ( )