Example #1
0
    def metrics(self, **params):
        logging.debug(params)
        message = ''
        if True:
            try:
                if params.get('save'):
                    pgwatch2.update_preset_config(params)
                    message = 'Config "{}" updated!'.format(params['pc_name'])
                elif params.get('new'):
                    config = pgwatch2.insert_preset_config(params)
                    message = 'Config "{}" added!'.format(config)
                elif params.get('delete'):
                    pgwatch2.delete_preset_config(params)
                    message = 'Config "{}" deleted!'.format(params['pc_name'])
                if params.get('metric_save'):
                    pgwatch2.update_metric(params)
                    message = 'Metric "{}" updated!'.format(params['m_name'])
                elif params.get('metric_new'):
                    id = pgwatch2.insert_metric(params)
                    message = 'Metric with ID "{}" added!'.format(id)
                elif params.get('metric_delete'):
                    pgwatch2.delete_metric(params)
                    message = 'Metric "{}" deleted!'.format(params['m_name'])
            except Exception as e:
                message = 'ERROR: ' + str(e)

        preset_configs = pgwatch2.get_preset_configs()
        metrics_list = pgwatch2.get_active_metrics_with_versions()
        metric_definitions = pgwatch2.get_all_metrics()

        tmpl = env.get_template('metrics.html')
        return tmpl.render(message=message,
                           preset_configs=preset_configs,
                           metrics_list=metrics_list,
                           metric_definitions=metric_definitions)
Example #2
0
    def metrics(self, **params):
        logging.debug(params)
        messages = []
        preset_configs = []
        metrics_list = []
        metric_definitions = []

        try:
            if params.get('save'):
                pgwatch2.update_preset_config(params)
                messages.append('Config "{}" updated!'.format(
                    params['pc_name']))
            elif params.get('new'):
                config = pgwatch2.insert_preset_config(params)
                messages.append('Config "{}" added!'.format(config))
            elif params.get('delete'):
                pgwatch2.delete_preset_config(params)
                messages.append('Config "{}" deleted!'.format(
                    params['pc_name']))
            if params.get('metric_save'):
                msg = pgwatch2.update_metric(params)
                messages.append('Metric "{}" updated!'.format(
                    params['m_name']))
                if msg:
                    messages.append(msg)
            elif params.get('metric_new'):
                id, msg = pgwatch2.insert_metric(params)
                messages.append('Metric with ID "{}" added!'.format(id))
                if msg:
                    messages.append(msg)
            elif params.get('metric_delete'):
                msg = pgwatch2.delete_metric(params)
                messages.append('Metric "{}" deleted!'.format(
                    params['m_name']))
                if msg:
                    messages.append(msg)

            preset_configs = pgwatch2.get_preset_configs()
            metrics_list = pgwatch2.get_active_metrics_with_versions()
            metric_definitions = pgwatch2.get_all_metrics()
        except psycopg2.OperationalError:
            messages.append('ERROR: Could not connect to Postgres')
        except Exception as e:
            messages.append('ERROR: ' + str(e))

        tmpl = env.get_template('metrics.html')
        return tmpl.render(messages=messages,
                           preset_configs=preset_configs,
                           metrics_list=metrics_list,
                           metric_definitions=metric_definitions,
                           no_anonymous_access=cmd_args.no_anonymous_access,
                           session=cherrypy.session,
                           no_component_logs=cmd_args.no_component_logs)