2022-03-24 00:09:25 +00:00
|
|
|
using App.Metrics;
|
2022-03-23 18:24:09 +00:00
|
|
|
using App.Metrics.AspNetCore;
|
2022-03-24 00:09:25 +00:00
|
|
|
using App.Metrics.Formatters.Prometheus;
|
2022-03-23 18:24:09 +00:00
|
|
|
|
2021-08-01 19:22:23 +00:00
|
|
|
using Autofac.Extensions.DependencyInjection;
|
2020-01-26 00:27:45 +00:00
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
2020-08-27 21:36:02 +00:00
|
|
|
using Serilog;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.API;
|
|
|
|
|
|
|
|
public class Program
|
2019-07-09 18:39:29 +00:00
|
|
|
{
|
2022-03-24 00:09:25 +00:00
|
|
|
public static IMetricsRoot _metrics { get; set; }
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public static async Task Main(string[] args)
|
2019-07-09 18:39:29 +00:00
|
|
|
{
|
2022-03-24 00:09:25 +00:00
|
|
|
_metrics = AppMetrics.CreateDefaultBuilder()
|
|
|
|
.OutputMetrics.AsPrometheusPlainText()
|
|
|
|
.OutputMetrics.AsPrometheusProtobuf()
|
|
|
|
.Build();
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
InitUtils.InitStatic();
|
|
|
|
await BuildInfoService.LoadVersion();
|
2022-01-22 08:52:52 +00:00
|
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
var config = host.Services.GetRequiredService<CoreConfig>();
|
|
|
|
await host.Services.GetRequiredService<RedisService>().InitAsync(config);
|
|
|
|
await host.RunAsync();
|
2019-07-09 18:39:29 +00:00
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
Host.CreateDefaultBuilder(args)
|
2022-03-24 00:09:25 +00:00
|
|
|
.ConfigureMetrics(_metrics)
|
|
|
|
.UseMetricsWebTracking()
|
|
|
|
.UseMetricsEndpoints()
|
|
|
|
.UseMetrics(
|
|
|
|
options =>
|
|
|
|
{
|
|
|
|
options.EndpointOptions = endpointsOptions =>
|
|
|
|
{
|
|
|
|
endpointsOptions.MetricsTextEndpointOutputFormatter = _metrics.OutputMetricsFormatters.OfType<MetricsPrometheusTextOutputFormatter>().First();
|
|
|
|
endpointsOptions.MetricsEndpointOutputFormatter = _metrics.OutputMetricsFormatters.OfType<MetricsPrometheusProtobufOutputFormatter>().First();
|
|
|
|
};
|
|
|
|
})
|
2021-11-27 02:10:56 +00:00
|
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
|
|
|
.UseSerilog()
|
|
|
|
.ConfigureWebHostDefaults(whb => whb
|
|
|
|
.UseConfiguration(InitUtils.BuildConfiguration(args).Build())
|
|
|
|
.ConfigureKestrel(opts =>
|
|
|
|
{
|
|
|
|
opts.ListenAnyIP(opts.ApplicationServices.GetRequiredService<ApiConfig>().Port);
|
|
|
|
})
|
|
|
|
.UseStartup<Startup>());
|
2019-07-09 18:39:29 +00:00
|
|
|
}
|