rabbit.js 10 KB
$(
    updateOverView(),
    updateClusterView(),
    updateQueuesView()
);

function updateOverView() {
    alert("choosed rabbit :"+ 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 style='margin-left: 45px'>").addClass("micro-highlight").html("Connections: ").appendTo(div);

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

    var channels = $("<div style='margin-left: 45px'>").addClass("micro-highlight").html("Channels: ").appendTo(div);

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

    var exchanges = $("<div style='margin-left: 45px'>").addClass("micro-highlight").html("Exchanges: ").appendTo(div);

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

    var Queues = $("<div style='margin-left: 45px'>").addClass("micro-highlight").html("Queues: ").appendTo(div);

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

    var consumers = $("<div style='margin-left: 45px'>").addClass("micro-highlight").html("Consumers: ").appendTo(div);

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

    var Messages_Ready = $("<div style='margin-left: 45px'>").addClass("micro-highlight").html("Message_Ready: ").appendTo(div);

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

    var Messages_unack = $("<div style='margin-left: 45px'>").addClass("micro-highlight").html("Message_Unack: ").appendTo(div);

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

    var Messages_total = $("<div style='margin-left: 45px'>").addClass("micro-highlight").html("Message_Total: ").appendTo(div);

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

function updateClusterView() {

    $("#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() {
    $("#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: moId,
            queueName: rowData.name,
            alertHigh: $("#msg_alert_high_" + rowIndex + "").val()
        }
    })
}