Ejemplo n.º 1
0
    def create_new_graphs_and_topqueries(self):
        prefix = config.get('plot_dir') or 'plots'
        current_dir = os.getcwd()

        # Get profiles of the created table
        nexttable = self.next_table_name()
        
        profiles = query_profile(nexttable,
                                 config.get("numtop") or 200,
                                 self.time_division_radiogroup.value,
                                 self.cur)
        peruser_divided, peruser_alltime, full_divided, full_alltime, full_topqueries, peruser_topqueries = profiles

        # Remove previous plotted data
        if os.path.exists(prefix):
            os.system("rm -r {0}".format(prefix))
        os.mkdir(prefix)
        os.chdir(prefix)
        gnuplot(profiles, time_axis_label=self.time_division_radiogroup.value)
        # use a for loop so that gnuplot settings don't stick around between scripts
        os.system("for x in *.gnu; do gnuplot $x; done")

        # Load the new image lists
        self.full_ = [Image(file=x) for x in glob('full_*.png')]
        self.peruser_alltime_ = [Image(file=x) for x in \
                                 glob('peruser_alltime_*.png')]
        self.peruser_divided_ = [Image(file=x) for x in \
                                 glob('peruser_divided_*.png') if '_total_' not in x]
        self.peruser_divided_total_ = [Image(file=x) for x in \
                                       glob('peruser_divided_total_*.png')]
        
        os.chdir(current_dir)

        # Set self.image.images = whatever's selected in the radio
        # (we got new lists)
        self.change_images()

        # Generate the new topquery panel text
        self.topqueries.new_profiles(full_topqueries, peruser_topqueries)

        self.last_grouped_by = self.time_division_radiogroup.value
import sys
import os
import re

from myutils import get_conn, get_reserved_words, print_and_execute, clean, repl_constants, querytypes, define_time_functions, partition_from_str, config
from QueryReducer import QueryReducer

reducer = QueryReducer( **(config.get('reducer') or {}) )
    
reserved_words = get_reserved_words('mysql_keywords.txt')

numlist_re = re.compile(r'\([0-9, ]{20,}\)')
numlist_sub_fcn = lambda x: '<numlist len={0}>'.format(x.group(0).count(',') + 1)

# TODO: make this regex accept dots in table names
insert_re = re.compile(r"(INSERT INTO ['`]?\w+['`]?)")

values_re = re.compile(r'VALUES', re.I)

def reduce_log(tablename, cur):

    print >>sys.stderr, "Reducing general_log.{0} and storing into reduced_log".format(tablename)
    print >>sys.stderr, "Selecting results..."

    cur.execute("USE reduced_log")
    print_and_execute("SELECT user, userid FROM users", cur)
    users = dict(cur.fetchall())
    usernum = max(users.values()) + 1 if users.values() else 0 # first open usernum
    newusers = []

    print_and_execute("SELECT server, serverid FROM servers", cur)