Example #1
0
def top_queries(request, n, template='sqlcanon/top_queries.html'):
    try:
        n = int(n)

        column = request.GET.get('column', 'count')
        hostname = request.GET.get('hostname', None)
        schema = request.GET.get('schema', None)

        filter_dict = {}
        if hostname:
            filter_dict['hostname'] = hostname
        if schema:
            filter_dict['schema'] = schema

        qs = core.get_top_queries(n, column, filter_dict)

        return render_to_response(template, locals(),
            context_instance=RequestContext(request))
    except Exception, e:
        log.exception('%s' % (e,))
Example #2
0
    def get_top_queries(self, request, **kwargs):
        """
        Returns top 'n' queries.

        request.raw_post_data should be a JSON object in the form:
        {
            "n": 1,             # top limit
            "column": "",       # column to be used in ordering
            "hostname": ""      # hostname to be used in filtering
            "schema": ""        # schema to be used in filtering
        }
        """

        # allow posts only
        self.method_check(request, allowed=['post'])

        self.is_authenticated(request)

        data = {}
        try:
            post = json.loads(request.raw_post_data)
            n = int(post['n'])
            column = post['column']
            hostname = post.get('hostname', None)
            schema = post.get('schema', None)
            filter_dict = {}
            if hostname:
                filter_dict['hostname'] = hostname
            if schema:
                filter_dict['schema'] = schema
            qs = core.get_top_queries(n, column, filter_dict)
            objects = []
            for obj in qs:
                objects.append(obj)
            data['objects'] = objects
        except Exception, e:
            log.exception('EXCEPTION')
            data['error_message'] = '%s' % (e,)