javaApi.jsp 10.3 KB
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/bootstrap-datetimepicker.css"/>
    <link href="<%=basePath %>js/bootstrap-plugin/css/bootstrap.table.css" rel="stylesheet" media="screen"/>
    <link rel="stylesheet" href="<%=basePath %>css/bootstrap-responsive.min.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/fullcalendar.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/jquery-ui.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/uniform.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
    <link rel="stylesheet" href="<%=basePath %>js/jstree/themes/proton/style.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/yoho.css"/>
    <script src="<%=basePath %>js/excanvas.min.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/jquery-1.12.0.min.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/jquery-ui.custom.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>/js/bootstrap.min.js"></script>
    <script src="<%=basePath %>/js/unicorn.js"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js" charset="UTF-8"
            type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"
            type="text/javascript"></script>
    <script src="<%=basePath %>js/global.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js" charset="UTF-8"
            type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.table.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js" charset="UTF-8"
            type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js" charset="UTF-8"
            type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8"
            type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
    <script src="<%=basePath %>js/jstree/jstree.min.js"></script>
    <script src="<%=basePath %>js/jquery.toaster.js"></script>
    <script>
        var contextPath = '<%=basePath %>';
    </script>
    <title>YOHO!运维</title>
</head>
<body>

<!-- 头部 -->
<div id="head">
</div>
<!-- 右侧具体内容 -->
<div id="content">
<div id="breadcrumb">
    <a href="#" title="Go to Home" class="tip-bottom"><i
            class="icon-home"></i> Java服务</a> <a href="#" class="current">服务信息</a>
</div>

<div class="container-fluid">


    <div class="widget-box">
        <div class="widget-title">
            <h5>Java服务 DashBoard<a href="toJavaApiList">详细</a></h5>
        </div>
        <div class="widget-content">
            <div class="row api_info_container">
                <%--<div class="api_info_item col-xs-3 ">--%>
                <%--<div class="panel panel-default">--%>
                <%--<div class="panel-heading">gateway</div>--%>
                <%--<div class="panel-body">--%>
                <%--<h3><span class="label label-default">AWS状态</span>--%>
                <%--<span class="label label-default">Gcloud状态</span>--%>
                <%--</h3>--%>
                <%--<span>更新时间</span>--%>
                <%--</div>--%>
                <%--</div>--%>
                <%--</div>--%>
            </div>
        </div>
    </div>
</div>
</div>
</body>
<script src="<%=basePath %>script/common/genarate_left_panel.js"></script>
<script>
    $("#li_monitor").addClass("active open");
    $("#li_javaApi").addClass("active");
</script>
<script type="text/javascript">

    var getJavaAppType = function () {
        $.ajax({
            url: contextPath + "/type/queryJavaApiType",
            type: 'get',
            success: function (data) {
                if (!data || data.code != 200) {
                    $.toaster('获取java服务类型失败', '警告', 'warning');
                    return;
                }
                console.info(data.data);
                initDashBoard(data.data);
            },
            error: function (data) {
                $.toaster('获取java服务类型失败', '警告', 'warning');

            }
        });
    };

    var initDashBoard = function (data) {
        var div_dash = $(".api_info_container");
        $.each(data, function (idx, val) {
            var api_info_item = $('<div class="api_info_item col-xs-4 ">');
            var api_info_item_panel = $(' <div class="panel panel-default">');
            var api_info_item_panel_title = $('<div class="item_java_api_title panel-heading">' + val.typeName + '<span style="font-size: medium;float: right;padding-top: 15px"><span id="span_time_' + val.typeId + '"></span></span></div>');
            var api_info_item_panel_body = $('<div class="panel-body">');
            api_info_item_panel_body.append('<button class="btn_java_api btn btn-lg btn-default" id="btn_1_' + val.typeId + '">AWS &nbsp;<span class="badge"></span></button>');
            api_info_item_panel_body.append('<button class="btn_java_api btn btn-lg btn-default" id="btn_2_' + val.typeId + '">QCloud &nbsp;<span class="badge"></span></button>');
            api_info_item_panel_body.append('<button class="btn_java_api btn btn-lg btn-default" id="btn_0_' + val.typeId + '">Custom &nbsp;<span class="badge"></span></button>');
            //  api_info_item_panel_body.append('<h5 >更新时间:<span id="span_time_'+val.typeId+'"></span></h5>');
            api_info_item_panel.append(api_info_item_panel_title)
                    .append(api_info_item_panel_body);
            api_info_item.append(api_info_item_panel);
            div_dash.append(api_info_item);
        });

        $(".btn_java_api").on("click", function () {
            console.info(this);
            var url = contextPath + "/javaApi/toJavaApiList";
            var api_type = $(this).attr("id").split("_")[2];
            url += "?api_type=" + api_type;
            window.location.href = url;
        });

        timer();

    };

    var createTimeStr = function (checkTime) {
        var now = new Date();  //当前时间
        var ctime = new Date(Date.parse(checkTime.replace(/-/g, "/")));
        var timediff = now.getTime() - ctime.getTime(); //时间差的毫秒数


        var leave1 = timediff % (24 * 3600 * 1000);  //计算天数后剩余的毫秒数
        var hours = Math.floor(leave1 / (3600 * 1000));//计算相差分钟数

        var leave2 = leave1 % (3600 * 1000);        //计算小时数后剩余的毫秒数
        var minutes = Math.floor(leave2 / (60 * 1000));//计算相差秒数

        var leave3 = leave2 % (60 * 1000);      //计算分钟数后剩余的毫秒数
        var seconds = Math.round(leave3 / 1000);

        return minutes + " 分钟 " + seconds + " 秒" + "前更新";
    }

    var refreshDashBoard = function () {
        $.ajax({
            url: contextPath + "/javaApi/allStatus",
            type: 'get',
            success: function (data) {
                if (!data || data.code != 200) {
                    $.toaster('获取java服务类型失败', '警告', 'warning');
                    return;
                }
                console.info(data.data);
                $("button[id^='btn_0']").hide();
                $.each(data.data, function (idx, val) {
                    console.log($("#btn_" + val.cloudType + "_" + val.serviceType));
                    if(val.cloudType!=1&&val.cloudType!=2&&val.cloudType!=0)//目前只有腾讯aws、自定义url=0
                        return;
                    var btn = $("#btn_" + val.cloudType + "_" + val.serviceType);
                    if (val.updateTime != undefined && val.updateTime != "") {

                        var timestr = createTimeStr(val.updateTime)
                        $("#span_time_" + val.serviceType).html(timestr);
                    }
                    console.log(val);
                    btn.show();
                    if (val.errNum > 0) {
                        $(btn.children("span")[0]).html(val.errNum);
                        btn.removeClass("btn-success");
                        btn.addClass("btn-danger");
                    } else {
                        $(btn.children("span")[0]).html("");
                        btn.removeClass("btn-danger");
                        btn.addClass("btn-success");
                    }
                });

            },
            error: function (data) {
                $.toaster('获取java服务类型失败', '警告', 'warning');
            }
        });

    };


    function timer() {
        refreshDashBoard();
        setTimeout("timer()", 15000);
    };


    $(function () {
        getJavaAppType();
    });


</script>