From 8805ba55fdd536ae1ebe0e0e17ccf932f0472b3b Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Wed, 7 Apr 2021 00:08:54 +0200 Subject: [PATCH] Folder size --- .../Infrastructure/Bootstrapper.cs | 33 ++++++++++++++- src/ServiceControl/Bootstrapper.cs | 40 ++++++++++++++++--- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs b/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs index da296a82fe..43149c8641 100644 --- a/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs +++ b/src/ServiceControl.Audit/Infrastructure/Bootstrapper.cs @@ -168,6 +168,36 @@ 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; @@ -176,7 +206,8 @@ void RecordStartup(LoggingSettings loggingSettings, EndpointConfiguration endpoi ServiceControl Audit Version: {version} Audit Retention Period: {settings.AuditRetentionPeriod} Forwarding Audit Messages: {settings.ForwardAuditMessages} -Database Size: {DataSize()} bytes +Database Size: {DataSize():n0} bytes +Database Folder Size: {FolderSize():n0} bytes ServiceControl Logging Level: {loggingSettings.LoggingLevel} RavenDB Logging Level: {loggingSettings.RavenDBLogLevel} Selected Transport Customization: {settings.TransportCustomizationType} diff --git a/src/ServiceControl/Bootstrapper.cs b/src/ServiceControl/Bootstrapper.cs index 38371c359b..94131d6f6d 100644 --- a/src/ServiceControl/Bootstrapper.cs +++ b/src/ServiceControl/Bootstrapper.cs @@ -174,13 +174,42 @@ 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) @@ -193,7 +222,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: {DataSize():n0} bytes +Database Folder Size: {FolderSize():n0} bytes ServiceControl Logging Level: {loggingSettings.LoggingLevel} RavenDB Logging Level: {loggingSettings.RavenDBLogLevel} Selected Transport Customization: {settings.TransportCustomizationType} @@ -254,4 +284,4 @@ public ConstructorInfo[] FindConstructors(Type targetType) static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); } } -} \ No newline at end of file +}