Collect Sidekiq metrics
        :return:
968958
def collect(self):
        
        if redis is None:
            self.log.error('Unable to import module redis')
            return {}

        try:
            for redis_client, port, db in self.get_redis_client():
                try:
                    self.publish_queue_length(redis_client, port, db)
                    self.publish_schedule_length(redis_client, port, db)
                    self.publish_retry_length(redis_client, port, db)
                except Exception as execption:
                    self.log.error(execption)
        except Exception as execption:
            self.log.error(execption)
536251
def collect(self):
        
        if not os.access(self.PROC, os.R_OK):
            return False

        # Open PROC file
        file = open(self.PROC, 'r')

        # Get data
        for line in file:

            if line.startswith('ctxt') or line.startswith('processes'):
                data = line.split()
                metric_name = data[0]
                metric_value = int(data[1])
                metric_value = int(self.derivative(metric_name,
                                                   long(metric_value),
                                                   counter))
                self.publish(metric_name, metric_value)

            if line.startswith('procs_') or line.startswith('btime'):
                data = line.split()
                metric_name = data[0]
                metric_value = int(data[1])
                self.publish(metric_name, metric_value)

        # Close file
        file.close()
31146
def collect(self):
        
        if not os.access(self.PROC, os.R_OK):
            return False

        # Open PROC file
        file = open(self.PROC, 'r')
        # Get data
        cpuCount = None
        for line in file:
            if not cpuCount:
                cpuCount = len(line.split())
            else:
                data = line.strip().split(None, cpuCount + 2)
                data[0] = data[0].replace(':', '')

                if len(data) == 2:
                    metric_name = data[0]
                    metric_value = data[1]
                    self.publish(metric_name,
                                 self.derivative(metric_name,
                                                 long(metric_value),
                                                 counter))
                else:
                    if len(data[0]) == cpuCount + 1:
                        metric_name = data[0] + '.'
                    elif len(data[0]) == 3:
                        metric_name = (
                            ((data[-2] + ' ' +
                              data[-1]).replace(' ', '_')) + '.')
                    else:
                        metric_name = (
                            ((data[-2]).replace(' ', '_')) +
                            '.' +
                            ((data[-1]).replace(', ', '-').replace(' ', '_')) +
                            '.' + data[0] + '.')
                    total = 0
                    for index, value in enumerate(data):
                        if index == 0 or index >= cpuCount + 1:
                            continue

                        metric_name_node = metric_name + 'CPU' + str(index - 1)
                        value = int(self.derivative(metric_name_node,
                                                    long(value), counter))
                        total += value
                        self.publish(metric_name_node, value)

                    # Roll up value
                    metric_name_node = metric_name + 'total'
                    self.publish(metric_name_node, total)

        # Close file
        file.close()
977370
async def get_metrics(self, *tags):
        
        log.debug("Retrieving metrics for %s",
                  ', '.join(tags) if tags else "all units")

        metrics_facade = client.MetricsDebugFacade.from_connection(
            self.connection())

        entities = [client.Entity(tag) for tag in tags]
        metrics_result = await metrics_facade.GetMetrics(entities)

        metrics = collections.defaultdict(list)

        for entity_metrics in metrics_result.results:
            error = entity_metrics.error
            if error:
                if "is not a valid tag" in error:
                    raise ValueError(error.message)
                else:
                    raise Exception(error.message)

            for metric in entity_metrics.metrics:
                metrics[metric.unit].append(vars(metric))

        return metrics
49394
async def get_metrics(self):
        
        metrics = await self.model.get_metrics(self.tag)
        return metrics[self.name]
122108
def collect_snmp(self, device, host, port, community):
        

        # Set timestamp
        timestamp = time.time()

        for k, v in self.IODRIVE_STATS.items():
            # Get Metric Name and Value
            metricName = '.'.join([k])
            metricValue = int(self.get(v, host, port, community)[v])

            # Get Metric Path
            metricPath = '.'.join(['servers', host, device, metricName])

            # Create Metric
            metric = Metric(metricPath, metricValue, timestamp, 0)

            # Publish Metric
            self.publish_metric(metric)

        for k, v in self.IODRIVE_BYTE_STATS.items():
            # Get Metric Name and Value
            metricName = '.'.join([k])
            metricValue = int(self.get(v, host, port, community)[v])

            # Get Metric Path
            metricPath = '.'.join(['servers', host, device, metricName])

            # Create Metric
            metric = Metric(metricPath, metricValue, timestamp, 0)

            # Publish Metric
            self.publish_metric(metric)
1080354
@Override
    protected void collectMetrics(final Metrics metrics) {
        for (final JvmMetricsCollector collector : _collectorsEnabled) {
            collector.collect(metrics, _managementFactory);
        }
    }
946402
def collect_metrics(self, instance):
        
        i_key = self._instance_key(instance)
        if not self.mor_cache.contains(i_key):
            self.log.debug("Not collecting metrics for instance '{}', nothing to do yet.".format(i_key))
            return

        vm_count = 0
        custom_tags = instance.get('tags', [])
        tags = ["vcenter_server:{}".format(ensure_unicode(instance.get('name')))] + custom_tags

        n_mors = self.mor_cache.instance_size(i_key)
        if not n_mors:
            self.gauge('vsphere.vm.count', vm_count, tags=tags)
            self.log.debug("No Mor objects to process for instance '{}', skip...".format(i_key))
            return

        self.log.debug("Collecting metrics for {} mors".format(ensure_unicode(n_mors)))

        # Request metrics for several objects at once. We can limit the number of objects with batch_size
        # If batch_size is 0, process everything at once
        batch_size = self.batch_morlist_size or n_mors
        for batch in self.mor_cache.mors_batch(i_key, batch_size):
            query_specs = []
            for _, mor in iteritems(batch):
                if mor['mor_type'] == 'vm':
                    vm_count += 1
                if mor['mor_type'] not in REALTIME_RESOURCES and ('metrics' not in mor or not mor['metrics']):
                    continue

                query_spec = vim.PerformanceManager.QuerySpec()
                query_spec.entity = mor["mor"]
                query_spec.intervalId = mor["interval"]
                query_spec.maxSample = 1
                if mor['mor_type'] in REALTIME_RESOURCES:
                    query_spec.metricId = self.metadata_cache.get_metric_ids(i_key)
                else:
                    query_spec.metricId = mor["metrics"]
                query_specs.append(query_spec)

            if query_specs:
                self.pool.apply_async(self._collect_metrics_async, args=(instance, query_specs))

        self.gauge('vsphere.vm.count', vm_count, tags=tags)
1224512
def collect_results(self) -> Optional[Tuple[int, Dict[str, float]]]:
        
        self.wait_to_finish()
        if self.decoder_metric_queue.empty():
            if self._results_pending:
                self._any_process_died = True
            self._results_pending = False
            return None
        decoded_checkpoint, decoder_metrics = self.decoder_metric_queue.get()
        assert self.decoder_metric_queue.empty()
        self._results_pending = False
        logger.info("Decoder-%d finished: %s", decoded_checkpoint, decoder_metrics)
        return decoded_checkpoint, decoder_metrics
728017
def _make_metric_list_to_collect(self, instance, custom_metrics):
        
        metrics_to_collect = []
        for name, counter_name, instance_name in self.METRICS:
            try:
                sql_type, base_name = self.get_sql_type(instance, counter_name)
                cfg = {}
                cfg['name'] = name
                cfg['counter_name'] = counter_name
                cfg['instance_name'] = instance_name

                metrics_to_collect.append(
                    self.typed_metric(instance, cfg, DEFAULT_PERFORMANCE_TABLE, base_name, None, sql_type, None)
                )
            except SQLConnectionError:
                raise
            except Exception:
                self.log.warning("Can't load the metric {}, ignoring".format(name), exc_info=True)
                continue

        # Load any custom metrics from conf.d/sqlserver.yaml
        for row in custom_metrics:
            db_table = row.get('table', DEFAULT_PERFORMANCE_TABLE)
            if db_table not in self.valid_tables:
                self.log.error('{} has an invalid table name: {}'.format(row['name'], db_table))
                continue

            if db_table == DEFAULT_PERFORMANCE_TABLE:
                user_type = row.get('type')
                if user_type is not None and user_type not in VALID_METRIC_TYPES:
                    self.log.error('{} has an invalid metric type: {}'.format(row['name'], user_type))
                sql_type = None
                try:
                    if user_type is None:
                        sql_type, base_name = self.get_sql_type(instance, row['counter_name'])
                except Exception:
                    self.log.warning("Can't load the metric {}, ignoring".format(row['name']), exc_info=True)
                    continue

                metrics_to_collect.append(
                    self.typed_metric(instance, row, db_table, base_name, user_type, sql_type, None)
                )

            else:
                for column in row['columns']:
                    metrics_to_collect.append(
                        self.typed_metric(instance, row, db_table, base_name, None, sql_type, column)
                    )

        instance_key = self._conn_key(instance, self.DEFAULT_DB_KEY)
        self.instances_metrics[instance_key] = metrics_to_collect
        simple_metrics = []
        fraction_metrics = []
        wait_stat_metrics = []
        vfs_metrics = []
        clerk_metrics = []
        self.log.debug("metrics to collect {}".format(str(metrics_to_collect)))
        for m in metrics_to_collect:
            if type(m) is SqlSimpleMetric:
                self.log.debug("Adding simple metric %s", m.sql_name)
                simple_metrics.append(m.sql_name)
            elif type(m) is SqlFractionMetric or type(m) is SqlIncrFractionMetric:
                self.log.debug("Adding fraction metric %s", m.sql_name)
                fraction_metrics.append(m.sql_name)
                fraction_metrics.append(m.base_name)
            elif type(m) is SqlOsWaitStat:
                self.log.debug("Adding SqlOsWaitStat metric {}".format(m.sql_name))
                wait_stat_metrics.append(m.sql_name)
            elif type(m) is SqlIoVirtualFileStat:
                self.log.debug("Adding SqlIoVirtualFileStat metric {}".format(m.sql_name))
                vfs_metrics.append(m.sql_name)
            elif type(m) is SqlOsMemoryClerksStat:
                self.log.debug("Adding SqlOsMemoryClerksStat metric {}".format(m.sql_name))
                clerk_metrics.append(m.sql_name)

        self.instances_per_type_metrics[instance_key]["SqlSimpleMetric"] = simple_metrics
        self.instances_per_type_metrics[instance_key]["SqlFractionMetric"] = fraction_metrics
        self.instances_per_type_metrics[instance_key]["SqlOsWaitStat"] = wait_stat_metrics
        self.instances_per_type_metrics[instance_key]["SqlIoVirtualFileStat"] = vfs_metrics
        self.instances_per_type_metrics[instance_key]["SqlOsMemoryClerksStat"] = clerk_metrics
1056119
def collect(self):
        
        if not os.access(self.PROC, os.R_OK):
            return False

        # Open PROC file
        file = open(self.PROC, 'r')

        # Get data
        for line in file:
            if line.startswith('slabinfo'):
                continue

            if line.startswith('#'):
                keys = line.split()[1:]
                continue

            data = line.split()

            for key in ['<active_objs>', '<num_objs>', '<objsize>',
                        '<objperslab>', '<pagesperslab>']:
                i = keys.index(key)
                metric_name = data[0] + '.' + key.replace(
                    '<', '').replace('>', '')
                metric_value = int(data[i])
                self.publish(metric_name, metric_value)

            for key in ['<limit>', '<batchcount>', '<sharedfactor>']:
                i = keys.index(key)
                metric_name = data[0] + '.tunables.' + key.replace(
                    '<', '').replace('>', '')
                metric_value = int(data[i])
                self.publish(metric_name, metric_value)

            for key in ['<active_slabs>', '<num_slabs>', '<sharedavail>']:
                i = keys.index(key)
                metric_name = data[0] + '.slabdata.' + key.replace(
                    '<', '').replace('>', '')
                metric_value = int(data[i])
                self.publish(metric_name, metric_value)

        # Close file
        file.close()
571760
def collect_metrics():
    
    def _register(action):
        handler = Handler.get(action)
        handler.add_predicate(partial(_restricted_hook, 'collect-metrics'))
        return action
    return _register
181886
def expose_endpoint(self):
        
        @self._app.route('/metrics', methods=['GET'])
        async def expose_metrics(request):
            return raw(self._get_metrics_data(),
                       content_type=CONTENT_TYPE_LATEST)
834181
def collect_and_report
      return unless ::Instana.config[:metrics][:enabled]

      payload = {}
      with_snapshot = false

      # Run through the registered collectors and
      # get all the metrics
      #
      @collectors.each do |c|
        metrics = c.collect
        if metrics
          payload[c.payload_key] = metrics
        else
          payload.delete(c.payload_key)
        end
      end

      # Every 5 minutes, send snapshot data as well
      if (Time.now - @last_snapshot) > 600
        with_snapshot = true
        payload.merge!(@snapshot)

        # Add in process related that could have changed since
        # snapshot was taken.
        p = { :pid => ::Instana.agent.report_pid }
        p[:name] = ::Instana::Util.get_app_name
        p[:exec_args] = ::Instana.agent.process[:arguments]
        payload.merge!(p)
      else
        payload = enforce_deltas(payload, @last_values)
      end

      if ENV['INSTANA_GEM_TEST']
        true
      else
        # Report all the collected goodies
        if ::Instana.agent.report_metrics(payload) && with_snapshot
          @last_snapshot = Time.now
        end
      end
    end
637410
def _collect_for_instance(self, instance, connection):
        """"""
        with connection.cursor() as cursor:
            for queue, metrics in self.get_queue_info(instance, cursor):
                for name, metric in metrics.items():
                    self.publish('.'.join((instance, queue, name)), metric)

        with connection.cursor() as cursor:
            consumers = self.get_consumer_info(instance, cursor)
            for queue, consumer, metrics in consumers:
                for name, metric in metrics.items():
                    key_parts = (instance, queue, 'consumers', consumer, name)
                    self.publish('.'.join(key_parts), metric)
630436
def metrics(self):
        
        masterThrp, backupThrp = self.getThroughputs(self.instances.masterId)
        r = self.instance_throughput_ratio(self.instances.masterId)
        m = [
            ("{} Monitor metrics:".format(self), None),
            ("Delta", self.Delta),
            ("Lambda", self.Lambda),
            ("Omega", self.Omega),
            ("instances started", self.instances.started),
            ("ordered request counts",
             {i: r[0] for i, r in self.numOrderedRequests.items()}),
            ("ordered request durations",
             {i: r[1] for i, r in self.numOrderedRequests.items()}),
            ("master request latencies", self.masterReqLatencies),
            ("client avg request latencies", {i: self.getLatency(i)
                                              for i in self.instances.ids}),
            ("throughput", {i: self.getThroughput(i)
                            for i in self.instances.ids}),
            ("master throughput", masterThrp),
            ("total requests", self.totalRequests),
            ("avg backup throughput", backupThrp),
            ("master throughput ratio", r)]
        return m
143686
def __get_metrics(self):
        
        esfilters_merge = None
        esfilters_abandon = None
        if self.esfilters:
            esfilters_merge = self.esfilters.copy()
            esfilters_abandon = self.esfilters.copy()

        merged = Merged(self.es_url, self.es_index,
                        start=self.start, end=self.end,
                        esfilters=esfilters_merge, interval=self.interval)

        abandoned = Abandoned(self.es_url, self.es_index,
                              start=self.start, end=self.end,
                              esfilters=esfilters_abandon, interval=self.interval)
        return (merged, abandoned)