public void WithPrometheusEndpointReportPathEncodingTest() { var context = new DefaultMetricsContext(); var endpointReports = new MetricsEndpointReports(context.DataProvider, () => new HealthStatus()); var reports = endpointReports.WithPrometheusEndpointReport("test/prometheus", new UTF8Encoding(false)); Assert.AreEqual(endpointReports, reports); }
public void WithPrometheusEndpointReportTest() { var context = new DefaultMetricsContext(); var endpointReports = new MetricsEndpointReports(context.DataProvider, () => new HealthStatus()); var reports = endpointReports.WithPrometheusEndpointReport(); Assert.AreEqual(endpointReports, reports); }
/// <summary> /// Expose the metrics information at: /// /metrics in human readable format /// /metrics/json in json format /// <code> /// protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) /// { /// base.ApplicationStartup(container, pipelines); /// /// NancyMetrics.Configure() /// .WithGlobalMetrics(config => config.RegisterAllMetrics(pipelines)) /// .WithMetricsEndpoint(m => m.RequiresAuthentication()); // to enable authentication /// } /// </code> /// </summary> /// <param name="moduleConfig">Action that can configure the Metrics Module ( for example to apply authentication )</param> /// <param name="config">Action that can configure the endpoint reports</param> /// <param name="metricsPath">Path where to expose the metrics</param> /// <returns>This instance to allow chaining of the configuration.</returns> public NancyMetricsConfig WithMetricsModule(Action <INancyModule> moduleConfig, Action <MetricsEndpointReports> config, string metricsPath = "/metrics") { var reportsConfig = new MetricsEndpointReports(this.metricsContext.DataProvider, this.healthStatus); config(reportsConfig); MetricsModule.Configure(moduleConfig, reportsConfig, metricsPath); return(this); }
/// <summary> /// /// </summary> /// <param name="config"></param> /// <param name="path"></param> /// <param name="encoding"></param> /// <param name="reportConfig"></param> /// <returns></returns> public static MetricsEndpointReports WithPrometheusEndpointReport( this MetricsEndpointReports config, string path, Encoding encoding, PrometheusReportConfig reportConfig = null) { reportConfig = reportConfig ?? new PrometheusReportConfig(); return(config.WithEndpointReport(path, (d, h, c) => new MetricsEndpointResponse(PrometheusReport.RenderMetrics(d, h, reportConfig), "text/plain", encoding))); }
/// <summary> /// Configure Owin metrics endpoint. /// </summary> /// <param name="config">Action used to configure the Owin Metrics endpoint.</param> /// <returns>Chainable configuration object.</returns> public OwinMetricsConfig WithMetricsEndpoint(Action <MetricsEndpointReports> config, string endpointPrefix = "metrics") { var endpointConfig = new MetricsEndpointReports(this.context.DataProvider, this.healthStatus); config(endpointConfig); var metricsEndpointMiddleware = new MetricsEndpointMiddleware(endpointPrefix, endpointConfig); this.middlewareRegistration(metricsEndpointMiddleware); return(this); }
public void WithPrometheusEndpointReportPathConfigTest() { var context = new DefaultMetricsContext(); var endpointReports = new MetricsEndpointReports(context.DataProvider, () => new HealthStatus()); var config = new PrometheusReportConfig { OutputSetItems = true }; var reports = endpointReports.WithPrometheusEndpointReport(path: "test/prometheus", reportConfig: config); Assert.AreEqual(endpointReports, reports); }
internal static void Configure(Action <Module> moduleConfig, MetricsEndpointReports reports, string metricsPath) { // /ping // /text // /health // /json // /v1/health // /v1/json // /v2/json var handler = new HapperMetricsEndpointHandler(reports.Endpoints); MetricsModule.Config = new ModuleConfig(moduleConfig, handler, metricsPath); }
public HapperMetricsConfig WithMetricsModule(Action <Module> moduleConfig, Action <MetricsEndpointReports> reportsConfig, string metricsPath = "/metrics") { if (_isDiabled) { return(this); } var endpointsReports = new MetricsEndpointReports(_metricsContext.DataProvider, _healthStatus); reportsConfig(endpointsReports); MetricsModule.Configure(moduleConfig, endpointsReports, metricsPath); return(this); }
/// <summary> /// Create HTTP endpoint where metrics will be available in various formats: /// GET / => visualization application /// GET /json => metrics serialized as JSON /// GET /text => metrics in human readable text format /// </summary> /// <param name="httpUriPrefix">prefix where to start HTTP endpoint</param> /// <param name="reportsConfig">Endpoint reports configuration</param> /// <param name="filter">Only report metrics that match the filter.</param> /// <param name="maxRetries">maximum number of attempts to start the http listener. Note the retry time between attempts is dependent on this value</param> /// <returns>Chain-able configuration object.</returns> public MetricsConfig WithHttpEndpoint(string httpUriPrefix, Action <MetricsEndpointReports> reportsConfig, MetricsFilter filter = null, int maxRetries = 3) { if (this.isDisabled) { return(this); } if (this.httpEndpoints.ContainsKey(httpUriPrefix)) { throw new InvalidOperationException($"Http URI prefix {httpUriPrefix} already configured."); } var endpointReports = new MetricsEndpointReports(this.context.DataProvider.WithFilter(filter), this.healthStatus); reportsConfig(endpointReports); var endpoint = MetricsHttpListener.StartHttpListenerAsync(httpUriPrefix, endpointReports.Endpoints, this.httpEndpointCancellation.Token, maxRetries); this.httpEndpoints.Add(httpUriPrefix, endpoint); return(this); }
/// <summary> /// Create HTTP endpoint where metrics will be available in various formats: /// GET / => visualization application /// GET /json => metrics serialized as JSON /// GET /text => metrics in human readable text format /// </summary> /// <param name="httpUriPrefix">prefix where to start HTTP endpoint</param> /// <param name="reportsConfig">Endpoint reports configuration</param> /// <param name="filter">Only report metrics that match the filter.</param> /// <param name="maxRetries">maximum number of attempts to start the http listener. Note the retry time between attempts is dependent on this value</param> /// <returns>Chain-able configuration object.</returns> public MetricsConfig WithHttpEndpoint(string httpUriPrefix, Action <MetricsEndpointReports> reportsConfig, MetricsFilter filter = null, int maxRetries = 3) { if (this.isDisabled) { return(this); } if (this.httpEndpoints.ContainsKey(httpUriPrefix)) { log.WarnFormat("Http uri prefix {0} already registered. Ignoring...", httpUriPrefix); return(this); } var endpointReports = new MetricsEndpointReports(this.context.DataProvider.WithFilter(filter), this.healthStatus); reportsConfig(endpointReports); var endpoint = MetricsHttpListener.StartHttpListenerAsync(httpUriPrefix, endpointReports.Endpoints, this.httpEndpointCancellation.Token, maxRetries); this.httpEndpoints.Add(httpUriPrefix, endpoint); return(this); }
/// <summary> /// /// </summary> /// <param name="config"></param> /// <param name="path"></param> /// <returns></returns> public static MetricsEndpointReports WithPrometheusEndpointReport(this MetricsEndpointReports config, string path = "/prometheus") { return(WithPrometheusEndpointReport(config, path, Encoding.ASCII)); }
/// <summary> /// /// </summary> /// <param name="config"></param> /// <param name="path"></param> /// <returns></returns> public static MetricsEndpointReports WithPrometheusEndpointReport(this MetricsEndpointReports config, string path = "prometheus") { Encoding utf8WithoutBom = new UTF8Encoding(false); return(WithPrometheusEndpointReport(config, path, utf8WithoutBom)); }
public static MetricsEndpointReports WithPing(this MetricsEndpointReports reports) { return(reports.WithEndpointReport("/ping", (d, h, r) => new MetricsEndpointResponse("pong", "text/plain"))); }
public static MetricsEndpointReports WithJsonReport(this MetricsEndpointReports reports, string endpoint) { return(reports.WithEndpointReport(endpoint, GetJsonResponse)); }
public static MetricsEndpointReports WithJsonHealthReport(this MetricsEndpointReports reports, string endpoint, bool alwaysReturnOkStatusCode = false) { return(reports.WithEndpointReport(endpoint, (d, h, r) => GetHealthResponse(h, alwaysReturnOkStatusCode))); }
public static MetricsEndpointReports WithTextReport(this MetricsEndpointReports reports, string endpoint) { return(reports.WithEndpointReport(endpoint, (d, h, c) => new MetricsEndpointResponse(StringReport.RenderMetrics(d, h), "text/plain"))); }
public MetricsEndpointMiddleware(string endpointPrefix, MetricsEndpointReports endpointConfig) { this.endpointPrefix = NormalizePrefix(endpointPrefix); this.endpointHandler = new OwinMetricsEndpointHandler(endpointConfig.Endpoints); }
internal static void Configure(Action <INancyModule> moduleConfig, MetricsEndpointReports reports, string metricsPath) { var handler = new NancyMetricsEndpointHandler(reports.Endpoints); MetricsModule.Config = new ModuleConfig(moduleConfig, handler, metricsPath); }