Пример #1
0
def api_schooldisk_dayuploadinfo(user, startdate, enddate, dir_file_id):
    result = list()
    if not enddate:
        enddate = today(FORMAT_DATE='%Y-%m-%d', is_str=False)
    else:
        enddate = str2datetime(enddate, '%Y-%m-%d')

    if not startdate:
        startdate = enddate + datetime.timedelta(days=-30)
    else:
        startdate = str2datetime(startdate, '%Y-%m-%d')

    day_list = get_day_list(startdate, enddate)

    for each_day in day_list:
        day_cycle = get_day_cycle(each_day)
        upload_day_count = NetdiskSchoolFile.objects.filter(
            school=user.school,
            is_del=FALSE_INT,
            is_dir=FALSE_INT,
            create_time__gte=day_cycle['startdate'],
            create_time__lte=day_cycle['enddate'])
        if dir_file_id:
            upload_day_count = upload_day_count.filter(parent_id=dir_file_id)

        upload_day_count = upload_day_count.count()

        day_dict = {
            'day': datetime2str(day_cycle['startdate'], format='%Y-%m-%d'),
            'count': upload_day_count,
        }
        result.append(day_dict)

    return result
Пример #2
0
def api_schooldisk_alldirsummary(user):
    result = list()
    all_dir = NetdiskSchoolFile.objects.filter(school=user.school,
                                               is_del=FALSE_INT,
                                               is_dir=TRUE_INT)
    for each_dir in all_dir:
        son_files = NetdiskSchoolFile.objects.filter(school=user.school,
                                                     is_del=FALSE_INT,
                                                     is_dir=FALSE_INT,
                                                     parent_id=each_dir.id)
        totolsize = 0
        for each_son in son_files:
            totolsize = totolsize + each_son.fileobj.size
        dir_dict = {
            "dir_file_id":
            each_dir.id,
            "dir_name":
            each_dir.name,
            "dir_size_b":
            totolsize,
            "dir_size":
            get_friendly_size(totolsize),
            "dir_updatetime":
            datetime2str(each_dir.update_time, format="%Y-%m-%d %H:%M:%S"),
        }
        result.append(dir_dict)

    return result
Пример #3
0
def request_long(report):
    # http长请求数(>2s,不含上传操作)
    exclude_oper = [
        'api_upload_image',
        'api_upload_video',
        'api_upload_voice',
        'api_upload_file',
    ]
    today_dt = today(is_str=False)
    yesterday_dt = yesterday(is_str=False)
    qs = OperateLog.objects.filter(
        request_time__gte=yesterday_dt, request_time__lt=today_dt, duration__gte=LONG_REQUEST) \
        .exclude(account_id=None).exclude(user_type=None).exclude(user_school_id=None)
    lines = list()
    report.writelines([
        '\n[http长请求(>2s, 不含上传操作)]: \n',
    ])
    for each in qs:
        lines.append(
            u'ID:%d, url:%s, 时长:%d, 请求者:%d_%d_%d, 响应码:%s, c:%s, m:%s, 时间:%s\n'
            % (each.id, each.url, each.duration, each.account_id,
               each.user_type, each.user_school_id, each.status_code, each.c,
               each.m, datetime2str(each.request_time)))
    report.writelines(lines)
    return len(lines)
Пример #4
0
def request_500(report):
    # http请求"500"响应数, 详情见邮件附件
    today_dt = today(is_str=False)
    yesterday_dt = yesterday(is_str=False)
    qs = OperateLog.objects.filter(
        request_time__gte=yesterday_dt, request_time__lt=today_dt, status_code='500') \
        .exclude(account_id=None).exclude(user_type=None).exclude(user_school_id=None)
    lines = list()
    report.writelines([
        '\n[http请求"500"响应]: \n',
    ])
    for each in qs:
        lines.append(u'ID:%d, url:%s, 请求者:%d_%d_%d, c:%s, m:%s, 时间:%s\n' %
                     (each.id, each.url, each.account_id, each.user_type,
                      each.user_school_id, each.c, each.m,
                      datetime2str(each.request_time)))
    report.writelines(lines)
    return len(lines)