2021-08-27 15:03:47 +00:00
|
|
|
using App.Metrics;
|
2020-12-19 10:55:35 +00:00
|
|
|
|
|
|
|
using Autofac;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Core;
|
|
|
|
|
|
|
|
public class MetricsModule: Module
|
2020-12-19 10:55:35 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private readonly string _onlyContext;
|
2020-12-19 10:55:35 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public MetricsModule(string onlyContext = null)
|
|
|
|
{
|
|
|
|
_onlyContext = onlyContext;
|
|
|
|
}
|
2020-12-19 10:55:35 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
|
|
{
|
|
|
|
builder.Register(c => InitMetrics(c.Resolve<CoreConfig>()))
|
|
|
|
.AsSelf().As<IMetrics>().SingleInstance();
|
|
|
|
}
|
2020-12-19 10:55:35 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
private IMetricsRoot InitMetrics(CoreConfig config)
|
|
|
|
{
|
|
|
|
var builder = AppMetrics.CreateDefaultBuilder();
|
|
|
|
if (config.InfluxUrl != null && config.InfluxDb != null)
|
2022-03-23 23:28:51 +00:00
|
|
|
builder.Report.ToInfluxDb(config.InfluxUrl, config.InfluxDb);
|
2021-11-27 02:10:56 +00:00
|
|
|
if (_onlyContext != null)
|
|
|
|
builder.Filter.ByIncludingOnlyContext(_onlyContext);
|
|
|
|
return builder.Build();
|
2020-12-19 10:55:35 +00:00
|
|
|
}
|
|
|
|
}
|