コード例 #1
0
ファイル: models.py プロジェクト: emedez/sqlcanon
    def canonicalized_statement_hostname_hash_hex_str(self):
        """Returns canonicalized statement-hostname hash as hex string."""

        return utils.int_to_hex_str(
            self.canonicalized_statement_hostname_hash)
コード例 #2
0
ファイル: sqlcanon_tags.py プロジェクト: emedez/sqlcanon
def hex_str(value):
    """Template filter for displaying hex string equivalent of value."""

    int_value = int(value)
    return utils.int_to_hex_str(int_value)
コード例 #3
0
ファイル: models.py プロジェクト: emedez/sqlcanon
 def canonicalized_statement_hostname_hash_hex_str(self):
     """Returns the hex string version of canonicalized_statement-hostname hash."""
     return utils.int_to_hex_str(
         self.canonicalized_statement_hostname_hash)
コード例 #4
0
ファイル: views.py プロジェクト: emedez/sqlcanon
def last_statements(
        request, window_length,
        template='sqlcanon/last_statements.html'):

    try:
        window_length = int(window_length)
        dt = timezone.now()
        dt_start = dt - datetime.timedelta(minutes=window_length)
        statement_data_qs = (
            models.StatementData.objects
            .filter(dt__gte=dt_start, dt__lte=dt)
            .values(
                'canonicalized_statement',
                'server_id',
                'canonicalized_statement_hostname_hash',
                'canonicalized_statement_hash',
                'statement')
            .annotate(Max('dt'), Count('dt')).order_by('dt__max'))

        # calculate counts
        counts = {}
        for statement_data in statement_data_qs:
            canonicalized_statement_hostname_hash = statement_data[
                'canonicalized_statement_hostname_hash']
            if canonicalized_statement_hostname_hash in counts:
                counts[canonicalized_statement_hostname_hash] += (
                    statement_data['dt__count'])
            else:
                counts[canonicalized_statement_hostname_hash] = (
                    statement_data['dt__count'])

        statements = []
        for statement_data in statement_data_qs:
            canonicalized_statement_hostname_hash = statement_data[
                'canonicalized_statement_hostname_hash']
            count = counts.get(canonicalized_statement_hostname_hash, 1)
            sparkline_data_session_key = 'sparkline_data.%s' % (
                utils.int_to_hex_str(
                    canonicalized_statement_hostname_hash),)
            sparkline_data = request.session.get(
                sparkline_data_session_key, [])
            if sparkline_data:
                if sparkline_data[-1] != count:
                    # add new data only if it is different from the
                    # last data added
                    sparkline_data.append(count)
            else:
                sparkline_data.append(count)
            if len(sparkline_data) > settings.SPARKLINE_DATA_COUNT_LIMIT:
                # limit number of items in sparkline data
                sparkline_data = sparkline_data[
                    -settings.SPARKLINE_DATA_COUNT_LIMIT:len(
                        sparkline_data)]
            statements.append([
                statement_data,
                count,
                utils.int_to_hex_str(
                    canonicalized_statement_hostname_hash),
                ','.join([str(i) for i in sparkline_data])
            ])
            request.session[sparkline_data_session_key] = sparkline_data

        return render_to_response(template, locals(),
            context_instance=RequestContext(request))
    except Exception, e:
        log.exception('%s' % (e,))