99
1010namespace Prometheus . Client . MetricServer ;
1111
12- /// <inheritdoc cref="IMetricServer" />
1312/// <summary>
14- /// MetricSever based of Kestrel
13+ /// Kestrel-based implementation of the metrics server.
1514/// </summary>
1615public class MetricServer : IMetricServer
1716{
1817 private readonly MetricServerOptions _options ;
1918 private IWebHost _host ;
2019
2120 /// <summary>
22- /// Constructor
21+ /// Initialize a new instance of the <see cref="MetricServer"/> class with default options.
2322 /// </summary>
2423 public MetricServer ( )
2524 : this ( new MetricServerOptions ( ) )
2625 {
2726 }
2827
2928 /// <summary>
30- /// Constructor
29+ /// Initialize a new instance of the <see cref="MetricServer"/> class with the specified options.
3130 /// </summary>
31+ /// <param name="options">The server configuration options.</param>
3232 public MetricServer ( MetricServerOptions options )
3333 {
3434 ArgumentNullException . ThrowIfNull ( options ) ;
35-
3635 if ( ! options . MapPath . StartsWith ( '/' ) )
3736 options . MapPath = "/" + options . MapPath ;
38-
3937 _options = options ;
40-
4138 _options . CollectorRegistry ??= Metrics . DefaultCollectorRegistry ;
42-
4339 if ( _options . UseDefaultCollectors )
4440 options . CollectorRegistry . UseDefaultCollectors ( options . MetricPrefixName ) ;
4541 }
4642
47- /// <inheritdoc />
4843 public bool IsRunning => _host != null ;
4944
50- /// <inheritdoc />
5145 public void Start ( )
5246 {
5347 if ( IsRunning )
5448 return ;
55-
5649 var configBuilder = new ConfigurationBuilder ( ) ;
5750 configBuilder . Properties [ "parent" ] = this ;
5851 var config = configBuilder . Build ( ) ;
59-
6052 _host = new WebHostBuilder ( )
6153 . UseConfiguration ( config )
6254 . UseKestrel ( options =>
@@ -68,16 +60,13 @@ public void Start()
6860 . ConfigureServices ( services => { services . AddSingleton < IStartup > ( new Startup ( _options ) ) ; } )
6961 . UseSetting ( WebHostDefaults . ApplicationKey , typeof ( Startup ) . GetTypeInfo ( ) . Assembly . FullName )
7062 . Build ( ) ;
71-
7263 _host . Start ( ) ;
7364 }
7465
75- /// <inheritdoc />
7666 public void Stop ( )
7767 {
7868 if ( ! IsRunning )
7969 return ;
80-
8170 _host . Dispose ( ) ;
8271 _host = null ;
8372 }
@@ -101,14 +90,12 @@ public void Configure(IApplicationBuilder app)
10190 var contentType = _options . ResponseEncoding != null
10291 ? $ "{ Defaults . ContentType } ; charset={ _options . ResponseEncoding . BodyName } "
10392 : Defaults . ContentType ;
104-
10593 app . Map ( _options . MapPath , coreapp =>
10694 {
10795 coreapp . Run ( async context =>
10896 {
10997 var response = context . Response ;
11098 response . ContentType = contentType ;
111-
11299 await using var outputStream = response . Body ;
113100 await ScrapeHandler . ProcessAsync ( _options . CollectorRegistry , outputStream ) ;
114101 } ) ;
0 commit comments