/
ResourceUtilizationHealthCheckExtensions.cs
170 lines (151 loc) · 8.55 KB
/
ResourceUtilizationHealthCheckExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.DependencyInjection;
/// <summary>
/// Controls resource utilization health check features.
/// </summary>
public static class ResourceUtilizationHealthCheckExtensions
{
private const string HealthCheckName = "container resources";
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="tags">A list of tags that can be used to filter health checks.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" /> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, params string[] tags)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(tags);
_ = builder.Services.AddOptionsWithValidateOnStart<ResourceUtilizationHealthCheckOptions, ResourceUtilizationHealthCheckOptionsValidator>();
return builder.AddCheck<ResourceUtilizationHealthCheck>(HealthCheckName, tags: tags);
}
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="tags">A list of tags that can be used to filter health checks.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" /> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, IEnumerable<string> tags)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(tags);
_ = builder.Services.AddOptionsWithValidateOnStart<ResourceUtilizationHealthCheckOptions, ResourceUtilizationHealthCheckOptionsValidator>();
return builder.AddCheck<ResourceUtilizationHealthCheck>(HealthCheckName, tags: tags);
}
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="section">Configuration for <see cref="ResourceUtilizationHealthCheckOptions"/>.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" /> or <paramref name="section"/> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(
this IHealthChecksBuilder builder,
IConfigurationSection section)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(section);
_ = builder.Services.Configure<ResourceUtilizationHealthCheckOptions>(section);
return builder.AddResourceUtilizationHealthCheck();
}
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="section">Configuration section holding an instance of <see cref="ResourceUtilizationHealthCheckOptions"/>.</param>
/// <param name="tags">A list of tags that can be used to filter health checks.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" />, <paramref name="section"/> or <paramref name="tags"/> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(
this IHealthChecksBuilder builder,
IConfigurationSection section,
params string[] tags)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(section);
_ = Throw.IfNull(tags);
_ = builder.Services.Configure<ResourceUtilizationHealthCheckOptions>(section);
return builder.AddResourceUtilizationHealthCheck(tags);
}
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="section">Configuration section holding an instance of <see cref="ResourceUtilizationHealthCheckOptions"/>.</param>
/// <param name="tags">A list of tags that can be used to filter health checks.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" />, <paramref name="section"/> or <paramref name="tags"/> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(
this IHealthChecksBuilder builder,
IConfigurationSection section,
IEnumerable<string> tags)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(section);
_ = Throw.IfNull(tags);
_ = builder.Services.Configure<ResourceUtilizationHealthCheckOptions>(section);
return builder.AddResourceUtilizationHealthCheck(tags);
}
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="configure">Configuration callback.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" /> or <paramref name="configure"/> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(
this IHealthChecksBuilder builder,
Action<ResourceUtilizationHealthCheckOptions> configure)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(configure);
_ = builder.Services.Configure(configure);
return builder.AddResourceUtilizationHealthCheck();
}
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="configure">Configuration callback.</param>
/// <param name="tags">A list of tags that can be used to filter health checks.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" />, <paramref name="configure"/> or <paramref name="tags"/> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(
this IHealthChecksBuilder builder,
Action<ResourceUtilizationHealthCheckOptions> configure,
params string[] tags)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(configure);
_ = Throw.IfNull(tags);
_ = builder.Services.Configure(configure);
return builder.AddResourceUtilizationHealthCheck(tags);
}
/// <summary>
/// Registers a health check provider that monitors resource utilization to assess the application's health.
/// </summary>
/// <param name="builder">The builder to add the provider to.</param>
/// <param name="configure">Configuration callback.</param>
/// <param name="tags">A list of tags that can be used to filter health checks.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder" />, <paramref name="configure"/> or <paramref name="tags"/> is <see langword="null" />.</exception>
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(
this IHealthChecksBuilder builder,
Action<ResourceUtilizationHealthCheckOptions> configure,
IEnumerable<string> tags)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(configure);
_ = Throw.IfNull(tags);
_ = builder.Services.Configure(configure);
return builder.AddResourceUtilizationHealthCheck(tags);
}
}