Added database size to stats, added total ram size to stats
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
namespace Server.Controllers;
|
||||
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using AdaptiveExpressions;
|
||||
using ElmahCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Server.Exceptions;
|
||||
using Server.Helper;
|
||||
using Server.Models;
|
||||
using Shared;
|
||||
@@ -73,6 +69,7 @@ public class ServerController : ControllerBase
|
||||
embeddingsCount += entry.Keys.Count;
|
||||
}
|
||||
var sqlHelper = DatabaseHelper.GetSQLHelper(_options.Value);
|
||||
var databaseTotalSize = DatabaseHelper.GetTotalDatabaseSize(sqlHelper);
|
||||
Task<long> entityCountTask = DatabaseHelper.CountEntities(sqlHelper);
|
||||
long queryCacheUtilization = 0;
|
||||
long queryCacheElementCount = 0;
|
||||
@@ -95,6 +92,10 @@ public class ServerController : ControllerBase
|
||||
}
|
||||
};
|
||||
long entityCount = await entityCountTask;
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
long ramTotalSize = GC.GetTotalMemory(false);
|
||||
|
||||
return new ServerGetStatsResult() {
|
||||
Success = true,
|
||||
@@ -106,7 +107,9 @@ public class ServerController : ControllerBase
|
||||
EmbeddingCacheUtilization = size,
|
||||
EmbeddingCacheMaxElementCount = _searchdomainManager.EmbeddingCacheMaxCount,
|
||||
EmbeddingCacheElementCount = elementCount,
|
||||
EmbeddingsCount = embeddingsCount
|
||||
EmbeddingsCount = embeddingsCount,
|
||||
DatabaseTotalSize = databaseTotalSize,
|
||||
RamTotalSize = ramTotalSize
|
||||
};
|
||||
} catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -224,6 +224,21 @@ public class DatabaseHelper(ILogger<DatabaseHelper> logger)
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long GetTotalDatabaseSize(SQLHelper helper)
|
||||
{
|
||||
Dictionary<string, dynamic> parameters = [];
|
||||
DbDataReader searchdomainSumReader = helper.ExecuteSQLCommand("SELECT SUM(Data_length) FROM information_schema.tables", parameters);
|
||||
try
|
||||
{
|
||||
bool success = searchdomainSumReader.Read();
|
||||
long result = success && !searchdomainSumReader.IsDBNull(0) ? searchdomainSumReader.GetInt64(0) : 0;
|
||||
return result;
|
||||
} finally
|
||||
{
|
||||
searchdomainSumReader.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<long> CountEntities(SQLHelper helper)
|
||||
{
|
||||
DbDataReader searchdomainSumReader = helper.ExecuteSQLCommand("SELECT COUNT(*) FROM entity;", []);
|
||||
|
||||
@@ -24,6 +24,24 @@
|
||||
|
||||
<div class="row g-4">
|
||||
|
||||
<!-- Server -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm h-100">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title fs-5">@T["Server"]</h2>
|
||||
|
||||
<div class="d-flex justify-content-between mt-2">
|
||||
<span>@T["Total RAM usage"]</span>
|
||||
<strong id="serverMemorySize"></strong>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between mt-2">
|
||||
<span>@T["Total Database size"]</span>
|
||||
<strong id="serverDatabaseSize"></strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Embedding Cache -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm h-100">
|
||||
@@ -175,6 +193,10 @@
|
||||
showThrobber(querycacheLoadedMaxElementCount);
|
||||
let querycacheLoadedElementCountProgressBar = document.getElementById("querycacheLoadedElementCountProgressBar");
|
||||
|
||||
let serverMemorySize = document.getElementById("serverMemorySize");
|
||||
showThrobber(serverMemorySize);
|
||||
let serverDatabaseSize = document.getElementById("serverDatabaseSize");
|
||||
showThrobber(serverDatabaseSize);
|
||||
|
||||
let healthchecksServer = document.getElementById("healthchecksServer");
|
||||
let healthchecksAiProvider = document.getElementById("healthchecksAiProvider");
|
||||
@@ -214,6 +236,10 @@
|
||||
hideThrobber(querycacheLoadedMaxElementCount);
|
||||
querycacheLoadedMaxElementCount.textContent = queryCacheMaxElementCountLoadedSearchdomainsOnly.toLocaleString();
|
||||
querycacheLoadedMaxElementCountProgressBar.style.width = `${queryCacheElementCount / queryCacheMaxElementCountLoadedSearchdomainsOnly * 100}%`;
|
||||
serverMemorySize.textContent = NumberOfBytesAsHumanReadable(result.RamTotalSize);
|
||||
hideThrobber(serverMemorySize);
|
||||
serverDatabaseSize.textContent = NumberOfBytesAsHumanReadable(result.DatabaseTotalSize);
|
||||
hideThrobber(serverDatabaseSize);
|
||||
});
|
||||
getHealthCheckStatusAndApply(healthchecksServer, "/healthz/Database");
|
||||
getHealthCheckStatusAndApply(healthchecksAiProvider, "/healthz/AIProvider");
|
||||
|
||||
Reference in New Issue
Block a user