Skip to content

Commit

Permalink
added example of using grafana loki for nbomber serilog logger (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
mangystx authored May 12, 2024
1 parent 051cc5b commit dfdeb23
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.2" />

<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.117" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.31.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using NBomber.CSharp;
using Serilog;
using Serilog.Sinks.Grafana.Loki;

namespace Demo.Features.SerilogGrafanaLokiLogger;

public class SerilogGrafanaLokiExample
{
public void Run()
{
var scenario = Scenario.Create("hello_world_scenario", async context =>
{
await Task.Delay(1000);

context.Logger.Information("my log message: {0}", context.InvocationNumber);

return Response.Ok();
})
.WithoutWarmUp()
.WithLoadSimulations(
Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(30))
);

NBomberRunner
.RegisterScenarios(scenario)
.WithLoggerConfig(() =>
new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.GrafanaLoki("http://localhost:3100",
new [] {new LokiLabel {Key = "application", Value = "NBomber"}})
)
.Run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3"

services:
loki:
image: grafana/loki:master
ports:
- 3100:3100
command: -config.file=/etc/loki/local-config.yaml

grafana:
image: grafana/grafana:master
ports:
- "3000:3000"
4 changes: 3 additions & 1 deletion examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Demo.Features.ElasticsearchLogger;
using Demo.Features.RealtimeReporting.CustomReportingSink;
using Demo.Features.RealtimeReporting.InfluxDB;
using Demo.Features.SerilogGrafanaLokiLogger;
using Demo.Features.Timeouts;
using Demo.HelloWorld;
using Demo.HelloWorld.LoadSimulation;
Expand All @@ -24,7 +25,7 @@
// -------------------------------
// ----- Hello World examples -----
// -------------------------------
new HelloWorldExample().Run();
//new HelloWorldExample().Run();
// new ScenarioWithInit().Run();
// new ScenarioWithSteps().Run();
// new StepsShareData().Run();
Expand Down Expand Up @@ -60,6 +61,7 @@

// ---- Logs ----
// new ElasticsearchExample().Run();
new SerilogGrafanaLokiExample().Run();

// ---- Timeouts ----
// new ScenarioCompletionTimeout().Run();
Expand Down

0 comments on commit dfdeb23

Please sign in to comment.