Beispiel #1
0
    def index(self, **params):
        logging.debug('params: %s', params)
        messages = []
        data = []
        dbnames = []
        dbname = params.get('dbname')
        page = params.get('page', 'index')
        sort_column = params.get('sort_column', 'total_time')
        start_time = params.get('start_time', '')
        end_time = params.get('end_time', '')

        try:
            if sort_column not in pgwatch2_influx.STATEMENT_SORT_COLUMNS:
                raise Exception('invalid "sort_column": ' + sort_column)

            dbnames = [x['md_unique_name']
                       for x in pgwatch2.get_all_monitored_dbs()]
            if dbname:
                if page == 'index' and dbname:
                    data = pgwatch2_influx.get_db_overview(dbname)
                elif page == 'statements' and dbname:
                    data = pgwatch2_influx.find_top_growth_statements(dbname,
                                                                      sort_column,
                                                                      start_time,
                                                                      (end_time if end_time else datetime.utcnow().isoformat() + 'Z'))
        except requests.exceptions.ConnectionError:
            messages.append('ERROR - Could not connect to InfluxDB')
        except psycopg2.OperationalError:
            messages.append('ERROR - Could not connect to Postgres')

        tmpl = env.get_template('index.html')
        return tmpl.render(dbnames=dbnames, dbname=dbname, page=page, data=data, sort_column=sort_column,
                           start_time=start_time, end_time=end_time, grafana_baseurl=cmd_args.grafana_baseurl,
                           messages=messages, no_anonymous_access=cmd_args.no_anonymous_access, session=cherrypy.session,
                           no_component_logs=cmd_args.no_component_logs)
Beispiel #2
0
    def index(self, **params):
        logging.debug('params: %s', params)
        page = params.get('page', 'index')
        dbname = params.get('dbname')
        data = []
        sort_column = params.get('sort_column', 'total_time')
        if sort_column not in pgwatch2_influx.STATEMENT_SORT_COLUMNS:
            raise Exception('invalid "sort_column": ' + sort_column)
        utcn = datetime.utcnow()
        start_time = params.get('start_time',
                                (utcn - timedelta(days=1)).isoformat() + 'Z')
        end_time = params.get('end_time', (utcn.isoformat() + 'Z'))

        dbnames = [
            x['md_unique_name'] for x in pgwatch2.get_all_monitored_dbs()
        ]
        if dbname:
            if page == 'index' and dbname:
                data = pgwatch2_influx.get_db_overview(dbname)
            elif page == 'statements' and dbname:
                data = pgwatch2_influx.find_top_growth_statements(
                    dbname, sort_column, start_time, end_time)

        tmpl = env.get_template('index.html')
        return tmpl.render(dbnames=dbnames,
                           dbname=dbname,
                           page=page,
                           data=data,
                           sort_column=sort_column,
                           start_time=start_time,
                           end_time=end_time,
                           grafana_baseurl=cmd_args.grafana_baseurl)
Beispiel #3
0
    def stats_summary(self, **params):
        if cmd_args.no_stats_summary:
            raise Exception('Displaying summary statistics has been disabled')

        logging.debug('params: %s', params)
        messages = []
        data = []
        dbnames = []
        dbname = params.get('dbname')
        page = params.get('page', 'stats-summary')
        sort_column = params.get('sort_column', 'total_time')
        start_time = params.get('start_time', '')
        end_time = params.get('end_time', '')

        try:
            if cmd_args.datastore not in ['influx', 'postgres']:
                raise Exception('Summary statistics only available for InfluxDB or Postgres data stores')

            if sort_column not in pgwatch2_influx.STATEMENT_SORT_COLUMNS:
                raise Exception('invalid "sort_column": ' + sort_column)

            if cmd_args.datastore == 'influx':
                dbnames = pgwatch2_influx.get_active_dbnames()
            else:
                dbnames = pgwatch2.get_all_dbnames()

            if dbname:
                if page == 'stats-summary' and dbname:
                    data = pgwatch2_influx.get_db_overview(dbname) if cmd_args.datastore == 'influx' else pgwatch2.get_db_overview(dbname)
                elif page == 'statements' and dbname:
                    if cmd_args.datastore == 'influx':
                        data = pgwatch2_influx.find_top_growth_statements(dbname,
                                                                      sort_column,
                                                                      start_time,
                                                                      (end_time if end_time else datetime.utcnow().isoformat() + 'Z'))
                    else:
                        data = pgwatch2.find_top_growth_statements(dbname,
                                                                      sort_column,
                                                                      start_time,
                                                                      (end_time if end_time else datetime.utcnow().isoformat() + 'Z'))
        except (requests.exceptions.ConnectionError, influxdb.exceptions.InfluxDBClientError):
            messages.append('ERROR - Could not connect to InfluxDB')
        except psycopg2.OperationalError:
            messages.append('ERROR - Could not connect to Postgres')
        except Exception as e:
            messages.append('ERROR - ' + str(e))

        tmpl = env.get_template('stats-summary.html')
        return tmpl.render(dbnames=dbnames, dbname=dbname, page=page, data=data, sort_column=sort_column,
                           start_time=start_time, end_time=end_time, grafana_baseurl=cmd_args.grafana_baseurl,
                           messages=messages, no_anonymous_access=cmd_args.no_anonymous_access, session=cherrypy.session,
                           no_component_logs=cmd_args.no_component_logs, datastore=cmd_args.datastore)