rabbit.js 11.3 KB
$(
    initRabbitSelect()
);

function updateOverView(moId) {
    $.ajax({
        url: contextPath + "rabbitmq/overview",
        type: "post",
        dataType: "json",
        data: {
            moId: moId
        },
        success: function (response) {
            updateOverview(response);
        },
        error: function (e) {
        }
    });
}

function updateOverview(response) {


    var div = document.getElementById("overviewDiv");

    div.innerHTML = "";

    var connections = $("<div>").addClass("micro-highlight").html("Connections:").appendTo(div);

    var conValue = $("<strong>").html(response.data.connections).appendTo(connections);

    var channels = $("<div>").addClass("micro-highlight").html("Channels:").appendTo(div);

    var chaValue = $("<strong>").html(response.data.channels).appendTo(channels);

    var exchanges = $("<div>").addClass("micro-highlight").html("Exchanges:").appendTo(div);

    var excValue = $("<strong>").html(response.data.exchanges).appendTo(exchanges);

    var Queues = $("<div>").addClass("micro-highlight").html("Queues:").appendTo(div);

    var quevalue = $("<strong>").html(response.data.queues).appendTo(Queues);

    var consumers = $("<div>").addClass("micro-highlight").html("Consumers:").appendTo(div);

    var consValue = $("<strong>").html(response.data.consumers).appendTo(consumers);

    var Messages_Ready = $("<div>").addClass("micro-highlight").html("Message_Ready:").appendTo(div);

    var readyValue = $("<strong>").html(response.data.messages_ready).appendTo(Messages_Ready);

    var Messages_unack = $("<div>").addClass("micro-highlight").html("Message_Unack:").appendTo(div);

    var unValue = $("<strong>").html(response.data.messages_unack).appendTo(Messages_unack);

    var Messages_total = $("<div>").addClass("micro-highlight").html("Message_Total:").appendTo(div);

    var totValue = $("<strong>").html(response.data.messages).appendTo(Messages_total);
}

function updateClusterView(moId) {

    $("#clusterViewTable").table(
        {
            url: contextPath + "rabbitmq/clusterView",
            queryParams: {
                moId: moId
            },		//调用url传递的参数
            method: "POST",
            striped: true,
            panelClass: "panel-success",
            pagination: true,
            pageSize: 5,
            loadFilter: function (data) {
                return defaultLoadFilter(data);
            },
            columns: [{
                title: "Name",
                formatter: function (value, rowData) {
                    /*alert(rowData.name);*/
                    var div = $("<div align='center'>").html(rowData.name);
                    return div;
                }
            },
                {
                    title: "File descriptors",
                    formatter: function (value, rowData) {
                        var div = $("<div style='width: 240px;'>").addClass("status-bar");
                        var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
                            .addClass("status-bar-main green")
                            .html(rowData.fd_used);
                        var nameAvliable = $("<sub>").html(rowData.fd_total + " vailable");
                        div.append(nameDiv);
                        div.append(nameAvliable);
                        return div;
                    }
                },
                {
                    title: "Socket descriptors",
                    formatter: function (value, rowData) {
                        var div = $("<div style='width: 240px;'>").addClass("status-bar");
                        var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
                            .addClass("status-bar-main green")
                            .html(rowData.sockets_used);
                        var nameAvliable = $("<sub>").html(rowData.sockets_total + " available");
                        div.append(nameDiv);
                        div.append(nameAvliable);
                        return div;
                    }
                },
                {
                    title: "Erlang processes",
                    formatter: function (value, rowData) {
                        var div = $("<div style='width: 240px;'>").addClass("status-bar");
                        var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
                            .addClass("status-bar-main green")
                            .html(rowData.proc_used);
                        var nameAvliable = $("<sub>").html(rowData.proc_used + " available");
                        div.append(nameDiv);
                        div.append(nameAvliable);
                        return div;
                    }
                },
                {
                    title: "Memory",
                    formatter: function (value, rowData) {
                        var div = $("<div style='width: 240px;'>").addClass("status-bar");
                        var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
                            .addClass("status-bar-main green")
                            .html(rowData.mem_used);
                        var nameAvliable = $("<sub>").html(rowData.mem_limit + " vailable");
                        div.append(nameDiv);
                        div.append(nameAvliable);
                        return div;
                    }
                },
                {
                    title: "Disk space",
                    formatter: function (value, rowData) {
                        var div = $("<div style='width: 240px;'>").addClass("status-bar");
                        var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
                            .addClass("status-bar-main green")
                            .html(rowData.disk_free);
                        var nameAvliable = $("<sub>").html(rowData.disk_free_limit + " available");
                        div.append(nameDiv);
                        div.append(nameAvliable);
                        return div;
                    }
                }

            ]
        });
}

function updateQueuesView(moId) {
    $("#queueViewTable").table(
        {
            url: contextPath + "rabbitmq/queueView",
            method: "POST",
            queryParams: {
                moId: moId
            },		//调用url传递的参数
            striped: true,
            panelClass: "panel-success",
            pagination: true,
            pageSize: 5,
            loadFilter: function (data) {
                return defaultLoadFilter(data);
            },
            columns: [{
                title: "Virtual host",
                formatter: function (value, rowData) {
                    /*alert(rowData.name);*/
                    var div = $("<div align='center'>").html(rowData.vhost);
                    return div;
                }
            }, {
                title: "Name",
                formatter: function (value, rowData) {
                    /*alert(rowData.name);*/
                    var div = $("<div align='center'>").html(rowData.name);
                    return div;
                }
            }, {
                title: "State",
                formatter: function (value, rowData) {
                    /*alert(rowData.name);*/
                    var div = $("<div align='center'>").html(rowData.state);
                    return div;
                }
            }, {
                title: "Messages_Ready",
                formatter: function (value, rowData) {
                    /*alert(rowData.name);*/
                    var div = $("<div align='center'>").html(rowData.messages_ready);
                    return div;
                }
            }, {
                title: "Messages_Unack",
                formatter: function (value, rowData) {
                    /*alert(rowData.name);*/
                    var div = $("<div align='center'>").html(rowData.messages_unacknowledged);
                    return div;
                }
            }, {
                title: "Messages_Total",
                formatter: function (value, rowData) {
                    /*alert(rowData.name);*/
                    var div = $("<div align='center'>").html(rowData.messages);
                    return div;
                }
            },
                {
                    title: "Alert_High_Watermark",
                    formatter: function (value, rowData, rowIndex) {
                        /*alert(rowData.name);*/
                        var div = $("<div>");
                        var input = $("<input type='text' id='msg_alert_high_" + rowIndex + "' class='form-control' style='width: 120px;' height='50%'>");
                        input.val(rowData.alert_high);
                        var submit = $("<button >").addClass("btn btn-xs btn-danger").html("设置");
                        submit.click(function () {
                            fixAlertHigh(rowData, rowIndex);
                        });
                        div.append(input);
                        div.append("&nbsp;");
                        div.append("&nbsp;");
                        div.append("&nbsp;");
                        div.append(submit);
                        return div;
                    }
                }
            ]
        }
    )

}

function fixAlertHigh(rowData, rowIndex) {

    /*    alert(rowIndex);
     alert(rowData.name);
     alert($("#msg_alert_high_" + rowIndex + "").val());*/
    $.ajax({
        url: contextPath + "rabbitmq/fixAlertHigh",
        type: "post",
        dataType: "json",
        data: {
            moId: $('#rabbitMqSelected option:selected').val(),
            queueName: rowData.name,
            alertHigh: $("#msg_alert_high_" + rowIndex + "").val()
        }
    })
}


function initRabbitSelect() {
    $.ajax({
        url: contextPath + "rabbitmq/allRabbitMq",
        type: "post",
        dataType: "json",
        success: function (response) {
            //将查询到的数据,update到选择框中
            genarateRabbitSelectOption(response.data);
            updateOverView((response.data)[0].moId);
            updateClusterView((response.data)[0].moId);
            updateQueuesView((response.data)[0].moId);

        },
        error: function (e) {
        }
    })
}
function genarateRabbitSelectOption(optionList) {
    var innerHTML = "<select id='rabbitMqSelected' class='form-control' style='width:50%; height: 20%; margin-left: 20%'  onchange='rabbitUpdateSelectOnChange()'>";
    for (var i = 0; i < optionList.length; i++) {
        innerHTML += "<option value='" + optionList[i].moId + "'>" + optionList[i].moName + "</option>";
    }
    innerHTML += "</select>";
    console.log(document.getElementById("selectRabbitDiv"));
    document.getElementById("selectRabbitDiv").innerHTML = innerHTML;
    document.getElementById("selectRabbitDiv").value = optionList[0].moName;
}

/**
 * 主机组选择框选中属性发生变化时,则异步查询当前主机组号下的ip列表,并且刷新ip列表
 */
function rabbitUpdateSelectOnChange() {
    var rabbitId = $('#rabbitMqSelected option:selected').val().replace(/\'/g, '\"');

    updateOverView(rabbitId);

    $("#clusterViewTable").table("load", {
        'moId': rabbitId
    });
    $("#queueViewTable").table("load", {
        'moId': rabbitId
    });
}