Redis监控Web版管理工具

HomeController.cs

using RedisMonitor.Core.Model;
using RedisMonitor.Core.RedisServer;
using System.Linq;
using System.Web.Mvc;

namespace RedisManager
{
    public class HomeController : Controller
    {
        #region 视图

        public ActionResult Index()
        {
            var redisServers = RedisServerConfig.RedisServers;
            ViewBag.RedisServers = redisServers;
            return View();
        }

        public ActionResult Details(string serverId)
        {
            return View();
        }

        public ActionResult SimpleDetails(string serverId)
        {
            return PartialView();
        }

        public ActionResult RichDetails(string serverId)
        {
            var result = RedisServerHelp.GetRedisInfo(serverId);
            ViewBag.InfoMsg = result;
            return PartialView();
        }

        public ActionResult InfoInstructions()
        {
            return View();
        }

        public ActionResult Clients(string serverId)
        {
            return PartialView();
        }

        public ActionResult GetClients(string serverId)
        {
            var result = RedisServerHelp.GetClients(serverId);
            ViewBag.Clients = result;
            return PartialView();
        }

        public ActionResult BaseRedisStatus(string serverId)
        {
            RedisServerModel model = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);
            var serverResponse = RedisServerHelp.GetRedisServerResponse(serverId);
            ViewBag.RedisServer = model;
            ViewBag.ServerResponse = serverResponse;
            return PartialView();
        }

        #endregion 视图

        #region 方法

        public ActionResult GetRedisStatus(string serverId)
        {
            var model = RedisServerHelp.GetRedisServerResponse(serverId);
            return Json(model, JsonRequestBehavior.AllowGet);
        }

        public ActionResult SimpleDetailsData(string serverId)
        {
            var result = RedisServerHelp.GetRedisInfoRow(serverId);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public ActionResult RichDetailsData(string serverId)
        {
            var result = RedisServerHelp.GetRedisInfo(serverId);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 更新读取配置文件
        /// </summary>
        /// <returns></returns>
        public ActionResult RefreshServerConfig()
        {
            RedisServerConfig.LoadConfig();
            return Content("刷新成功");
        }

        #endregion 方法
    }
}

RedisServiceConfig.json

[
  {
    "ServerHost": "127.0.0.1:6379,allowadmin=true,password=123456",
    "ServerDescribe": "本地"
  },
  {
    "ServerHost": "192.168.1.104:6379,allowadmin=true,password=123456",
    "ServerDescribe": "测试环境"
  },
  {
    "ServerHost": "192.168.1.141:6379,allowadmin=true",
    "ServerDescribe": "开发环境"
  }
]

_Layout.cshtml:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("监控列表", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Info命令说明", "InfoInstructions", "Home")</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

Index.cshtml:

@using RedisMonitor.Core.Model
@{
    ViewBag.Title = "监控列表";
}
@{
    var redisServers = ViewBag.RedisServers as List<RedisServerModel>;
}
<br />
<!--操作栏-->
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">操作</h3>
    </div>
    <div class="panel-body" style="padding-bottom: 2px;">
        <form class="form-horizontal" role="form">
            <div class="form-group form-group-lg has-success has-feedback">
                <label class="col-sm-2 control-label" for="select_time">刷新频率:</label>
                <div class="col-sm-4">
                    <select class="form-control" id="select_time">
                        <option value="2">2s</option>
                        <option value="5" selected>5s</option>
                        <option value="20">20s</option>
                        <option value="40">40s</option>
                        <option value="60">1分钟</option>
                        <option value="300">5分钟</option>
                        <option value="600">10分钟</option>
                        <option value="1800">30分钟</option>
                    </select>
                </div>
                <label class="col-sm-2 control-label" for="select_time">修改了配置文件,请戳</label>
                <div class="col-sm-4">
                    <button type="button" class="btn btn-primary" onclick="refreshList()">
                        <span class="glyphicon glyphicon-refresh"></span>点击刷新
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<!--监控列表-->
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">监控列表</h3>
    </div>
    <div class="panel-body">
        <div class="table-responsive" style="min-height:500px;">
            <table class="table table-bordered table-hover" id="table_redis">
                <thead>
                    <tr>
                        <th>ServerId</th>
                        <th>配置地址</th>
                        <th style="width:10%">描述</th>
                        <th>状态</th>
                        <th>响应时间</th>
                    </tr>
                </thead>
                <tbody>
                    @if (redisServers != null)
                    {
                        foreach (var item in redisServers)
                        {
                    <tr class="active">
                        <td class="ServerId">@item.ServerId</td>
                        <td class="ServerHost"><a title="查看详情" target="_blank" href="/Home/Details?ServerId=@item.ServerId">@item.ServerHost</a></td>
                        <td class="ServerDescribe">@item.ServerDescribe</td>
                        <td class="Status">--</td>
                        <td class="ResponseTime">--</td>
                    </tr>
                        }
                    }
                    else
                    {
                    <tr>
                        <td>暂无配置的Redis服务器列表</td>
                    </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>

@section scripts{
    <script>
        $(function () {
            updateStatus();
        });

        function updateStatus() {
            var $serverIds = $(".ServerId");
            $serverIds.each(function () {
                var $td = $(this);
                $.ajax({
                    type: "get",
                    url: "/Home/GetRedisStatus",
                    data: {
                        serverId: $td.text()
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data != null) {
                            var $tr = $td.parent();
                            $tr.removeClass("active");
                            if (data.IsConnection) {
                                $tr.addClass("success");
                            } else {
                                $tr.addClass("danger");
                            }
                            $td.nextAll(".Status").text(data.Status);
                            $td.nextAll(".ResponseTime").text(data.ResponseTime + "ms");
                        }
                    }
                });
            });
            setTimeout(updateStatus, $("#select_time").val() * 1000);
        }

        function refreshList() {
            $.ajax({
                type: "get",
                url: "/Home/RefreshServerConfig",
                success: function (data) {
                    location.reload(true);
                }
            });
        }
    </script>
}

视图页面:

这里写图片描述

Dll:

web项目所需dll

运行结果如图:

这里写图片描述


这里写图片描述


这里写图片描述


这里写图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Crawlab是一个基于Golang的分布式爬虫管理平台,支持Python、NodeJS、Go、Java、PHP等多种编程语言以及多种爬虫框架。 Crawlab架构: Crawlab的架构包括了一个主节点(Master Node)和多个工作节点(Worker Node),以及负责通信和数据储存的Redis和MongoDB数据库。 前端应用向主节点请求数据,主节点通过MongoDB和Redis来执行任务派发调度以及部署,工作节点收到任务之后,开始执行爬虫任务,并将任务结果储存到MongoDB。架构相对于v0.3.0之前的Celery本有所精简,去除了不必要的节点监控模块Flower,节点监控主要由Redis完成。 主节点 主节点是整个Crawlab架构的核心,属于Crawlab的中控系统。主节点负责与前端应用进行通信,并通过Redis将爬虫任务派发给工作节点。同时,主节点会同步(部署)爬虫给工作节点,通过Redis和MongoDB的GridFS。 工作节点 工作节点的主要功能是执行爬虫任务和储存抓取数据与日志,并且通过Redis的PubSub跟主节点通信。通过增加工作节点数量,Crawlab可以做到横向扩展,不同的爬虫任务可以分配到不同的节点上执行。 MongoDB MongoDB是Crawlab的运行数据库,储存有节点、爬虫、任务、定时任务等数据,另外GridFS文件储存方式是主节点储存爬虫文件并同步到工作节点的中间媒介。 Redis Redis是非常受欢迎的Key-Value数据库,在Crawlab中主要实现节点间数据通信的功能。例如,节点会将自己信息通过HSET储存在Redis的nodes哈希列表中,主节点根据哈希列表来判断在线节点。 前端 前端是一个基于Vue-Element-Admin的单页应用。其中重用了很多Element-UI的控件来支持相应的展示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值