public ServerDiagnostics Get() { var diagnostics = new ServerDiagnostics { MachineDate = DateTime.Now, MachineName = Environment.MachineName, MachineCulture = string.Format("{0} - {1}", CultureInfo.CurrentCulture.DisplayName, CultureInfo.CurrentCulture.Name), Platform = PlatformHandler.Platform.OSPlatform.ToString(), DnsHostName = Dns.GetHostName(), WorkingDirectory = null, ContentRootPath = _env.ContentRootPath, WebRootPath = _env.WebRootPath, ApplicationName = _env.ApplicationName, EnvironmentName = _env.EnvironmentName, }; diagnostics.MachineTimeZone = TimeZoneInfo.Local.IsDaylightSavingTime(diagnostics.MachineDate) ? TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName; diagnostics.ApplicationVersionNumber = GetType().GetTypeInfo().Assembly.GetName().Version.ToString(); var ipAddresses = Dns.GetHostAddressesAsync(diagnostics.DnsHostName).Result.Where(x => x.AddressFamily == AddressFamily.InterNetwork).ToList().Distinct(); var enumerable = ipAddresses as IPAddress[] ?? ipAddresses.ToArray(); var ipList = new List <string>(enumerable.Count()); foreach (var ipAddress in enumerable) { ipList.Add(ipAddress.ToString()); } diagnostics.IpAddressList = ipList; return(diagnostics); }
public IHttpActionResult Get() { _Logger.Trace("Fetch diagnostics started"); var diagnostics = new ServerDiagnostics(); try { diagnostics.MachineDate = DateTime.Now; diagnostics.MachineName = Environment.MachineName; diagnostics.MachineCulture = string.Format("{0} - {1}", CultureInfo.CurrentCulture.DisplayName, CultureInfo.CurrentCulture.Name); diagnostics.MachineTimeZone = TimeZone.CurrentTimeZone.IsDaylightSavingTime(diagnostics.MachineDate) ? TimeZone.CurrentTimeZone.DaylightName : TimeZone.CurrentTimeZone.StandardName; diagnostics.DnsHostName = Dns.GetHostName(); diagnostics.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; var ipHost = Dns.GetHostEntry(diagnostics.DnsHostName); var ipList = new List <string>(ipHost.AddressList.Length); foreach (var ipAddress in ipHost.AddressList) { ipList.Add(ipAddress.ToString()); } diagnostics.IpAddressList = ipList; diagnostics.ApplicationName = "Signup API"; diagnostics.ApplicationVersionNumber = GetType().Assembly.GetName().Version.ToString(); var dbChecks = new DiagnosticCheckCollection { CollectionName = "Data access", Results = GetDbCheckResults() }; diagnostics.Checks = new List <DiagnosticCheckCollection> { dbChecks }; SetStatus(diagnostics); _Logger.Trace("Fetch diagnostics completed"); } catch (Exception ex) { diagnostics.Status = string.Format("FAIL - diagnostic check threw error: {0}", ex); _Logger.Error(ex, "Fetch diagnostics failed"); } return(Ok(diagnostics)); }
protected virtual void SetStatus(ServerDiagnostics diagnostics) { //overall status: var statusBuilder = new StringBuilder(); foreach (var collection in diagnostics.Checks) { if (collection.Results.Any(x => x.Passed == false)) { statusBuilder.AppendFormat("{0} checks failed; ", collection.CollectionName); } } diagnostics.Status = statusBuilder.ToString(); if (diagnostics.Status.Length > 0) { diagnostics.Status = string.Format("RED - {0}", diagnostics.Status); } else { diagnostics.Status = "GREEN - service checks all passed"; } }
public IActionResult Get() { Log.Information($"Init:ServerDiagnostics:{DateTime.UtcNow}"); var osNameAndVersion = System.Runtime.InteropServices.RuntimeInformation.OSDescription; var diagnostics = new ServerDiagnostics { MachineDate = DateTime.Now, MachineName = Environment.MachineName, MachineCulture = $"{CultureInfo.CurrentCulture.DisplayName} - {CultureInfo.CurrentCulture.Name}", Platform = osNameAndVersion.Trim(), DnsHostName = Dns.GetHostName(), WorkingDirectory = null, ContentRootPath = _env.ContentRootPath, WebRootPath = _env.WebRootPath, ApplicationName = _env.ApplicationName, EnvironmentName = _env.EnvironmentName, Runtime = GetNetCoreVersion(), }; diagnostics.MachineTimeZone = TimeZoneInfo.Local.IsDaylightSavingTime(diagnostics.MachineDate) ? TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName; diagnostics.ApplicationVersionNumber = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; var ipAddresses = Dns.GetHostAddressesAsync(diagnostics.DnsHostName).Result.Where(x => x.AddressFamily == AddressFamily.InterNetwork).AsEnumerable().Distinct(); var enumerable = ipAddresses as IPAddress[] ?? ipAddresses.ToArray(); var ipList = new List <string>(enumerable.Count()); foreach (var ipAddress in enumerable) { ipList.Add(ipAddress.ToString()); } diagnostics.IpAddressList = ipList; return(Ok(diagnostics)); }
public IActionResult Index() { //adapted from https://gist.github.com/sixeyed/8445048 var diagnostics = new ServerDiagnostics(); diagnostics.MachineDate = DateTime.Now; diagnostics.MachineName = Environment.MachineName; diagnostics.MachineCulture = string.Format("{0} - {1}", CultureInfo.CurrentCulture.DisplayName, CultureInfo.CurrentCulture.Name); diagnostics.MachineTimeZone = TimeZone.CurrentTimeZone.IsDaylightSavingTime(diagnostics.MachineDate) ? TimeZone.CurrentTimeZone.DaylightName : TimeZone.CurrentTimeZone.StandardName; diagnostics.DnsHostName = Dns.GetHostName(); diagnostics.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; var ipHost = Dns.GetHostEntry(diagnostics.DnsHostName); var ipList = new List <string>(ipHost.AddressList.Length); foreach (var ipAddress in ipHost.AddressList) { ipList.Add(ipAddress.ToString()); } diagnostics.IpAddressList = ipList; diagnostics.ApplicationName = "Managing Azure IaaS with PowerShell"; diagnostics.ApplicationVersionNumber = this.GetType().Assembly.GetName().Version.ToString(); return(View(diagnostics)); }