PluralKit/PluralKit.Core/Modules/MetricsModule.cs
spiral 770907f232
fix(api): load metrics reporting module
i don't know why this fixes it, but it does somehow
2022-11-25 08:53:24 +00:00

31 lines
850 B
C#

using App.Metrics;
using Autofac;
namespace PluralKit.Core;
public class MetricsModule: Module
{
private readonly string _onlyContext;
public MetricsModule(string onlyContext = null)
{
_onlyContext = onlyContext;
}
protected override void Load(ContainerBuilder builder)
{
builder.Register(c => InitMetrics(c.Resolve<CoreConfig>()))
.AsSelf().As<IMetrics>().SingleInstance().AutoActivate();
}
private IMetricsRoot InitMetrics(CoreConfig config)
{
var builder = AppMetrics.CreateDefaultBuilder();
if (config.InfluxUrl != null && config.InfluxDb != null)
builder.Report.ToInfluxDb(config.InfluxUrl, config.InfluxDb);
if (_onlyContext != null)
builder.Filter.ByIncludingOnlyContext(_onlyContext);
return builder.Build();
}
}