diff --git a/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs b/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs index da296a82fe..e1a33b5cae 100644 --- a/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs +++ b/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs @@ -3,6 +3,7 @@ namespace ServiceControl.Audit.Infrastructure using System; using System.Collections.Concurrent; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -16,6 +17,7 @@ namespace ServiceControl.Audit.Infrastructure using Autofac; using Autofac.Core.Activators.Reflection; using Autofac.Features.ResolveAnything; + using ByteSizeLib; using Microsoft.Owin.Hosting; using Monitoring; using NServiceBus; @@ -168,15 +170,48 @@ long DataSize() } } + long FolderSize() + { + try + { + var dir = new DirectoryInfo(settings.DbPath); + var dirSize = DirSize(dir); + return dirSize; + } + catch + { + return -1; + } + } + + static long DirSize(DirectoryInfo d) + { + long size = 0; + FileInfo[] fis = d.GetFiles(); + foreach (FileInfo fi in fis) + { + size += fi.Length; + } + DirectoryInfo[] dis = d.GetDirectories(); + foreach (DirectoryInfo di in dis) + { + size += DirSize(di); + } + return size; + } + void RecordStartup(LoggingSettings loggingSettings, EndpointConfiguration endpointConfiguration) { var version = FileVersionInfo.GetVersionInfo(typeof(Bootstrapper).Assembly.Location).ProductVersion; + var dataSize = DataSize(); + var folderSize = FolderSize(); var startupMessage = $@" ------------------------------------------------------------- ServiceControl Audit Version: {version} Audit Retention Period: {settings.AuditRetentionPeriod} Forwarding Audit Messages: {settings.ForwardAuditMessages} -Database Size: {DataSize()} bytes +Database Size: {ByteSize.FromBytes(dataSize).ToString("#.##", CultureInfo.InvariantCulture)} +Database Folder Size: {ByteSize.FromBytes(folderSize).ToString("#.##", CultureInfo.InvariantCulture)} ServiceControl Logging Level: {loggingSettings.LoggingLevel} RavenDB Logging Level: {loggingSettings.RavenDBLogLevel} Selected Transport Customization: {settings.TransportCustomizationType} @@ -235,4 +270,4 @@ public ConstructorInfo[] FindConstructors(Type targetType) static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); } } -} \ No newline at end of file +} diff --git a/src/ServiceControl.Audit/ServiceControl.Audit.csproj b/src/ServiceControl.Audit/ServiceControl.Audit.csproj index c606db0fff..089ed89714 100644 --- a/src/ServiceControl.Audit/ServiceControl.Audit.csproj +++ b/src/ServiceControl.Audit/ServiceControl.Audit.csproj @@ -20,6 +20,7 @@ + @@ -56,4 +57,4 @@ - \ No newline at end of file + diff --git a/src/ServiceControl/Bootstrapper.cs b/src/ServiceControl/Bootstrapper.cs index 38371c359b..7de8e7f02c 100644 --- a/src/ServiceControl/Bootstrapper.cs +++ b/src/ServiceControl/Bootstrapper.cs @@ -3,6 +3,7 @@ namespace Particular.ServiceControl using System; using System.Collections.Concurrent; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -14,6 +15,7 @@ namespace Particular.ServiceControl using Autofac; using Autofac.Core.Activators.Reflection; using Autofac.Features.ResolveAnything; + using ByteSizeLib; using global::ServiceControl.CompositeViews.Messages; using global::ServiceControl.Infrastructure; using global::ServiceControl.Infrastructure.DomainEvents; @@ -174,18 +176,49 @@ long DataSize() try { var info = new FileInfo(datafilePath); - return info.Length; } - catch (Exception) + catch + { + return -1; + } + } + + long FolderSize() + { + try + { + var dir = new DirectoryInfo(settings.DbPath); + var dirSize = DirSize(dir); + return dirSize; + } + catch + { + return -1; + } + } + + static long DirSize(DirectoryInfo d) + { + long size = 0; + FileInfo[] fis = d.GetFiles(); + foreach (FileInfo fi in fis) + { + size += fi.Length; + } + DirectoryInfo[] dis = d.GetDirectories(); + foreach (DirectoryInfo di in dis) { - return 0; + size += DirSize(di); } + return size; } void RecordStartup(LoggingSettings loggingSettings, EndpointConfiguration endpointConfiguration) { var version = FileVersionInfo.GetVersionInfo(typeof(Bootstrapper).Assembly.Location).ProductVersion; + var dataSize = DataSize(); + var folderSize = FolderSize(); var startupMessage = $@" ------------------------------------------------------------- ServiceControl Version: {version} @@ -193,7 +226,8 @@ Audit Retention Period (optional): {settings.AuditRetentionPeriod} Error Retention Period: {settings.ErrorRetentionPeriod} Ingest Error Messages: {settings.IngestErrorMessages} Forwarding Error Messages: {settings.ForwardErrorMessages} -Database Size: {DataSize()} bytes +Database Size: {ByteSize.FromBytes(dataSize).ToString("#.##", CultureInfo.InvariantCulture)} +Database Folder Size: {ByteSize.FromBytes(folderSize).ToString("#.##", CultureInfo.InvariantCulture)} ServiceControl Logging Level: {loggingSettings.LoggingLevel} RavenDB Logging Level: {loggingSettings.RavenDBLogLevel} Selected Transport Customization: {settings.TransportCustomizationType} @@ -254,4 +288,4 @@ public ConstructorInfo[] FindConstructors(Type targetType) static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); } } -} \ No newline at end of file +} diff --git a/src/ServiceControl/ServiceControl.csproj b/src/ServiceControl/ServiceControl.csproj index e54477a730..1fa6109c04 100644 --- a/src/ServiceControl/ServiceControl.csproj +++ b/src/ServiceControl/ServiceControl.csproj @@ -21,6 +21,7 @@ +