/// <summary> /// 构造函数- 默认值 /// </summary> public AgentServiceOption(EnvModel envModel) { _envModel = envModel; // 标签 Service_TagList = new List <string>() { ".Net Core 2.2", _envModel.ASPNETCORE_ENVIRONMENT, _envModel.APP_BUILD_NO }; // 服务标签与服务名 Service_ID = $"{EnvHelper.GetLocalIPV4().Replace(".", "")}"; Service_Name = $"{envModel.APP_BUILD_NAME}".ToLower(); }
/// <summary> /// 实现 健康监测 middleware 方法 /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task InvokeAsync(HttpContext context) { if (context.Request.Path.Value.Equals(this._agentServiceOption.Service_HealthCheck_Route)) { string msg = $"Instance Health: OK <br/>" + $"Instance Container IP:[{ EnvHelper.GetLocalIPV4()}] <br/>" + $"Instance Service URL:[{_envModel.ASPNETCORE_URLS}] <br/>" + $"MiceoService Version[{_envModel.APP_ASSEMPLY_VERSION}],[{_envModel.ASPNETCORE_ENVIRONMENT}]"; //Content-Encoding context.Response.StatusCode = 200; context.Response.ContentType = "text/html"; await context.Response.WriteAsync(msg); } else { await _next(context); } }
public AgentServiceRegistration BuildMicroServiceRegisterInfo(AgentServiceOption conf) { var serviceRegistration = new AgentServiceRegistration { //对外公布的IP地址 Address = EnvHelper.GetLocalIPV4(), Port = EnvHelper.GetServicePort(), Check = new AgentServiceCheck { DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(conf.Service_Deregister_TimeSpan_Seconds), Interval = TimeSpan.FromSeconds(conf.Service_HealthCheck_Interval_Seconds), HTTP = conf.Service_HealthCheck_Route, Timeout = TimeSpan.FromSeconds(conf.Service_Check_Timeout_Seconds) }, ID = conf.Service_ID, Name = conf.Service_Name, Tags = conf.Service_TagList.ToArray() }; return(serviceRegistration); }
/// <summary> /// 生产外发字符串 /// </summary> /// <returns></returns> public string ToLogstashMessage() { string strPublishMessage = $"<{this.LogTime}> <{this.LogLevel}> <{this.LogId}> <{this.LogAttr}> <{this.LogCategory}> "; strPublishMessage += $"<{ EnvHelper.GetEnv().APP_BUILD_NAME}> <{EnvHelper.GetLocalHostName()}> <{EnvHelper.GetLocalIPV4()}> <{this.LogMsg}>"; return(strPublishMessage); }