Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy authored Sep 18, 2024
2 parents 40c1ca6 + b76627c commit 6a421ad
Show file tree
Hide file tree
Showing 30 changed files with 716 additions and 596 deletions.
15 changes: 3 additions & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: ernado
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
github: [a-gubskiy]
buy_me_a_coffee: g.andrew
custom: ["http://andrew.gubskiy.com/donate"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Andrew Gubskiy
Copyright (c) Andrew Gubskiy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# X.Spectator

Framework for monitoring the state of the system and system modules.
X.Spectator is a powerful library designed to help developers easily integrate real-time monitoring and analytics into their .NET applications. With X.Spectator 2.0, we introduce a range of new features and improvements that enhance performance, usability, and flexibility.

More [information about library](https://andrey-gubskiy.medium.com/x-spectator-2-0-bea1c9073eab) on Medium.

## Features

- **Extensible API**: Flexible and extensible API, allowing for custom monitoring solutions.
- **Ease of Use**: Simplified integration process with clear and concise documentation.
- **Compatibility**: Seamlessly integrates with various .NET applications and services.

## Installation

To install X.Spectator 2.0, use the following NuGet command:

```bash
dotnet add package X.Spectator --version 2.0.0
```

Or add the package directly to your `csproj` file:

```xml
<PackageReference Include="X.Spectator" Version="2.0.0" />
```

## Contributing

We welcome contributions to the X.Spectator project! If you have any ideas, bug reports, or pull requests, please visit our [GitHub repository](https://github.com/your-repo/x-spectator).

1. Fork the repository.
2. Create your feature branch (`git checkout -b feature/YourFeature`).
3. Commit your changes (`git commit -am 'Add some feature'`).
4. Push to the branch (`git push origin feature/YourFeature`).
5. Create a new Pull Request.

## License

X.Spectator 2.0 is licensed under the MIT License. See the [LICENSE](https://github.com/ernado-x/X.Spectator/blob/master/LICENSE) file for more details.
8 changes: 4 additions & 4 deletions examples/Example.App/Example.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
69 changes: 35 additions & 34 deletions examples/Example.App/Probes/LibraryServiceProbe.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Example.App.Services;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using X.Spectator.Base;

namespace Example.App.Probes
namespace Example.App.Probes;

/// <summary>
/// Example probe
/// </summary>
public class LibraryServiceProbe : IProbe
{
/// <summary>
/// Example probe
/// </summary>
public class LibraryServiceProbe : IProbe
{
private readonly LibraryService _service;
private readonly int _minimumBookCount;
private readonly LibraryService _service;
private readonly int _minimumBookCount;

public string Name => "Library Service Probe";
public string Name => "Library Service Probe";

public LibraryServiceProbe(LibraryService service, int minimumBookCount)
{
_service = service;
_minimumBookCount = minimumBookCount;
}
public LibraryServiceProbe(LibraryService service, int minimumBookCount)
{
_service = service;
_minimumBookCount = minimumBookCount;
}

public Task<ProbeResult> Check()
public Task<ProbeResult> Check()
{
var result = new ProbeResult
{
var result = new ProbeResult
{
Time = DateTime.UtcNow,
ProbeName = this.Name,
Success = false
};
Time = DateTime.UtcNow,
ProbeName = Name,
Status = HealthStatus.Unhealthy
};

try
{
if (_service.TotalBookCount > _minimumBookCount)
{
result.Success = true;
}
}
catch (Exception ex)
try
{
if (_service.TotalBookCount > _minimumBookCount)
{
result.Exception = ex;
result.Data = ex.Message;
result.Status = HealthStatus.Healthy;
}

return Task.FromResult(result);
}
catch (Exception ex)
{
result.Exception = ex;
result.Data = new Dictionary<string, object>{{"exception-message", ex.Message}};
}

return Task.FromResult(result);
}
}
}
76 changes: 37 additions & 39 deletions examples/Example.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,52 @@
using Example.App.Probes;
using Example.App.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using X.Spectator.Base;

namespace Example.App
namespace Example.App;

public class Program
{
public class Program
public static async Task Main(string[] args)
{
public static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureServices((hostContext, services) =>
{
services
.AddHostedService<CityHostedService>( );

services
.AddSingleton<LibraryService>()
.AddSingleton<PublishingHouseService>()
.AddSingleton<LibraryServiceProbe>(CreateLibraryServiceProbe)
.AddSingleton<IStateEvaluator<SystemState>, SystemStateEvaluator>()
.AddSingleton<SystemSpectator>(CreateSystemSpectator);
})
.Build();
var host = new HostBuilder()
.ConfigureServices((hostContext, services) =>
{
services
.AddHostedService<CityHostedService>()
.AddSingleton<LibraryService>()
.AddSingleton<PublishingHouseService>()
.AddSingleton<LibraryServiceProbe>(CreateLibraryServiceProbe)
.AddSingleton<IStateEvaluator<HealthStatus>, SystemStateEvaluator>()
.AddSingleton<SystemSpectator>(CreateSystemSpectator);
})
.Build();

await host.RunAsync();
}
await host.RunAsync();
}

private static LibraryServiceProbe CreateLibraryServiceProbe(IServiceProvider ctx)
{
var minimumBookCount = 20;
var libraryService = ctx.GetService<LibraryService>();
private static LibraryServiceProbe CreateLibraryServiceProbe(IServiceProvider ctx)
{
var minimumBookCount = 20;
var libraryService = ctx.GetService<LibraryService>();

return new LibraryServiceProbe(libraryService, minimumBookCount);
}
return new LibraryServiceProbe(libraryService, minimumBookCount);
}

private static SystemSpectator CreateSystemSpectator(IServiceProvider ctx)
{
var stateEvaluator = ctx.GetService<IStateEvaluator<SystemState>>();
var libraryServiceProbe = ctx.GetService<LibraryServiceProbe>();
var retentionPeriod = TimeSpan.FromMinutes(5);
var checkHealthPeriod = TimeSpan.FromMilliseconds(500);
var spectator = new SystemSpectator(checkHealthPeriod, stateEvaluator, retentionPeriod, SystemState.Normal);

spectator.AddProbe(libraryServiceProbe);
private static SystemSpectator CreateSystemSpectator(IServiceProvider ctx)
{
var stateEvaluator = ctx.GetService<IStateEvaluator<HealthStatus>>();
var libraryServiceProbe = ctx.GetService<LibraryServiceProbe>();
var retentionPeriod = TimeSpan.FromMinutes(5);
var checkHealthPeriod = TimeSpan.FromMilliseconds(500);
var spectator = new SystemSpectator(checkHealthPeriod, stateEvaluator, retentionPeriod, HealthStatus.Healthy);

spectator.Start();
spectator.AddProbe(libraryServiceProbe);

spectator.Start();

return spectator;
}
return spectator;
}
}
}
Loading

0 comments on commit 6a421ad

Please sign in to comment.