Exemplo n.º 1
0
def get_mysql_summary(pk):
    conn = Database.objects.get(pk=pk)
    db_type = conn.db_type
    query = reprocess_query(Space_Total_Query, {'pk': pk})
    total_space = execute_return_json(query)
    if not total_space:
        get_space(conn)
        total_space = execute_return_json(query)
    query = SummaryQuery.get(db_type)
    flag, json_data = run_batch_sql(conn, query)
    if not flag:
        raise build_exception_from_java(json_data)
    database_json = {
        x.get('Variable_name'): x.get('Value')
        for x in json_data.get('database')
        if x.get('Variable_name') in ('version', 'version_comment',
                                      'version_compile_machine',
                                      'version_compile_os',
                                      'default_storage_engine', 'general_log',
                                      'log_bin', 'slow_query_log')
    }
    memory_json = {
        x.get('Variable_name'): x.get('Value')
        for x in json_data.get('database')
        if x.get('Variable_name') in ('innodb_buffer_pool_size',
                                      'join_buffer_size', 'key_buffer_size',
                                      'query_cache_size', 'sort_buffer_size',
                                      'thread_cache_size')
    }
    summary_data = {
        'space': total_space,
        'database': database_json,
        'memory': memory_json
    }
    return summary_data
Exemplo n.º 2
0
def space(self):
    db_filter_set = Database.objects.all().filter((Q(disabled=False))
                                                  & (Q(is_switch_off=False)))
    for db in db_filter_set:
        try:
            get_space(db)
        except Exception as e:
            logger.error(str(e))

        if db.db_type == 'oracle':
            if db.instance_count > 1:
                try:
                    diskgroup_warn(db)
                except Exception as e:
                    logger.error(str(e))
Exemplo n.º 3
0
def get_sqlserver_summary(pk):
    conn = Database.objects.get(pk=pk)
    db_type = conn.db_type
    query = reprocess_query(SQLServer_Space_Total_Query, {'pk': pk})
    total_space = execute_return_json(query)
    if not total_space:
        get_space(conn)
        total_space = execute_return_json(query)
    query = SummaryQuery.get(db_type)
    flag, json_data = run_batch_sql(conn, query)
    if not flag:
        raise build_exception_from_java(json_data)
    space = {'space': total_space}
    summary_data = {**space, **json_data}
    return summary_data
Exemplo n.º 4
0
def detail_info(pk, name, days=7, limit=200):
    try:
        database = Database.objects.get(pk=pk)
        db_type = database.db_type
        options = {'pk': pk, 'days': days, 'limit': limit, 'name': name}
        space_detail = (Space_Detail.objects.filter(database=database)).first()
        if not space_detail:
            get_space(database)
            space_detail = (Space_Detail.objects.filter(
                database=database)).first()
        name_detail = {}
        for x in space_detail.detail:
            if x.get('TABLESPACE_NAME') == name:
                name_detail = x
                break

        query = reprocess_query(Space_Detail_Lag_Query, options)
        space_trend = execute_return_json(query)
        query = reprocess_query(Space_Detail_Realtime_Query.get(db_type),
                                options)
        if not is_temp(db_type, name_detail):
            if db_type in ('db2', 'oracle'):
                query.pop('temp')
        if db_type == 'sqlserver':
            flag, json_data = run_batch_sql(database, query, name)
        else:
            flag, json_data = run_batch_sql(database, query)
        if not flag:
            raise build_exception_from_java(json_data)
        detail_data = {
            'space_detail': name_detail,
            'space_trend': {
                'name':
                '(MB)',
                'data':
                [[x.get('CREATED_AT'), x.get('DELTA')] for x in space_trend]
            },
            'table_data': json_data.get('segment') if json_data else [],
            'temp': json_data.get('temp') if json_data else []
        }
        if db_type != 'mysql':
            detail_data['datafile'] = json_data.get(
                'datafile') if json_data.get('datafile') else []
        return detail_data
    except ObjectDoesNotExist:
        return {'error_message': ''}
Exemplo n.º 5
0
def space_info(pk, days=7):
    try:
        database = Database.objects.get(pk=pk)
        db_type = database.db_type
        options = {'pk': pk, 'days': days}
        space_detail = (Space_Detail.objects.filter(database=database)).first()
        if not space_detail:
            get_space(database)
            space_detail = (Space_Detail.objects.filter(
                database=database)).first()
        space_detail = space_detail.detail if space_detail else {}
        space_total_query = Space_Total_Query if db_type != 'sqlserver' else SQLServer_Space_Total_Query
        query = reprocess_query(space_total_query, options)
        total_space = execute_return_json(query)
        query = reprocess_query(Space_Total_Lag_Query, options)
        total_trend = execute_return_json(query)
        if db_type == 'oracle':
            query = reprocess_query(Space_Realtime_Query.get(db_type), options)
            flag, json_data = run_batch_sql(database, query)
            if not flag:
                raise build_exception_from_java(json_data)
            else:
                json_data = {}
        local_data = {
            'space_detail': space_detail,
            'total_space': total_space[0] if total_space else {},
            'total_trend': {
                'name':
                '(MB)',
                'data':
                [[x.get('CREATED_AT'), x.get('DELTA')] for x in total_trend]
            }
        }
        json_data['switch_trend'] = {
            'name':
            '',
            'data': [[x.get('TIME'), x.get('COUNT')]
                     for x in json_data.get('switch_trend', [])]
        }
        space_summary = {**local_data, **json_data}
        return space_summary
    except ObjectDoesNotExist:
        return {'error_message': ''}
    except Exception as err:
        return {'error_message': str(err)}
Exemplo n.º 6
0
def get_oracle_summary(pk):
    key = 'oracle:%s:index' % pk
    read_data = redis.get(key)
    if read_data:
        return json.loads(read_data)
    else:
        conn = Database.objects.get(pk=pk)
        db_type = conn.db_type
        query = reprocess_query(Space_Total_Query, {'pk': pk})
        total_space = execute_return_json(query)
        if not total_space:
            get_space(conn)
            total_space = execute_return_json(query)
        query = SummaryQuery.get(db_type)
        flag, json_data = run_batch_sql(conn, query)
        if not flag:
            raise build_exception_from_java(json_data)
        space = {'space': total_space}
        summary_data = {**space, **json_data}
        redis.setex(key, 86400, json.dumps(summary_data))
        return summary_data