public void CollectAndSerialize() { using (var stream = new NullStream()) { ScrapeHandler.Process(_registry, stream); } }
private void StartListen() { _httpListener.Start(); IsRunning = true; while (IsRunning) { try { var context = _httpListener.GetContext(); var response = context.Response; response.ContentType = Defaults.ContentType; using (var outputStream = response.OutputStream) { ScrapeHandler.Process(Registry, outputStream); } } catch (HttpListenerException ex) { Trace.WriteLine($"Error in MetricServer: {ex}"); } } }
public void Get() { Response.StatusCode = 200; using (var outputStream = Response.Body) { ScrapeHandler.Process(CollectorRegistry.Instance, outputStream); } }
/// <inheritdoc /> public async Task PushAsync() { var memoryStream = ScrapeHandler.Process(_collectorRegistry); var response = await _httpClient.PostAsync(_targetUri, new StreamContent(memoryStream)); response.EnsureSuccessStatusCode(); memoryStream.Dispose(); }
public void Configure(IApplicationBuilder app) { app.Map(_mapPath, coreapp => { coreapp.Run(async context => { var response = context.Response; response.ContentType = Defaults.ContentType; using (var outputStream = response.Body) { ScrapeHandler.Process(_registry, outputStream); } await Task.FromResult(0).ConfigureAwait(false); }); }); }
private static Task Handle(HttpContext context) { var request = context.Request; var response = context.Response; if (request.Method == HttpMethods.Get) { _counter.Inc(); var registry = CollectorRegistry.Instance; response.StatusCode = 200; ScrapeHandler.Process(registry, response.Body); } else { response.StatusCode = StatusCodes.Status405MethodNotAllowed; } return(Task.CompletedTask); }
/// <summary> /// Add PrometheusServer request execution pipeline. /// </summary> public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder app, Action <PrometheusOptions> setupOptions) { var options = new PrometheusOptions(); setupOptions?.Invoke(options); if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (!options.MapPath.StartsWith("/")) { throw new ArgumentException($"MapPath '{options.MapPath}' should start with '/'"); } RegisterCollectors(options); app.Map(options.MapPath, coreapp => { coreapp.Run(async context => { var response = context.Response; response.ContentType = "text/plain; version=0.0.4"; using (var outputStream = response.Body) { ScrapeHandler.Process(options.CollectorRegistryInstance, outputStream); } await Task.FromResult(0).ConfigureAwait(false); }); }); return(app); }
public void Configure(IApplicationBuilder app) { app.Run(context => { if (context.Request.Path == _mapPath) { var response = context.Response; response.ContentType = Defaults.ContentType; using (var outputStream = response.Body) { ScrapeHandler.Process(_registry, outputStream); } return(Task.FromResult(true)); } context.Response.StatusCode = 404; return(Task.FromResult(true)); }); }
private void StartListen() { _httpListener.Start(); IsRunning = true; while (IsRunning) { try { var context = _httpListener.GetContext(); var request = context.Request; var response = context.Response; var rawUrl = request.RawUrl.EndsWith("/") ? request.RawUrl : request.RawUrl + "/"; if (rawUrl == _mapPath) { response.StatusCode = 200; response.ContentType = Defaults.ContentType; using (var outputStream = response.OutputStream) { ScrapeHandler.Process(Registry, outputStream); } } else { response.StatusCode = 404; using (var outputStream = response.OutputStream) { } } } catch (HttpListenerException ex) { Trace.WriteLine($"Error in MetricServer: {ex}"); } } }
public void Collect() { ScrapeHandler.Process(_registry, _stream); }