Beispiel #1
0
        /// <summary>
        ///     Add the <see cref="HttpMetricsReporter" /> allowing metrics to be reported over HTTP.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="endpoint">The HTTP endpoint where metrics are POSTed.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverHttp(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            string endpoint)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            if (!Uri.TryCreate(endpoint, UriKind.Absolute, out var uri))
            {
                throw new InvalidOperationException($"{nameof(endpoint)} must be a valid absolute URI");
            }

            var options = new MetricsReportingHttpOptions {
                HttpSettings = new HttpSettings(uri)
            };
            var provider = new HttpMetricsReporter(options);

            return(metricReporterProviderBuilder.Using(provider));
        }
 public MetricsReportingMackerelOptions()
 {
     ApiBase     = API_BASE_DEFAULT;
     HttpOptions = new MetricsReportingHttpOptions()
     {
         // メトリックは1分毎に送出する
         FlushInterval = TimeSpan.FromSeconds(60)
     };
 }
        public DefaultHttpClient(MetricsReportingHttpOptions options)
        {
            if (options.HttpSettings.RequestUri == null)
            {
                throw new InvalidOperationException($"{nameof(HttpSettings.RequestUri)} is required to flush metric values over HTTP");
            }

            _httpClient            = CreateHttpClient(options.HttpSettings, options.HttpPolicy, options.InnerHttpMessageHandler);
            _httpSettings          = options.HttpSettings;
            _backOffPeriod         = options.HttpPolicy.BackoffPeriod;
            _failuresBeforeBackoff = options.HttpPolicy.FailuresBeforeBackoff;
            _failureAttempts       = 0;
        }
Beispiel #4
0
        /// <summary>
        ///     Add the <see cref="HttpMetricsReporter" /> allowing metrics to be reported over HTTP.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The HTTP reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverHttp(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            MetricsReportingHttpOptions options)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var provider = new HttpMetricsReporter(options);

            return(metricReporterProviderBuilder.Using(provider));
        }
Beispiel #5
0
        /// <summary>
        ///     Add the <see cref="HttpMetricsReporter" /> allowing metrics to be reported over HTTP.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The HTTP reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverHttp(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            Action <MetricsReportingHttpOptions> setupAction)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var options = new MetricsReportingHttpOptions();

            setupAction?.Invoke(options);

            var provider = new HttpMetricsReporter(options);

            return(metricReporterProviderBuilder.Using(provider));
        }
        /// <summary>
        /// Adds HTTP reporting.
        /// </summary>
        /// <param name="metricsBuilder">IMetricBuilder to add InfluxDB reporting to.</param>
        /// <param name="hostEnvironment">Provides information about the hosting environment an application is running in.</param>
        /// <param name="httpOptions">Configuration options of HTTP reporting. </param>
        static void AddOverHttp(this IMetricsBuilder metricsBuilder, IHostEnvironment hostEnvironment, MetricsReportingHttpOptions httpOptions)
        {
            if (httpOptions.HttpSettings.RequestUri == null)
            {
                return;
            }

            var jobName    = hostEnvironment.ApplicationName.Replace('/', '.');
            var requestUrl = $"{httpOptions.HttpSettings.RequestUri.AbsoluteUri.TrimEnd('/')}/job/{jobName}";

            httpOptions.HttpSettings.RequestUri = new Uri(requestUrl);
            httpOptions.MetricsOutputFormatter  = new MetricsPrometheusTextOutputFormatter();

            metricsBuilder.Report.OverHttp(httpOptions);
        }