2025-02-25 00:45:13 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-10-01 22:41:07 -04:00
|
|
|
|
using meilisearch.NET;
|
|
|
|
|
using meilisearch.NET.Configurations;
|
2025-02-25 03:11:59 -05:00
|
|
|
|
using meilisearch.NET.example;
|
2024-10-01 22:41:07 -04:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static async Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
|
|
|
|
|
IHost host = CreateHostBuilder(args).Build();
|
|
|
|
|
var testService = host.Services.GetService<test>();
|
|
|
|
|
await host.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
|
.ConfigureAppConfiguration((hostingContext, configuration) =>
|
|
|
|
|
{
|
|
|
|
|
configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
2025-02-25 01:29:01 -05:00
|
|
|
|
configuration.AddEnvironmentVariables();
|
|
|
|
|
configuration.AddCommandLine(args);
|
2025-02-25 00:45:13 -05:00
|
|
|
|
})
|
|
|
|
|
.ConfigureServices((hostContext, services) =>
|
|
|
|
|
{
|
|
|
|
|
services.AddMeiliSearchService();
|
|
|
|
|
services.AddSingleton<test>();
|
2024-10-01 23:16:09 -04:00
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
// Add logging configuration
|
|
|
|
|
services.AddLogging(builder =>
|
|
|
|
|
{
|
|
|
|
|
builder.ClearProviders();
|
|
|
|
|
builder.AddConsole();
|
|
|
|
|
builder.SetMinimumLevel(LogLevel.Information);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.UseConsoleLifetime(options =>
|
|
|
|
|
{
|
2025-02-25 01:29:01 -05:00
|
|
|
|
options.SuppressStatusMessages = true;
|
2025-02-25 00:45:13 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-01 22:41:07 -04:00
|
|
|
|
|
|
|
|
|
public class test
|
|
|
|
|
{
|
2025-02-25 00:45:13 -05:00
|
|
|
|
private readonly ILogger<test> _logger;
|
|
|
|
|
|
2025-02-25 05:07:55 -05:00
|
|
|
|
public test(MeiliSearchService service, ILogger<test> logger)
|
2024-10-01 22:41:07 -04:00
|
|
|
|
{
|
2025-02-25 00:45:13 -05:00
|
|
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
|
|
|
|
2025-02-25 01:29:01 -05:00
|
|
|
|
// Wait until Meilisearch is running
|
2025-03-01 13:08:01 -05:00
|
|
|
|
while (!service.IsRunning())
|
2025-02-25 01:29:01 -05:00
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Waiting for Meilisearch to start...");
|
|
|
|
|
Task.Delay(1000).Wait(); // Wait for 1 second before checking again
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-01 13:08:01 -05:00
|
|
|
|
var usage = service.GetResourceUsage();
|
2025-03-01 03:13:00 -05:00
|
|
|
|
_logger.LogInformation($"Memory usage: {usage.MemoryUsageBytes} MB");
|
|
|
|
|
_logger.LogInformation($"CPU usage: {usage.CpuPercentage} %");
|
|
|
|
|
_logger.LogInformation($"Disk read: {usage.DiskReadBytes} MB");
|
|
|
|
|
_logger.LogInformation($"Disk write: {usage.DiskWriteBytes} MB");
|
|
|
|
|
_logger.LogInformation($"Thread count: {usage.ThreadCount}");
|
|
|
|
|
_logger.LogInformation($"Process ID: {usage.ProcessId}");
|
|
|
|
|
|
2025-03-01 13:08:01 -05:00
|
|
|
|
service.CreateIndex<document>("test");
|
2025-03-01 03:13:00 -05:00
|
|
|
|
|
2025-03-01 13:08:01 -05:00
|
|
|
|
service.AddDocument("test", new document()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
message = "Hello, Meilisearch!"
|
|
|
|
|
});
|
|
|
|
|
service.AddDocument("test", new document()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
message = "Hello, Meilisearch!"
|
|
|
|
|
});
|
|
|
|
|
service.AddDocument("test", new document()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
message = "Hello, Meilisearch!"
|
|
|
|
|
});
|
|
|
|
|
service.AddDocument("test", new document()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
message = "Hello, Meilisearch!"
|
|
|
|
|
});
|
|
|
|
|
service.AddDocument("test", new document()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
message = "Hello, Meilisearch!"
|
|
|
|
|
});
|
|
|
|
|
service.AddDocument("test", new document()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
message = "Hello, Meilisearch!"
|
|
|
|
|
});
|
|
|
|
|
service.AddDocument("test", new document()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
message = "Hello, Meilisearch!"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Task.Delay(10000).Wait();
|
|
|
|
|
service.SetIndexEnabled("test", false).Wait();
|
|
|
|
|
Task.Delay(10000).Wait();
|
|
|
|
|
usage = service.GetResourceUsage();
|
|
|
|
|
_logger.LogInformation($"Memory usage: {usage.MemoryUsageBytes} MB");
|
|
|
|
|
_logger.LogInformation($"CPU usage: {usage.CpuPercentage} %");
|
|
|
|
|
_logger.LogInformation($"Disk read: {usage.DiskReadBytes} MB");
|
|
|
|
|
_logger.LogInformation($"Disk write: {usage.DiskWriteBytes} MB");
|
|
|
|
|
_logger.LogInformation($"Thread count: {usage.ThreadCount}");
|
|
|
|
|
_logger.LogInformation($"Process ID: {usage.ProcessId}");
|
|
|
|
|
var storage = service.GetIndexStorageUsage("test");
|
|
|
|
|
var totalStorage = service.GetTotalStorageUsage();
|
|
|
|
|
_logger.LogInformation($"Index storage usage: {storage} MB");
|
|
|
|
|
_logger.LogInformation($"Total storage usage: {totalStorage} MB");
|
|
|
|
|
Task.Delay(10000).Wait();
|
|
|
|
|
service.SetIndexEnabled("test", false).Wait();
|
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
_logger.LogInformation("Test service initialized.");
|
2024-10-01 22:41:07 -04:00
|
|
|
|
}
|
2025-02-25 01:29:01 -05:00
|
|
|
|
}
|