Skip to content

Commit

Permalink
update to v4.6.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yswenli committed Jul 25, 2019
1 parent 0603f57 commit 9342314
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 59 deletions.
29 changes: 19 additions & 10 deletions SAEA.WebRedisManager/Controllers/RedisController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,19 @@ public ActionResult GetInfo(string name, bool isCpu)
if (data != null)
{
var result = "0";

if (isCpu)
result = data.used_cpu_user.ToString();
else
{
if (long.TryParse(data.used_memory, out long used_memory))
{
result = (used_memory / 1024 / 1024).ToString();
}
else
{
result = "0";
}
result = CurrentRedisClient.CpuUsed(name).ToString();
}
else
{
var totalmem = CurrentRedisClient.GetMaxMem(name);

var usemem = double.Parse(data.used_memory);

result = (usemem / totalmem * 100).ToString();
}

return Json(new JsonResult<string>() { Code = 1, Data = result, Message = "OK" });
}
Expand Down Expand Up @@ -422,6 +421,16 @@ public ActionResult DelItem(RedisData redisData)
object data = string.Empty;
if (redisData != null)
{
redisData.Name = SAEA.Http.Base.HttpUtility.UrlDecode(redisData.Name);
redisData.ID = SAEA.Http.Base.HttpUtility.UrlDecode(redisData.ID);
if (!string.IsNullOrEmpty(redisData.Key))
{
redisData.Key = SAEA.Http.Base.HttpUtility.UrlDecode(redisData.Key);
}
if (!string.IsNullOrEmpty(redisData.Value))
{
redisData.Value = SAEA.Http.Base.HttpUtility.UrlDecode(redisData.Value);
}
CurrentRedisClient.DelItem(redisData);
}
result.Code = 1;
Expand Down
63 changes: 63 additions & 0 deletions SAEA.WebRedisManager/Libs/CurrentRedisClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SAEA.RedisSocket;
using SAEA.RedisSocket.Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -93,6 +94,68 @@ public static ServerInfo GetServerInfo(string name)
}


static ConcurrentDictionary<string, double> _cpuUsed = new ConcurrentDictionary<string, double>();

public static double CpuUsed(string name)
{
var data = CurrentRedisClient.GetServerInfo(name);

var before = 0D;

var now = double.Parse(data.used_cpu_sys);

if (_cpuUsed.ContainsKey(name))
{
before = _cpuUsed[name];
}

_cpuUsed[name] = now;

return (now - before) * 100;
}


public static double GetMaxMem(string name)
{
lock (_locker)
{
if (_redisClients.ContainsKey(name))
{
var redisClient = _redisClients[name];

if (redisClient.IsConnected)
{
var str = redisClient.Info("Memory");

if (string.IsNullOrEmpty(str))
{
return 0D;
}

var arr = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

if (arr == null || !arr.Any())
{
return 0D;
}

foreach (var item in arr)
{
var sarr = item.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

if (sarr[0] == "maxmemory")
{
return double.Parse(sarr[1]);
}
}

}
}
return 0D;
}
}


public static bool IsCluster(string name)
{
if (_redisClients.ContainsKey(name))
Expand Down
2 changes: 1 addition & 1 deletion SAEA.WebRedisManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void Main(string[] args)
var config = SAEAMvcApplicationConfigBuilder.Read();

config.Port = 16379;
config.Count = 1;
config.Count = 100;

SAEAMvcApplicationConfigBuilder.Write(config);

Expand Down
2 changes: 1 addition & 1 deletion SAEA.WebRedisManager/wwwroot/Chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="layui-row layui-col-space15 cluster-content" style="margin-top:15px;">
<div class="layui-card">
<div class="layui-card-header" style="font-size:18px;">
<div class="layui-card-header" style="font-size:18px;display:none;">
redis cluster nodes <button class="layui-btn">add node</button>
</div>
<div class="layui-card-body layuiadmin-card-list" style="height:650px; overflow:auto">
Expand Down
12 changes: 8 additions & 4 deletions SAEA.WebRedisManager/wwwroot/Content/css/layui.css
Original file line number Diff line number Diff line change
Expand Up @@ -4451,7 +4451,11 @@ body .layui-util-face {
animation-name: layui-fadeout
}

#edit-form-container {
width: 590px;
margin-right:10px;
}
#add_form{
display:block;
height:312px;
}

#edit_form {
padding-right: 15px;
}
6 changes: 5 additions & 1 deletion SAEA.WebRedisManager/wwwroot/Content/js/redis.console.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

var layerIndex = -1;


$("#cmdTxt").keypress(function (e) {
if (e.which === 13) {
$("#runBtn").click();
}
});

$("#runBtn").click(function () {

Expand Down
Loading

0 comments on commit 9342314

Please sign in to comment.