diff --git a/AgileConfig.Server.Apisite/Controllers/ReportController.cs b/AgileConfig.Server.Apisite/Controllers/ReportController.cs index 282c1ce3..dff408b7 100644 --- a/AgileConfig.Server.Apisite/Controllers/ReportController.cs +++ b/AgileConfig.Server.Apisite/Controllers/ReportController.cs @@ -173,7 +173,7 @@ public async Task ServiceCount() { var services = await _serviceInfoService.GetAllServiceInfoAsync(); var serviceCount = services.Count; - var serviceOnCount = services.Count(x => x.Alive == ServiceAlive.Online); + var serviceOnCount = services.Count(x => x.Status == ServiceStatus.Healthy); return Json(new { serviceCount, diff --git a/AgileConfig.Server.Apisite/Controllers/ServiceController.cs b/AgileConfig.Server.Apisite/Controllers/ServiceController.cs index b782051d..4f085c98 100644 --- a/AgileConfig.Server.Apisite/Controllers/ServiceController.cs +++ b/AgileConfig.Server.Apisite/Controllers/ServiceController.cs @@ -67,7 +67,7 @@ public async Task Add([FromBody] ServiceInfoVM model) }); } - public async Task Search(string serviceName, string serviceId, ServiceAlive? alive, + public async Task Search(string serviceName, string serviceId, ServiceStatus? status, string sortField, string ascOrDesc, int current = 1, int pageSize = 20) { @@ -89,9 +89,9 @@ public async Task Search(string serviceName, string serviceId, Se { query = query.Where(x => x.ServiceId.Contains(serviceId)).ToList(); } - if (alive.HasValue) + if (status.HasValue) { - query = query.Where(x => x.Alive == alive).ToList(); + query = query.Where(x => x.Status == status).ToList(); } query = query.OrderByDescending(x => x.RegisterTime).ToList(); @@ -127,7 +127,7 @@ public async Task Search(string serviceName, string serviceId, Se serviceVMs.Add(new ServiceInfoVM() { Id = service.Id, - Alive = service.Alive, + Status = service.Status, ServiceId = service.ServiceId, ServiceName = service.ServiceName, Ip = service.Ip, diff --git a/AgileConfig.Server.Apisite/Controllers/api/Models/ServiceInfoVM.cs b/AgileConfig.Server.Apisite/Controllers/api/Models/ServiceInfoVM.cs index 25b7ae2a..f6293028 100644 --- a/AgileConfig.Server.Apisite/Controllers/api/Models/ServiceInfoVM.cs +++ b/AgileConfig.Server.Apisite/Controllers/api/Models/ServiceInfoVM.cs @@ -15,7 +15,7 @@ public class ServiceInfoVM public List MetaData { get; set; } = new List(); - public ServiceAlive Status { get; set; } + public ServiceStatus Status { get; set; } } public class QueryServiceInfoResultVM diff --git a/AgileConfig.Server.Apisite/Controllers/api/RegisterCenterController.cs b/AgileConfig.Server.Apisite/Controllers/api/RegisterCenterController.cs index 26c64642..78947548 100644 --- a/AgileConfig.Server.Apisite/Controllers/api/RegisterCenterController.cs +++ b/AgileConfig.Server.Apisite/Controllers/api/RegisterCenterController.cs @@ -135,7 +135,7 @@ public async Task> AllServices() Ip = serviceInfo.Ip, Port = serviceInfo.Port, MetaData = JsonConvert.DeserializeObject>(serviceInfo.MetaData), - Status = serviceInfo.Alive + Status = serviceInfo.Status }; vms.Add(vm); } @@ -157,7 +157,7 @@ public async Task> OnlineServices() Ip = serviceInfo.Ip, Port = serviceInfo.Port, MetaData = JsonConvert.DeserializeObject>(serviceInfo.MetaData), - Status = serviceInfo.Alive + Status = serviceInfo.Status }; vms.Add(vm); } @@ -179,7 +179,7 @@ public async Task> OfflineServices() Ip = serviceInfo.Ip, Port = serviceInfo.Port, MetaData = JsonConvert.DeserializeObject>(serviceInfo.MetaData), - Status = serviceInfo.Alive + Status = serviceInfo.Status }; vms.Add(vm); } diff --git a/AgileConfig.Server.Apisite/Models/ServiceInfoVM.cs b/AgileConfig.Server.Apisite/Models/ServiceInfoVM.cs index bf9ea4b3..52c9ebcd 100644 --- a/AgileConfig.Server.Apisite/Models/ServiceInfoVM.cs +++ b/AgileConfig.Server.Apisite/Models/ServiceInfoVM.cs @@ -23,7 +23,7 @@ public class ServiceInfoVM public string MetaData { get; set; } - public ServiceAlive Alive { get; set; } + public ServiceStatus Status { get; set; } public DateTime? RegisterTime { get; set; } diff --git a/AgileConfig.Server.Data.Entity/ServiceInfo.cs b/AgileConfig.Server.Data.Entity/ServiceInfo.cs index c3f76838..19d50bf8 100644 --- a/AgileConfig.Server.Data.Entity/ServiceInfo.cs +++ b/AgileConfig.Server.Data.Entity/ServiceInfo.cs @@ -5,10 +5,10 @@ namespace AgileConfig.Server.Data.Entity { - public enum ServiceAlive + public enum ServiceStatus { - Offline = 0, - Online = 1 + Unhealthy = 0, + Healthy = 1 } public enum RegisterWay @@ -46,8 +46,8 @@ public class ServiceInfo [Column(Name = "meta_data", StringLength = 2000)] public string MetaData { get; set; } - [Column(Name = "alive")] - public ServiceAlive Alive { get; set; } + [Column(Name = "status")] + public ServiceStatus Status { get; set; } [Column(Name = "register_time")] public DateTime? RegisterTime { get; set; } diff --git a/AgileConfig.Server.IService/IServiceInfoService.cs b/AgileConfig.Server.IService/IServiceInfoService.cs index d1d41196..55108406 100644 --- a/AgileConfig.Server.IService/IServiceInfoService.cs +++ b/AgileConfig.Server.IService/IServiceInfoService.cs @@ -12,7 +12,7 @@ public interface IServiceInfoService: IDisposable Task RemoveAsync(string id); - Task UpdateServiceStatus(ServiceInfo service, ServiceAlive status); + Task UpdateServiceStatus(ServiceInfo service, ServiceStatus status); Task> GetAllServiceInfoAsync(); Task> GetOnlineServiceInfoAsync(); diff --git a/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs b/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs index 89bc1007..be4c6183 100644 --- a/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs +++ b/AgileConfig.Server.Service/EventRegisterService/ServiceInfoStatusUpdateRegister.cs @@ -104,7 +104,7 @@ public void Register() using var serviceInfoService = NewServiceInfoService(); var service = await serviceInfoService.GetByUniqueIdAsync(id); if (service != null && !string.IsNullOrWhiteSpace(service.AlarmUrl) && - service.Alive == ServiceAlive.Offline) + service.Status == ServiceStatus.Unhealthy) { //如果是下线发送通知 _ = SendServiceOfflineMessageAsync(service); @@ -121,7 +121,7 @@ private async Task SendServiceOfflineMessageAsync(ServiceInfo service) service.ServiceId, service.ServiceName, Time = DateTime.Now, - Status = ServiceAlive.Offline.ToString(), + Status = ServiceStatus.Unhealthy.ToString(), Message = "服务已经下线" }; diff --git a/AgileConfig.Server.Service/RegisterCenterService.cs b/AgileConfig.Server.Service/RegisterCenterService.cs index 88ce93f6..4a05ba08 100644 --- a/AgileConfig.Server.Service/RegisterCenterService.cs +++ b/AgileConfig.Server.Service/RegisterCenterService.cs @@ -42,7 +42,7 @@ public async Task RegisterAsync(ServiceInfo serviceInfo) if (oldEntity != null) { oldEntity.RegisterTime = DateTime.Now; - oldEntity.Alive = ServiceAlive.Online; + oldEntity.Status = ServiceStatus.Healthy; oldEntity.LastHeartBeat = DateTime.Now; oldEntity.ServiceName = serviceInfo.ServiceName; oldEntity.Ip = serviceInfo.Ip; @@ -65,7 +65,7 @@ public async Task RegisterAsync(ServiceInfo serviceInfo) serviceInfo.RegisterTime = DateTime.Now; serviceInfo.LastHeartBeat = DateTime.Now; - serviceInfo.Alive = ServiceAlive.Online; + serviceInfo.Status = ServiceStatus.Healthy; serviceInfo.Id = Guid.NewGuid().ToString("n"); _dbContext.ServiceInfo.Add(serviceInfo); @@ -151,14 +151,14 @@ public async Task ReceiveHeartbeatAsync(string serviceUniqueId) } else { - var oldStatus = entity.Alive; - entity.Alive = ServiceAlive.Online; + var oldStatus = entity.Status; + entity.Status = ServiceStatus.Healthy; entity.LastHeartBeat = DateTime.Now; await _dbContext.UpdateAsync(entity); await _dbContext.SaveChangesAsync(); - if (oldStatus != ServiceAlive.Online) + if (oldStatus != ServiceStatus.Healthy) { _serviceInfoService.ClearCache(); dynamic param = new ExpandoObject(); diff --git a/AgileConfig.Server.Service/ServiceHealthCheckService.cs b/AgileConfig.Server.Service/ServiceHealthCheckService.cs index 778a2d97..e7ed3f20 100644 --- a/AgileConfig.Server.Service/ServiceHealthCheckService.cs +++ b/AgileConfig.Server.Service/ServiceHealthCheckService.cs @@ -149,9 +149,9 @@ public Task StartCheckAsync() if ((DateTime.Now - lstHeartBeat.Value).TotalSeconds > UnhealthInterval) { //客户端主动心跳模式:超过 UnhealthInterval 没有心跳,则认为服务不可用 - if (service.Alive == ServiceAlive.Online) + if (service.Status == ServiceStatus.Healthy) { - await _serviceInfoService.UpdateServiceStatus(service, ServiceAlive.Offline); + await _serviceInfoService.UpdateServiceStatus(service, ServiceStatus.Unhealthy); } } @@ -164,7 +164,7 @@ public Task StartCheckAsync() if (string.IsNullOrWhiteSpace(service.CheckUrl)) { //CheckUrl不填,直接认为下线 - await _serviceInfoService.UpdateServiceStatus(service, ServiceAlive.Offline); + await _serviceInfoService.UpdateServiceStatus(service, ServiceStatus.Unhealthy); continue; } @@ -172,7 +172,7 @@ public Task StartCheckAsync() { var result = await CheckAService(service); await _serviceInfoService.UpdateServiceStatus(service, - result ? ServiceAlive.Online : ServiceAlive.Offline); + result ? ServiceStatus.Healthy : ServiceStatus.Unhealthy); }); } } diff --git a/AgileConfig.Server.Service/ServiceInfoService.cs b/AgileConfig.Server.Service/ServiceInfoService.cs index fd76b894..a312d591 100644 --- a/AgileConfig.Server.Service/ServiceInfoService.cs +++ b/AgileConfig.Server.Service/ServiceInfoService.cs @@ -53,7 +53,7 @@ public async Task> GetAllServiceInfoAsync() public async Task> GetOnlineServiceInfoAsync() { - var services = await FreeSQL.Instance.Select().Where(x => x.Alive == ServiceAlive.Online) + var services = await FreeSQL.Instance.Select().Where(x => x.Status == ServiceStatus.Healthy) .ToListAsync(); return services; @@ -61,7 +61,7 @@ public async Task> GetOnlineServiceInfoAsync() public async Task> GetOfflineServiceInfoAsync() { - var services = await FreeSQL.Instance.Select().Where(x => x.Alive == ServiceAlive.Offline) + var services = await FreeSQL.Instance.Select().Where(x => x.Status == ServiceStatus.Unhealthy) .ToListAsync(); return services; @@ -107,7 +107,7 @@ private string GenerateMD5(List services) } sb.Append( - $"{serviceInfo.ServiceId}&{serviceInfo.ServiceName}&{serviceInfo.Ip}&{serviceInfo.Port}&{(int)serviceInfo.Alive}&{metaDataStr}&"); + $"{serviceInfo.ServiceId}&{serviceInfo.ServiceName}&{serviceInfo.Ip}&{serviceInfo.Port}&{(int)serviceInfo.Status}&{metaDataStr}&"); } var txt = sb.ToString(); @@ -122,22 +122,22 @@ public void ClearCache() } } - public async Task UpdateServiceStatus(ServiceInfo service, ServiceAlive status) + public async Task UpdateServiceStatus(ServiceInfo service, ServiceStatus status) { var id = service.Id; - var oldStatus = service.Alive; + var oldStatus = service.Status; - if (status == ServiceAlive.Offline) + if (status == ServiceStatus.Unhealthy) { await FreeSQL.Instance.Update() - .Set(x => x.Alive, status) + .Set(x => x.Status, status) .Where(x => x.Id == id) .ExecuteAffrowsAsync(); } else { await FreeSQL.Instance.Update() - .Set(x => x.Alive, status) + .Set(x => x.Status, status) .Set(x => x.LastHeartBeat, DateTime.Now) .Where(x => x.Id == id) .ExecuteAffrowsAsync(); diff --git a/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx b/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx index 5d33fb8f..76beaf96 100644 --- a/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx +++ b/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx @@ -97,7 +97,7 @@ const services: React.FC = () => { }, { title: '状态', - dataIndex: 'alive', + dataIndex: 'status', valueEnum: { 0: { text: '异常', @@ -148,14 +148,14 @@ const services: React.FC = () => { toolBarRender={()=> [ ] } />