Home | History | Annotate | Download | only in stats
      1 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 import re
      7 import logging
      8 
      9 import common
     10 import requests
     11 from autotest_lib.client.common_lib.cros.graphite import autotest_stats
     12 from autotest_lib.site_utils.stats import registry
     13 
     14 
     15 # requests will log at INFO and DEBUG, which gets automatically enabled by
     16 # default by autotest code.  Let's silence these.
     17 requests_logger = logging.getLogger('requests.packages.urllib3.connectionpool')
     18 requests_logger.setLevel(logging.WARNING)
     19 
     20 
     21 @registry.loop_stat('sam')
     22 def rpcs_per_sec(server):
     23     """
     24     Scrape the requests/sec number off of the apache server-status page and
     25     submit it as a stat to statsd.
     26 
     27     @param server: The AFE server.
     28     """
     29     try:
     30         page = requests.get('http://%s/server-status' % server).text
     31     except requests.ConnectionError as e:
     32         logging.exception(e)
     33         return
     34 
     35     m = re.search("(\d+) requests/sec", page)
     36     if m:
     37         val = int(m.groups(0)[0])
     38         stat = autotest_stats.Gauge(server, bare=True)
     39         stat.send('requests_per_sec', val)
     40