Maintain some stats about our requests.
333599
def update_stats(self, responses, no_responses):
        
        slowest_rtt = 0.0
        slowest_ip  = None
        fastest_rtt = 9999999.9
        fastest_ip  = None
        rtt_total   = 0.0

        for ip, rtt in responses.items():
            rtt_total += rtt
            if rtt > slowest_rtt:
                slowest_rtt = rtt
                slowest_ip  = ip
            elif rtt < fastest_rtt:
                fastest_rtt = rtt
                fastest_ip  = ip

        sorted_rtts = sorted(responses.values())
        l           = len(sorted_rtts)
        if l == 0:
            median_rtt = 0.0
        elif l % 2 == 1:
            # Odd number: Median is the middle element
            median_rtt = sorted_rtts[int(l / 2)]
        else:
            # Even number (average between two middle elements)
            median_rtt = (sorted_rtts[int(l / 2) - 1] +
                          sorted_rtts[int(l / 2)]) / 2.0

        now = datetime.datetime.now().isoformat()
        m = {
            "time" : now,
            "num_responses" : len(responses),
            "num_no_responses" : len(no_responses),
            "slowest" : {
                "ip"  : slowest_ip,
                "rtt" : slowest_rtt
            },
            "fastest" : {
                "ip"  : fastest_ip,
                "rtt" : fastest_rtt
            },
            "average_rtt" : rtt_total / len(responses),
            "median_rtt" : median_rtt
        }

        self.measurements.insert(0, m)
        self.measurements = self.measurements[:self.max_num_measurements]
613999
def write_stats (self):
        """"""
        self.writeln(u'<br/><i>%s</i><br/>' % _("Statistics"))
        if self.stats.number > 0:
            self.writeln(_(
              "Content types: %(image)d image, %(text)d text, %(video)d video, "
              "%(audio)d audio, %(application)d application, %(mail)d mail"
              " and %(other)d other.") % self.stats.link_types)
            self.writeln(u"<br/>")
            self.writeln(_("URL lengths: min=%(min)d, max=%(max)d, avg=%(avg)d.") %
                         dict(min=self.stats.min_url_length,
                         max=self.stats.max_url_length,
                         avg=self.stats.avg_url_length))
        else:
            self.writeln(_("No statistics available since no URLs were checked."))
        self.writeln(u"<br/>")
1209169
def aggregate(request)
      @trackers.each do |tracker|
        tracker.update(request) if tracker.should_update?(request)
      end
    end
682735
def update(self):
        """"""
        # Init new stats
        stats = self.get_init_value()

        # Grab quicklook stats: CPU, MEM and SWAP
        if self.input_method == 'local':
            # Get the latest CPU percent value
            stats['cpu'] = cpu_percent.get()
            stats['percpu'] = cpu_percent.get(percpu=True)
            # Use the psutil lib for the memory (virtual and swap)
            stats['mem'] = psutil.virtual_memory().percent
            stats['swap'] = psutil.swap_memory().percent
        elif self.input_method == 'snmp':
            # Not available
            pass

        # Optionnaly, get the CPU name/frequency
        # thanks to the cpuinfo lib: https://github.com/workhorsy/py-cpuinfo
        if cpuinfo_tag:
            cpu_info = cpuinfo.get_cpu_info()
            #  Check cpu_info (issue #881)
            if cpu_info is not None:
                stats['cpu_name'] = cpu_info.get('brand', 'CPU')
                if 'hz_actual_raw' in cpu_info:
                    stats['cpu_hz_current'] = cpu_info['hz_actual_raw'][0]
                if 'hz_advertised_raw' in cpu_info:
                    stats['cpu_hz'] = cpu_info['hz_advertised_raw'][0]

        # Update the stats
        self.stats = stats

        return self.stats
651425
function pollStats(ms) {
    request('./stats', function (data) {
        o('li.inactive .count').text(data.inactiveCount);
        o('li.active .count').text(data.activeCount);
        o('li.complete .count').text(data.completeCount);
        o('li.failed .count').text(data.failedCount);
        o('li.delayed .count').text(data.delayedCount);
        setTimeout(function () {
            pollStats(ms);
        }, ms);
    });
}
594962
def _calculate_num_queries(self):
        
        request_totals = self._totals("request")
        response_totals = self._totals("response")

        return request_totals[2] + response_totals[2]
1211679
def info_post_request(self, node, info):
        """"""
        for agent in node.neighbors():
            node.transmit(what=info, to_whom=agent)
1042059
def update(self, input_stats=None):
        """"""
        input_stats = input_stats or {}

        # Force update of all the stats
        super(GlancesStatsServer, self).update()

        # Build all_stats variable (concatenation of all the stats)
        self.all_stats = self._set_stats(input_stats)
803065
def _add_response_info(self):
        """"""
        self.charset = httputil.get_charset(self.headers)
        self.set_content_type()
        self.add_size_info()
613135
def log_stats(self):
        """"""
        if not self.stats.get('counts'):
            if self.consumers:
                LOGGER.info('Did not receive any stats data from children')
            return

        if self.poll_data['processes']:
            LOGGER.warning('%i process(es) did not respond with stats: %r',
                           len(self.poll_data['processes']),
                           self.poll_data['processes'])

        if self.stats['counts']['processes'] > 1:
            LOGGER.info('%i consumers processed %i messages with %i errors',
                        self.stats['counts']['processes'],
                        self.stats['counts']['processed'],
                        self.stats['counts']['failed'])

        for key in self.stats['consumers'].keys():
            LOGGER.info('%i %s %s processed %i messages with %i errors',
                        self.stats['consumers'][key]['processes'], key,
                        self.consumer_keyword(self.stats['consumers'][key]),
                        self.stats['consumers'][key]['processed'],
                        self.stats['consumers'][key]['failed'])
600598
private void updateStats() {
        EhcacheStats stats = getProducerStats();
        Statistics statistics = underlyingCache.getStatistics();
        double accesses = statistics.getCacheHits() + statistics.getCacheMisses();
        double hitRatio = accesses != 0 ? statistics.getCacheHits() / accesses : 0;

        stats.getStatisticsAccuracy().setValueAsString(statistics.getStatisticsAccuracyDescription());
        stats.getHitRatio().setValueAsDouble(hitRatio);
        stats.getHits().setValueAsLong(statistics.getCacheHits());
        stats.getMisses().setValueAsLong(statistics.getCacheMisses());
        stats.getElements().setValueAsLong(statistics.getObjectCount());

        stats.getInMemoryHits().setValueAsLong(statistics.getInMemoryHits());
        stats.getInMemoryMisses().setValueAsLong(statistics.getInMemoryMisses());
        stats.getInMemoryElements().setValueAsLong(statistics.getMemoryStoreObjectCount());

        stats.getOnDiskHits().setValueAsLong(statistics.getOnDiskHits());
        stats.getOnDiskMisses().setValueAsLong(statistics.getOnDiskMisses());
        stats.getOnDiskElements().setValueAsLong(statistics.getDiskStoreObjectCount());

        stats.getOffHeapHits().setValueAsLong(statistics.getOffHeapHits());
        stats.getOffHeapMisses().setValueAsLong(statistics.getOffHeapMisses());
        stats.getOffHeapElements().setValueAsLong(statistics.getOffHeapStoreObjectCount());

        stats.getAverageGetTime().setValueAsDouble(statistics.getAverageGetTime());
        stats.getAverageSearchTime().setValueAsLong(statistics.getAverageSearchTime());

        stats.getSearchesPerSecond().setValueAsLong(statistics.getSearchesPerSecond());
        stats.getEvictionCount().setValueAsLong(statistics.getEvictionCount());
        stats.getWriterQueueLength().setValueAsLong(statistics.getWriterQueueSize());
    }
1308022
def ensure_hbounds(self):
        """"""
        self.cursor.x = min(max(0, self.cursor.x), self.columns - 1)
302733
def _patch_stats_request(request):
    '''
    '''
    filt = request.get('filter', {})
    if not filt.get('config', None):
        request['filter'] = filters.date_range('acquired',
                                               gt='1970-01-01T00:00:00Z')
    return request
32116
def update(self):
        """"""
        # Init new stats
        stats = self.get_init_value()

        if self.input_method == 'local':
            # Update stats using the standard system lib
            stats = self.glancesgrabhddtemp.get()

        else:
            # Update stats using SNMP
            # Not available for the moment
            pass

        # Update the stats
        self.stats = stats

        return self.stats
707413
public void updateMetrics() {
    Counters counters = getCounters();
    for (Counters.Group group : counters) {
      jobMetrics.setTag("group", group.getDisplayName());
      for (Counters.Counter counter : group) {
        jobMetrics.setTag("counter", counter.getDisplayName());
        jobMetrics.setMetric("value", (float) counter.getCounter());
        jobMetrics.update();
      }
    }
  }
220918
protected void recordSuccessMetrics(ApiResponse response) {
        requestMetric.setResponseCode(response.getCode());
        requestMetric.setResponseMessage(response.getMessage());
    }
743589
def __display_stats(self):
        """"""

        self.display('unify.tmpl', processed=self.total,
                     matched=self.matched,
                     unified=self.total - self.matched)