def render_GET(self, request):
        """Renders a GET request, by showing this nodes stats and children."""
        fullPath = request.path.split("/")
        if not fullPath[-1]:
            fullPath = fullPath[:-1]
        parts = fullPath[2:]
        statDict = util.lookup(scales.getStats(), parts)

        if statDict is None:
            request.setResponseCode(404)
            return "Path not found."

        if "query" in request.args:
            query = request.args["query"][0]
        else:
            query = None

        if "format" in request.args and request.args["format"][0] == "json":
            request.headers["content-type"] = "text/javascript; charset=UTF-8"
            formats.jsonFormat(request, statDict, query)
        elif "format" in request.args and request.args["format"][0] == "prettyjson":
            request.headers["content-type"] = "text/javascript; charset=UTF-8"
            formats.jsonFormat(request, statDict, query, pretty=True)
        else:
            formats.htmlHeader(request, "/" + "/".join(parts), self.serverName, query)
            formats.htmlFormat(request, tuple(parts), statDict, query)

        return ""
Exemple #2
0
def bottlestats(server_name, path=''):
    """Renders a GET request, by showing this nodes stats and children."""
    path = path.lstrip('/')
    parts = path.split('/')
    if not parts[0]:
        parts = parts[1:]
    stat_dict = util.lookup(scales.getStats(), parts)

    if stat_dict is None:
        abort(404, "Not Found")
        return

    output = StringIO()
    output_format = request.query.get('format', 'html')
    query = request.query.get('query', None)
    if output_format == 'json':
        response.content_type = "application/json"
        formats.jsonFormat(output, stat_dict, query)
    elif output_format == 'prettyjson':
        formats.jsonFormat(output, stat_dict, query, pretty=True)
        response.content_type = "application/json"
    else:
        formats.htmlHeader(output, '/' + path, server_name, query)
        formats.htmlFormat(output, tuple(parts), stat_dict, query)
        response.content_type = "text/html"

    return output.getvalue()
Exemple #3
0
  def get(self, path): # pylint: disable=W0221
    """Renders a GET request, by showing this nodes stats and children."""
    path = path or ''
    path = path.lstrip('/')
    parts = path.split('/')
    if not parts[0]:
      parts = parts[1:]
    statDict = util.lookup(scales.getStats(), parts)

    if statDict is None:
      self.set_status(404)
      self.finish('Path not found.')
      return

    outputFormat = self.get_argument('format', default='html')
    query = self.get_argument('query', default=None)
    if outputFormat == 'json':
      formats.jsonFormat(self, statDict, query)
    elif outputFormat == 'prettyjson':
      formats.jsonFormat(self, statDict, query, pretty=True)
    else:
      formats.htmlHeader(self, '/' + path, self.serverName, query)
      formats.htmlFormat(self, tuple(parts), statDict, query)

    return ''
Exemple #4
0
    def get(self, path):  # pylint: disable=W0221
        """Renders a GET request, by showing this nodes stats and children."""
        path = path or ''
        path = path.lstrip('/')
        parts = path.split('/')
        if not parts[0]:
            parts = parts[1:]
        statDict = util.lookup(scales.getStats(), parts)

        if statDict is None:
            self.set_status(404)
            self.finish('Path not found.')
            return

        outputFormat = self.get_argument('format', default='html')
        query = self.get_argument('query', default=None)
        if outputFormat == 'json':
            formats.jsonFormat(self, statDict, query)
        elif outputFormat == 'prettyjson':
            formats.jsonFormat(self, statDict, query, pretty=True)
        else:
            formats.htmlHeader(self, '/' + path, self.serverName, query)
            formats.htmlFormat(self, tuple(parts), statDict, query)

        return ''
Exemple #5
0
    def render_GET(self, request):
        """Renders a GET request, by showing this nodes stats and children."""
        fullPath = request.path.split('/')
        if not fullPath[-1]:
            fullPath = fullPath[:-1]
        parts = fullPath[2:]
        statDict = util.lookup(scales.getStats(), parts)

        if statDict is None:
            request.setResponseCode(404)
            return "Path not found."

        if 'query' in request.args:
            query = request.args['query'][0]
        else:
            query = None

        if 'format' in request.args and request.args['format'][0] == 'json':
            request.headers['content-type'] = 'text/javascript; charset=UTF-8'
            formats.jsonFormat(request, statDict, query)
        elif 'format' in request.args and request.args['format'][
                0] == 'prettyjson':
            request.headers['content-type'] = 'text/javascript; charset=UTF-8'
            formats.jsonFormat(request, statDict, query, pretty=True)
        else:
            formats.htmlHeader(request, '/' + '/'.join(parts), self.serverName,
                               query)
            formats.htmlFormat(request, tuple(parts), statDict, query)

        return ''
Exemple #6
0
def bottlestats(server_name, path=''):
    """Renders a GET request, by showing this nodes stats and children."""
    path = path.lstrip('/')
    parts = path.split('/')
    if not parts[0]:
        parts = parts[1:]
    stat_dict = util.lookup(scales.getStats(), parts)

    if stat_dict is None:
        abort(404, "Not Found")
        return

    output = StringIO()
    output_format = request.query.get('format', 'html')
    query = request.query.get('query', None)
    if output_format == 'json':
        response.content_type = "application/json"
        formats.jsonFormat(output, stat_dict, query)
    elif output_format == 'prettyjson':
        formats.jsonFormat(output, stat_dict, query, pretty=True)
        response.content_type = "application/json"
    else:
        formats.htmlHeader(output, '/' + path, server_name, query)
        formats.htmlFormat(output, tuple(parts), stat_dict, query)
        response.content_type = "text/html"

    return output.getvalue()
    def get(self, path):  # pylint: disable=W0221
        """Renders a GET request, by showing this nodes stats and children."""
        path = path or ""
        path = path.lstrip("/")
        parts = path.split("/")
        if not parts[0]:
            parts = parts[1:]
        statDict = util.lookup(scales.getStats(), parts)

        if statDict is None:
            self.set_status(404)
            self.finish("Path not found.")
            return

        outputFormat = self.get_argument("format", default="html")
        query = self.get_argument("query", default=None)
        if outputFormat == "json":
            formats.jsonFormat(self, statDict, query)
        elif outputFormat == "prettyjson":
            formats.jsonFormat(self, statDict, query, pretty=True)
        else:
            formats.htmlHeader(self, "/" + path, self.serverName, query)
            formats.htmlFormat(self, tuple(parts), statDict, query)

        return None
Exemple #8
0
 def testHtmlFormat(self):
   """Test generating HTML with Unicode values."""
   out = StringIO()
   formats.htmlFormat(out, statDict={'name': self.UNICODE_VALUE})
   result = out.getvalue()
   if six.PY3:
       self.assertTrue(self.UNICODE_VALUE in result)
   else:
       self.assertTrue(self.UNICODE_VALUE.encode('utf8') in result)
Exemple #9
0
 def testHtmlFormat(self):
     """Test generating HTML with Unicode values."""
     out = six.StringIO()
     formats.htmlFormat(out, statDict={'name': self.UNICODE_VALUE})
     result = out.getvalue()
     if six.PY2:
         value = self.UNICODE_VALUE.encode('utf8')
     else:
         value = self.UNICODE_VALUE
     self.assertTrue(value in result)
Exemple #10
0
    def __call__(self, environ, start_response):
        request = webob.Request(environ)
        if request.path_info.startswith(self.signature):
            query = request.GET.get('query')
            obj_type = request.GET.get('object_type')
            obj_address = request.GET.get('object_address')
            if obj_address:
                # Create a graph for the object
                leaking = [objgraph.at(int(obj_address))]
                filename = tempfile.mktemp(suffix='.png')
                objgraph.show_refs(leaking, filename=filename)
                output = open(filename, 'r').read()
                os.unlink(filename)
                start_response(
                    '200 Ok',
                    [('Content-Type', 'image/png')])
                return output

            output = StringIO()
            leaking = objgraph.get_leaking_objects()
            formats.htmlHeader(output, self.signature, request.host_url, query)
            output.write('<h3>Memory usage</h3>')
            output.write('<table>' + ''.join(
                    map(lambda info: MEMORY_LINE.format(*info),
                        objgraph.most_common_types(10, leaking))) +
                         '</table>')
            if obj_type:
                # Display detail about leaking objects of a given type.
                output.write('<h4>Memory detail for %s</h4>' % obj_type)
                output.write('<ul>')
                for obj in leaking:
                    if type(obj).__name__ == obj_type:
                        output.write(OBJECT_LINE.format(
                                id(obj), cgi.escape(str(obj))))
                output.write('</ul>')
            output.write('<h3>Timing</h3>')
            formats.htmlFormat(output, query=query)
            start_response(
                '200 Ok',
                [('Content-Type', 'text/html; charset=UTF8')])
            return output.getvalue()
        scale = self.find(request.path_info)
        scale.requests.mark()
        with scale.latency.time():
            response = request.get_response(self.app)
        result = scale.statuses(response.status_int)
        if result is not None:
            result.mark()
        start_response(
            response.status,
            [a for a in response.headers.iteritems()])
        return response.app_iter
Exemple #11
0
def statsHandler(serverName, path=''):
  """Renders a GET request, by showing this nodes stats and children."""
  path = path.lstrip('/')
  parts = path.split('/')
  if not parts[0]:
    parts = parts[1:]
  statDict = util.lookup(scales.getStats(), parts)

  if statDict is None:
    abort(404, 'No stats found with path /%s' % '/'.join(parts))

  output = StringIO()
  outputFormat = request.args.get('format', 'html')
  query = request.args.get('query', None)
  if outputFormat == 'json':
    formats.jsonFormat(output, statDict, query)
  elif outputFormat == 'prettyjson':
    formats.jsonFormat(output, statDict, query, pretty=True)
  else:
    formats.htmlHeader(output, '/' + path, serverName, query)
    formats.htmlFormat(output, tuple(parts), statDict, query)

  return output.getvalue()
Exemple #12
0
def statsHandler(serverName, path=""):
    """Renders a GET request, by showing this nodes stats and children."""
    path = path.lstrip("/")
    parts = path.split("/")
    if not parts[0]:
        parts = parts[1:]
    statDict = util.lookup(scales.getStats(), parts)

    if statDict is None:
        abort(404)
        return

    output = StringIO()
    outputFormat = request.args.get("format", "html")
    query = request.args.get("query", None)
    if outputFormat == "json":
        formats.jsonFormat(output, statDict, query)
    elif outputFormat == "prettyjson":
        formats.jsonFormat(output, statDict, query, pretty=True)
    else:
        formats.htmlHeader(output, "/" + path, serverName, query)
        formats.htmlFormat(output, tuple(parts), statDict, query)

    return output.getvalue()