Commit 4457e98d authored by Savorboard's avatar Savorboard

add CapCache to cache server nodes.

parent 7766d408
......@@ -55,7 +55,6 @@ _options.Schema);
}
return stats;
});
statistics.Servers = 1;
return statistics;
}
......
This diff is collapsed.
......@@ -84,7 +84,14 @@ namespace DotNetCore.CAP.Dashboard
_statisticsLazy = new Lazy<StatisticsDto>(() =>
{
var monitoring = Storage.GetMonitoringApi();
return monitoring.GetStatistics();
var dto = monitoring.GetStatistics();
if (CapCache.Global.TryGet("cap.nodes.count", out object count))
{
dto.Servers = (int)count;
}
return dto;
});
}
......
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Consul;
using System.Net;
namespace DotNetCore.CAP.NodeDiscovery
{
......@@ -24,24 +22,31 @@ namespace DotNetCore.CAP.NodeDiscovery
{
_consul = new ConsulClient(config =>
{
config.WaitTime = TimeSpan.FromSeconds(5);
config.Address = new Uri($"http://{_options.DiscoveryServerHostName}:{_options.DiscoveryServerProt}");
});
}
public async Task<IList<Node>> GetNodes()
{
var services = await _consul.Agent.Services();
try {
var services = await _consul.Agent.Services();
var nodes = services.Response.Select(x => new Node
{
Id = x.Key,
Name = x.Value.Service,
Address = x.Value.Address,
Port = x.Value.Port,
Tags = string.Join(", ", x.Value.Tags)
});
var nodes = services.Response.Select(x => new Node {
Id = x.Key,
Name = x.Value.Service,
Address = x.Value.Address,
Port = x.Value.Port,
Tags = string.Join(", ", x.Value.Tags)
});
CapCache.Global.AddOrUpdate("cap.nodes.count", nodes.Count(), TimeSpan.FromSeconds(30),true);
return nodes.ToList();
return nodes.ToList();
}
catch (Exception) {
return null;
}
}
public Task RegisterNode()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment