rabbit.js 12.1 KB
$(
    refreshView()
);

function refreshView() {
    updateOverView();
    updateClusterView();
    updateQueuesView();

    setTimeout('refreshView()', 30000);
}
function updateOverView() {
    $.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 cpus = $("<div style='margin-left: 35px; margin-top: 5px'>").addClass("micro-highlight").html("CPU(%): ").appendTo(div);

    var cpusValue = $("<strong>").html(response.data.cpu).appendTo(cpus);

    var mems = $("<div style='margin-left: 35px; margin-top: 5px'>").addClass("micro-highlight").html("可用/总内存(MB): ").appendTo(div);

    var memsValue = $("<strong>").html(response.data.mem).appendTo(mems);

    var nets = $("<div style='margin-left: 35px; margin-top: 5px'>").addClass("micro-highlight").html("网络I/O(Mbps): ").appendTo(div);

    var netsValue = $("<strong>").html(response.data.net).appendTo(nets);

    var connections = $("<div style='margin-left: 35px; margin-top: 5px'>").addClass("micro-highlight").html("Connections: ").appendTo(div);

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

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

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

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

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

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

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

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

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

    var Messages_Ready = $("<div style='margin-left: 35px; margin-top: 5px'>").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: 35px; margin-top: 5px'>").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: 35px; margin-top: 5px'>").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;'>")
                            .html(rowData.fd_used);
                        if (rowData.fd_used > rowData.fd_total / 2) {
                            nameDiv.addClass("status-bar-main red");
                        }
                        else {
                            nameDiv.addClass("status-bar-main green");
                        }
                        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);
                        if (rowData.sockets_used > rowData.sockets_total / 2) {
                            nameDiv.addClass("status-bar-main red");
                        }
                        else {
                            nameDiv.addClass("status-bar-main green");
                        }

                        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);

                        if (rowData.proc_used > rowData.proc_total / 2) {
                            nameDiv.addClass("status-bar-main red");
                        }
                        else {
                            nameDiv.addClass("status-bar-main green");
                        }
                        var nameAvliable = $("<sub>").html(rowData.proc_total + " 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;'>")
                            .html(rowData.mem_used);
                        if (rowData.mem_alarm) {
                            nameDiv.addClass("status-bar-main red");
                        }
                        else {
                            nameDiv.addClass("status-bar-main green");
                        }
                        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;'>")
                            .html(rowData.disk_free);

                        if (rowData.disk_free_alarm) {
                            nameDiv.addClass("status-bar-main red");
                        }
                        else {
                            nameDiv.addClass("status-bar-main green");
                        }
                        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",
/*            sortable: true, //是否启用排序
         sortOrder: "Messages_Total",*/
/*            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()
        }
    })
}