OTEL POC
This commit is contained in:
parent
8bea1496f4
commit
56ea91b890
13 changed files with 179 additions and 0 deletions
|
|
@ -417,6 +417,8 @@ public static class Core
|
|||
|
||||
VerifySerialization();
|
||||
|
||||
Telemetry.Start();
|
||||
|
||||
_now = DateTime.UtcNow;
|
||||
_firstTick = _tickCount = GetTimestamp();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ using Server.Targeting;
|
|||
using Server.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using CalcMoves = Server.Movement.Movement;
|
||||
|
||||
|
|
@ -196,6 +197,10 @@ public delegate int AOSStatusHandler(Mobile from, int index);
|
|||
/// </summary>
|
||||
public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPropertyListEntity, IValueLinkListNode<Mobile>
|
||||
{
|
||||
private static readonly Counter<long> mobilesCreatedCounter = Telemetry.MobilesMeter.CreateCounter<long>("mobiles_created_count");
|
||||
private static readonly Counter<long> mobilesDeletedCounter = Telemetry.MobilesMeter.CreateCounter<long>("mobiles_deleted_count");
|
||||
private static readonly Counter<long> mobilesKilledCounter = Telemetry.MobilesMeter.CreateCounter<long>("mobiles_killed_count");
|
||||
|
||||
// Allow four warmode changes in 0.5 seconds, any more will be delay for two seconds
|
||||
private const int WarmodeCatchCount = 4;
|
||||
|
||||
|
|
@ -364,6 +369,11 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
|
|||
DefaultMobileInit();
|
||||
|
||||
World.AddEntity(this);
|
||||
|
||||
mobilesCreatedCounter.Add(1, new KeyValuePair<string, object?>[]
|
||||
{
|
||||
new("Map", Map?.Name),
|
||||
});
|
||||
}
|
||||
|
||||
public Mobile(Serial serial)
|
||||
|
|
@ -2421,6 +2431,14 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
|
|||
|
||||
Region.OnRegionChange(this, m_Region, null);
|
||||
|
||||
if (Alive) {
|
||||
mobilesDeletedCounter.Add(1, new KeyValuePair<string, object?>[]
|
||||
{
|
||||
new("Map", Map?.Name),
|
||||
new("Region", Region?.Name),
|
||||
});
|
||||
}
|
||||
|
||||
m_Region = null;
|
||||
// Is the above line REALLY needed? The old Region system did NOT have said line
|
||||
// and worked fine, because of this a LOT of extra checks have to be done everywhere...
|
||||
|
|
@ -4801,6 +4819,13 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
|
|||
}
|
||||
}
|
||||
|
||||
mobilesKilledCounter.Add(1, new KeyValuePair<string, object?>[]
|
||||
{
|
||||
new("Map", Map?.Name),
|
||||
new("Region", Region?.Name),
|
||||
new("IsPlayer", Player),
|
||||
});
|
||||
|
||||
Region.OnDeath(this);
|
||||
OnDeath(c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.3.2" />
|
||||
<PackageReference Include="LibDeflate.Bindings" Version="1.0.2.120" />
|
||||
<PackageReference Include="OpenTelemetry" Version="1.10.0-beta.1" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0-beta.1" />
|
||||
<PackageReference Include="PollGroup" Version="1.5.1" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="8.0.0" />
|
||||
|
||||
|
|
|
|||
36
Projects/Server/Telemetry.cs
Normal file
36
Projects/Server/Telemetry.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Diagnostics.Metrics;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Resources;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public class Telemetry
|
||||
{
|
||||
public static MeterProvider MeterProvider { get; private set; }
|
||||
public static readonly Meter AccountingMeter = new("ModernUO.Accounting");
|
||||
public static readonly Meter ItemsMeter = new("ModernUO.Items");
|
||||
public static readonly Meter MobilesMeter = new("ModernUO.Mobiles");
|
||||
public static readonly Meter EconomyMeter = new("ModernUO.Economy");
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
MeterProvider = Sdk.CreateMeterProviderBuilder()
|
||||
.ConfigureResource(r => r.AddService("ModernUO"))
|
||||
.AddOtlpExporter(options =>
|
||||
{
|
||||
options.BatchExportProcessorOptions.ScheduledDelayMilliseconds = TimeSpan.FromSeconds(10.0).Milliseconds;
|
||||
})
|
||||
.AddMeter("ModernUO.Accounting")
|
||||
.AddMeter("ModernUO.Items")
|
||||
.AddMeter("ModernUO.Mobiles")
|
||||
.AddMeter("ModernUO.Economy")
|
||||
.AddView(
|
||||
"gold_created_histogram",
|
||||
new ExplicitBucketHistogramConfiguration()
|
||||
{ Boundaries = new double[] { 100, 200, 300, 400, 500, 700, 1000, 1500, 2000 } }
|
||||
)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue