Skip to content

Commit 6a421ad

Browse files
authored
Merge branch 'master' into master
2 parents 40c1ca6 + b76627c commit 6a421ad

30 files changed

+716
-596
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
# These are supported funding model platforms
2-
3-
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4-
patreon: ernado
5-
open_collective: # Replace with a single Open Collective username
6-
ko_fi: # Replace with a single Ko-fi username
7-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9-
liberapay: # Replace with a single Liberapay username
10-
issuehunt: # Replace with a single IssueHunt username
11-
otechie: # Replace with a single Otechie username
12-
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1+
github: [a-gubskiy]
2+
buy_me_a_coffee: g.andrew
3+
custom: ["http://andrew.gubskiy.com/donate"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Andrew Gubskiy
3+
Copyright (c) Andrew Gubskiy
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
# X.Spectator
22

3-
Framework for monitoring the state of the system and system modules.
3+
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.
4+
5+
More [information about library](https://andrey-gubskiy.medium.com/x-spectator-2-0-bea1c9073eab) on Medium.
6+
7+
## Features
8+
9+
- **Extensible API**: Flexible and extensible API, allowing for custom monitoring solutions.
10+
- **Ease of Use**: Simplified integration process with clear and concise documentation.
11+
- **Compatibility**: Seamlessly integrates with various .NET applications and services.
12+
13+
## Installation
14+
15+
To install X.Spectator 2.0, use the following NuGet command:
16+
17+
```bash
18+
dotnet add package X.Spectator --version 2.0.0
19+
```
20+
21+
Or add the package directly to your `csproj` file:
22+
23+
```xml
24+
<PackageReference Include="X.Spectator" Version="2.0.0" />
25+
```
26+
27+
## Contributing
28+
29+
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).
30+
31+
1. Fork the repository.
32+
2. Create your feature branch (`git checkout -b feature/YourFeature`).
33+
3. Commit your changes (`git commit -am 'Add some feature'`).
34+
4. Push to the branch (`git push origin feature/YourFeature`).
35+
5. Create a new Pull Request.
36+
37+
## License
38+
39+
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.

examples/Example.App/Example.App.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.2</TargetFramework>
6-
<LangVersion>7.1</LangVersion>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<LangVersion>default</LangVersion>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
11-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.2.0" />
10+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using Example.App.Services;
5+
using Microsoft.Extensions.Diagnostics.HealthChecks;
46
using X.Spectator.Base;
57

6-
namespace Example.App.Probes
8+
namespace Example.App.Probes;
9+
10+
/// <summary>
11+
/// Example probe
12+
/// </summary>
13+
public class LibraryServiceProbe : IProbe
714
{
8-
/// <summary>
9-
/// Example probe
10-
/// </summary>
11-
public class LibraryServiceProbe : IProbe
12-
{
13-
private readonly LibraryService _service;
14-
private readonly int _minimumBookCount;
15+
private readonly LibraryService _service;
16+
private readonly int _minimumBookCount;
1517

16-
public string Name => "Library Service Probe";
18+
public string Name => "Library Service Probe";
1719

18-
public LibraryServiceProbe(LibraryService service, int minimumBookCount)
19-
{
20-
_service = service;
21-
_minimumBookCount = minimumBookCount;
22-
}
20+
public LibraryServiceProbe(LibraryService service, int minimumBookCount)
21+
{
22+
_service = service;
23+
_minimumBookCount = minimumBookCount;
24+
}
2325

24-
public Task<ProbeResult> Check()
26+
public Task<ProbeResult> Check()
27+
{
28+
var result = new ProbeResult
2529
{
26-
var result = new ProbeResult
27-
{
28-
Time = DateTime.UtcNow,
29-
ProbeName = this.Name,
30-
Success = false
31-
};
30+
Time = DateTime.UtcNow,
31+
ProbeName = Name,
32+
Status = HealthStatus.Unhealthy
33+
};
3234

33-
try
34-
{
35-
if (_service.TotalBookCount > _minimumBookCount)
36-
{
37-
result.Success = true;
38-
}
39-
}
40-
catch (Exception ex)
35+
try
36+
{
37+
if (_service.TotalBookCount > _minimumBookCount)
4138
{
42-
result.Exception = ex;
43-
result.Data = ex.Message;
39+
result.Status = HealthStatus.Healthy;
4440
}
45-
46-
return Task.FromResult(result);
4741
}
42+
catch (Exception ex)
43+
{
44+
result.Exception = ex;
45+
result.Data = new Dictionary<string, object>{{"exception-message", ex.Message}};
46+
}
47+
48+
return Task.FromResult(result);
4849
}
49-
}
50+
}

examples/Example.App/Program.cs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,52 @@
33
using Example.App.Probes;
44
using Example.App.Services;
55
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Diagnostics.HealthChecks;
67
using Microsoft.Extensions.Hosting;
78
using X.Spectator.Base;
89

9-
namespace Example.App
10+
namespace Example.App;
11+
12+
public class Program
1013
{
11-
public class Program
14+
public static async Task Main(string[] args)
1215
{
13-
public static async Task Main(string[] args)
14-
{
15-
var host = new HostBuilder()
16-
.ConfigureServices((hostContext, services) =>
17-
{
18-
services
19-
.AddHostedService<CityHostedService>( );
20-
21-
services
22-
.AddSingleton<LibraryService>()
23-
.AddSingleton<PublishingHouseService>()
24-
.AddSingleton<LibraryServiceProbe>(CreateLibraryServiceProbe)
25-
.AddSingleton<IStateEvaluator<SystemState>, SystemStateEvaluator>()
26-
.AddSingleton<SystemSpectator>(CreateSystemSpectator);
27-
})
28-
.Build();
16+
var host = new HostBuilder()
17+
.ConfigureServices((hostContext, services) =>
18+
{
19+
services
20+
.AddHostedService<CityHostedService>()
21+
.AddSingleton<LibraryService>()
22+
.AddSingleton<PublishingHouseService>()
23+
.AddSingleton<LibraryServiceProbe>(CreateLibraryServiceProbe)
24+
.AddSingleton<IStateEvaluator<HealthStatus>, SystemStateEvaluator>()
25+
.AddSingleton<SystemSpectator>(CreateSystemSpectator);
26+
})
27+
.Build();
2928

30-
await host.RunAsync();
31-
}
29+
await host.RunAsync();
30+
}
3231

33-
private static LibraryServiceProbe CreateLibraryServiceProbe(IServiceProvider ctx)
34-
{
35-
var minimumBookCount = 20;
36-
var libraryService = ctx.GetService<LibraryService>();
32+
private static LibraryServiceProbe CreateLibraryServiceProbe(IServiceProvider ctx)
33+
{
34+
var minimumBookCount = 20;
35+
var libraryService = ctx.GetService<LibraryService>();
3736

38-
return new LibraryServiceProbe(libraryService, minimumBookCount);
39-
}
37+
return new LibraryServiceProbe(libraryService, minimumBookCount);
38+
}
4039

41-
private static SystemSpectator CreateSystemSpectator(IServiceProvider ctx)
42-
{
43-
var stateEvaluator = ctx.GetService<IStateEvaluator<SystemState>>();
44-
var libraryServiceProbe = ctx.GetService<LibraryServiceProbe>();
45-
var retentionPeriod = TimeSpan.FromMinutes(5);
46-
var checkHealthPeriod = TimeSpan.FromMilliseconds(500);
47-
var spectator = new SystemSpectator(checkHealthPeriod, stateEvaluator, retentionPeriod, SystemState.Normal);
48-
49-
spectator.AddProbe(libraryServiceProbe);
40+
private static SystemSpectator CreateSystemSpectator(IServiceProvider ctx)
41+
{
42+
var stateEvaluator = ctx.GetService<IStateEvaluator<HealthStatus>>();
43+
var libraryServiceProbe = ctx.GetService<LibraryServiceProbe>();
44+
var retentionPeriod = TimeSpan.FromMinutes(5);
45+
var checkHealthPeriod = TimeSpan.FromMilliseconds(500);
46+
var spectator = new SystemSpectator(checkHealthPeriod, stateEvaluator, retentionPeriod, HealthStatus.Healthy);
5047

51-
spectator.Start();
48+
spectator.AddProbe(libraryServiceProbe);
49+
50+
spectator.Start();
5251

53-
return spectator;
54-
}
52+
return spectator;
5553
}
56-
}
54+
}

0 commit comments

Comments
 (0)