Exemple #1
0
def Dashboard(request):
    #仪表盘
    DockerContainerAll = docker_main.DockerInitial().DockerContainerCictionary(
    )
    print(DockerContainerAll)
    return render(request, 'common/dashboard.html',
                  {'DockerContainerAll': DockerContainerAll})
Exemple #2
0
def DockerUpdateALog(hostname,container_name,log_type):
    # 某个容器的日志下载
    docker_container_all = docker_main.DockerInitial().DockerContainerCictionary()
    for i in docker_container_all[hostname]:
        if i.name == container_name:
            service_name = i.name.split('-')[0]
            service_name = service_name + '-service'
            if i.status == 'running':
                log_date = datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
                print(log_date,service_name,log_type)
                service_log_path = '/logs/' + service_name + '/'+log_type+'.log'
                print('/logs/' + service_name + '/'+log_type+'.log')
                log_init = i.get_archive(service_log_path)
                log_str = str(log_init[0].data, encoding="utf-8")
                log_name = hostname + '-' + service_name + '-' + log_date + '-' +  log_type + '.log'
                log_dir_master = config.log_dir_master
                log_path = log_dir_master + '/'+'tmp/' + log_name
                log_file = open(log_path, 'a+')
                date_now = str(datetime.datetime.now())
                log_file.write('执行时间:' + date_now+'\n')
                log_file.write(log_str)
                log_file.close()
                return_results = {'return_results': log_path, 'log_name': log_name}
                return return_results
            else:
                return_results = {'return_results': None, 'log_name': 'docker容器状态为exit,请检查!'}
                return return_results
Exemple #3
0
def Dashboard(request):
    #仪表盘
    host_all = models.host_information.objects.filter(docker_status=1).all()
    if host_all:
        type = request.GET.get('type')
        DockerContainerAll = docker_main.DockerInitial().DockerContainerNow()
        if type:
            DockerContainerAll = sorted(DockerContainerAll,
                                        key=lambda k: k[type])
        return render(request, 'common/dashboard.html',
                      {'DockerContainerAll': DockerContainerAll})
    else:
        return HttpResponse('请登录admin添加docker主机信息')
Exemple #4
0
def DockerLog(Hostname, ContainerName, FindTime):
    # 调取所有容器判断健康度,然后返回日志.
    DockerContainerAll = docker_main.DockerInitial().DockerContainerCictionary()
    ContainerAll = DockerContainerAll[Hostname]
    for i in ContainerAll:
        if i.name == ContainerName:
            if FindTime:
                FindTime = int(FindTime)
                DatetimeNow = datetime.datetime.now() + datetime.timedelta(minutes=-FindTime,hours=-8)
                b_logs = i.logs(since=DatetimeNow)
                return b_logs
            else:
                b_logs = i.logs(tail=config.log_tail_line)
                return b_logs
Exemple #5
0
def DockerUpdateAllLog():
    # 全部日志备份
    docker_container_all = docker_main.DockerInitial().DockerContainerCictionary()
    for i in docker_container_all:
        for y in docker_container_all[i]:
            service_name = y.name.split('-')[0]
            if y.status == 'running':
                if service_name in config.service_name_list:
                    service_name = service_name + '-service'
                    log_date = datetime.datetime.now().strftime("%Y-%m-%d")
                    service_log_path = '/logs/' + service_name + '/log_info.log'
                    log_init = y.get_archive(service_log_path)
                    log_str = str(log_init[0].data, encoding="utf-8")
                    log_dir_master = config.log_dir_master
                    log_local_name = log_dir_master +'/'+ service_name + '/update/'+'update'+ i + '-' + service_name + '-' + log_date + '.log'
                    log_file = open(log_local_name, 'a+')
                    date_now = str(datetime.datetime.now())
                    log_file.write('执行时间:' + date_now)
                    log_file.write(log_str)
                    log_file.close()
    return_results = {'return_results': '!备份成功!返回主页!', 'log_name': None}
    return return_results