Ejemplo n.º 1
0
        /// <summary>
        ///     Add the <see cref="GraphiteReporter" /> allowing metrics to be reported to Graphite.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="url">The base url where metrics are written.</param>
        /// <param name="flushInterval">
        ///     The <see cref="T:System.TimeSpan" /> interval used if intended to schedule metrics
        ///     reporting.
        /// </param>
        /// <param name="fieldsSetup">The metric fields to report as well as thier names.</param>
        /// <param name="optionsSetup">The setup action to configure the <see cref="MetricsGraphitePlainTextProtocolOptions"/> to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToGraphite(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            string url,
            TimeSpan flushInterval,
            Action <MetricFields> fieldsSetup = null,
            Action <MetricsGraphitePlainTextProtocolOptions> optionsSetup = null)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

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

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

            var plainTextProtocolOptions = new MetricsGraphitePlainTextProtocolOptions();

            optionsSetup?.Invoke(plainTextProtocolOptions);

            IMetricsOutputFormatter formatter;
            var defaultFields = new MetricFields();

            defaultFields.DefaultGraphiteMetricFieldNames();

            if (fieldsSetup == null)
            {
                formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(plainTextProtocolOptions, defaultFields);
            }
            else
            {
                fieldsSetup.Invoke(defaultFields);
                formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(plainTextProtocolOptions, defaultFields);
            }

            var options = new MetricsReportingGraphiteOptions
            {
                FlushInterval = flushInterval,
                Graphite      =
                {
                    BaseUri = uri
                },
                MetricsOutputFormatter = formatter
            };

            var httpClient = CreateClient(options, options.ClientPolicy);
            var reporter   = new GraphiteReporter(options, httpClient);

            var builder = metricReporterProviderBuilder.Using(reporter);

            builder.OutputMetrics.AsGraphitePlainTextProtocol(plainTextProtocolOptions, defaultFields);

            return(builder);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Add the <see cref="MetricsStatsDStringOutputFormatter" /> allowing metrics to be reported to StatsD over TCP.
        /// </summary>
        /// <param name="metricsReportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The StatsD reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToStatsDTcp(
            this IMetricsReportingBuilder metricsReportingBuilder,
            Action <MetricsReportingStatsDOptions> setupAction)
        {
            if (metricsReportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricsReportingBuilder));
            }

            var options = new MetricsReportingStatsDOptions();

            setupAction?.Invoke(options);

            var formatter = new MetricsStatsDStringOutputFormatter(options.StatsDOptions);

            return(metricsReportingBuilder.OverTcp(
                       opt =>
            {
                opt.MetricsOutputFormatter = formatter;
                opt.FlushInterval = options.FlushInterval;
                opt.SocketSettings = options.SocketSettings;
                opt.SocketPolicy = options.SocketPolicy;
                opt.Filter = options.Filter;
            }));
        }
Ejemplo n.º 3
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));
        }
        /// <summary>
        ///     Add the <see cref="DatadogReporter" /> allowing metrics to be reported to Datadog.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="url">The base url where metrics are written.</param>
        /// <param name="apiKey">The api key used for authentication</param>
        /// <param name="fieldsSetup">The metric fields to report as well as their names.</param>
        /// <param name="datadogOptionsSetup">The setup action to configure the <see cref="MetricsDatadogOptions"/> to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToDatadogHttp(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            string url,
            string apiKey,
            Action <MetricFields> fieldsSetup = null,
            Action <MetricsDatadogOptions> datadogOptionsSetup = null)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

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

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

            var datadogOptions = new MetricsDatadogOptions();

            var options = new MetricsReportingDatadogOptions
            {
                Datadog =
                {
                    BaseUri = uri,
                    ApiKey  = apiKey
                }
            };

            datadogOptionsSetup?.Invoke(datadogOptions);

            IMetricsOutputFormatter formatter;
            MetricFields            fields = null;

            if (fieldsSetup == null)
            {
                formatter = new MetricsDatadogJsonOutputFormatter(options.FlushInterval, datadogOptions);
            }
            else
            {
                fields = new MetricFields();
                fieldsSetup.Invoke(fields);
                formatter = new MetricsDatadogJsonOutputFormatter(options.FlushInterval, datadogOptions, fields);
            }

            options.MetricsOutputFormatter = formatter;

            var httpClient = CreateClient(options, options.HttpPolicy);
            var reporter   = new DatadogReporter(options, httpClient);

            var builder = metricReporterProviderBuilder.Using(reporter);

            builder.OutputMetrics.AsDatadogJson(datadogOptions, options.FlushInterval, fields);

            return(builder);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Add the <see cref="InfluxDbMetricsReporter" /> allowing metrics to be reported to InfluxDB.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="url">The base url where InfluxDB is hosted.</param>
        /// <param name="database">The InfluxDB where metrics should be flushed.</param>
        /// <param name="fieldsSetup">The metric fields to report as well as thier names.</param>
        /// <param name="lineProtocolOptionsSetup">The setup action to configure the <see cref="MetricsInfluxDbLineProtocolOptions"/> to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToInfluxDb(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            string url,
            string database,
            Action <MetricFields> fieldsSetup = null,
            Action <MetricsInfluxDbLineProtocolOptions> lineProtocolOptionsSetup = null)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

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

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

            var lineProtocolOptions = new MetricsInfluxDbLineProtocolOptions();

            lineProtocolOptionsSetup?.Invoke(lineProtocolOptions);

            IMetricsOutputFormatter formatter;
            MetricFields            fields = null;

            if (fieldsSetup == null)
            {
                formatter = new MetricsInfluxDbLineProtocolOutputFormatter(lineProtocolOptions);
            }
            else
            {
                fields = new MetricFields();
                fieldsSetup.Invoke(fields);
                formatter = new MetricsInfluxDbLineProtocolOutputFormatter(lineProtocolOptions, fields);
            }

            var options = new MetricsReportingInfluxDbOptions
            {
                InfluxDb =
                {
                    BaseUri  = uri,
                    Database = database
                },
                MetricsOutputFormatter = formatter
            };

            var httpClient = CreateClient(options.InfluxDb, options.HttpPolicy);
            var reporter   = new InfluxDbMetricsReporter(options, httpClient);

            var builder = metricReporterProviderBuilder.Using(reporter);

            builder.OutputMetrics.AsInfluxDbLineProtocol(lineProtocolOptions, fields);

            return(builder);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Add the <see cref="ApplicationInsightsReporter" /> allowing metrics to be reported to Azure Application Insights.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="instrumentationKey">Application Insights instrumentation key.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToApplicationInsights(this IMetricsReportingBuilder reportingBuilder, string instrumentationKey)
        {
            var options = new ApplicationInsightsReporterOptions {
                InstrumentationKey = instrumentationKey
            };

            return(ToApplicationInsights(reportingBuilder, options));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Add the <see cref="ApplicationInsightsReporter" /> allowing metrics to be reported to Azure Application Insights.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToApplicationInsights(
            this IMetricsReportingBuilder reportingBuilder,
            Action <ApplicationInsightsReporterOptions> setupAction)
        {
            var options = new ApplicationInsightsReporterOptions();

            setupAction?.Invoke(options);
            return(ToApplicationInsights(reportingBuilder, options));
        }
        /// <summary>
        ///     Add the <see cref="ConsoleMetricsReporter" /> allowing metrics to be reported to console.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToConsole(this IMetricsReportingBuilder reportingBuilder)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            return(reportingBuilder.Using <ConsoleMetricsReporter>());
        }
        public void Chain(IMetricsReportingBuilder builder, IConfigurationSection configuration)
        {
            var sections = configuration.GetChildren();

            foreach (var section in sections)
            {
                var reporterType = section.Key.ToLower();
                if (builders.ContainsKey(reporterType))
                {
                    builders[reporterType].Chain(builder, section);
                }
            }
        }
        /// <summary>
        ///     Add the <see cref="CloudWatchReporter" /> allowing metrics to be reported to AWS CloudWatch.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToCloudWatch(
            this IMetricsReportingBuilder reportingBuilder,
            CloudWatchReporterOptions options)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var reporter = new CloudWatchReporter(options);

            return(reportingBuilder.Using(reporter));
        }
        /// <summary>
        ///     Add the <see cref="ApplicationInsightsReporter" /> allowing metrics to be reported to Azure Application Insights.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToApplicationInsights(
            this IMetricsReportingBuilder reportingBuilder,
            ApplicationInsightsReporterOptions options)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var reporter = new ApplicationInsightsReporter(options);

            return(reportingBuilder.Using(reporter));
        }
Ejemplo n.º 12
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 ToCloudWatch(
            this IMetricsReportingBuilder metricReporterProviderBuilder, string awsNamespace)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var options  = new MetricsReportingCloudWatchOptions(awsNamespace);
            var provider = new CloudWatchMetricsReporter(options);

            return(metricReporterProviderBuilder.Using(provider));
        }
 public override void UseMonitoring(IMetricsReportingBuilder builder)
 {
     builder.ToInfluxDb(options =>
     {
         options.InfluxDb.BaseUri  = _influxDbMonitoringOptions.BaseUri;
         options.InfluxDb.Database = _influxDbMonitoringOptions.Database;
         options.InfluxDb.CreateDataBaseIfNotExists = _influxDbMonitoringOptions.CreateDataBaseIfNotExists;
         options.FlushInterval      = _influxDbMonitoringOptions.FlushInterval;
         options.HttpPolicy.Timeout = _influxDbMonitoringOptions.Timeout;
         options.HttpPolicy.FailuresBeforeBackoff = _influxDbMonitoringOptions.FailuresBeforeBackoff;
         options.HttpPolicy.BackoffPeriod         = _influxDbMonitoringOptions.BackoffPeriod;
     });
 }
        /// <summary>
        ///     Add the <see cref="ConsoleMetricsReporter" /> allowing metrics to be reported to console.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The console reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToConsole(
            this IMetricsReportingBuilder reportingBuilder,
            MetricsReportingConsoleOptions options)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var provider = new ConsoleMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
        /// <summary>
        ///     Add the <see cref="WavefrontReporter" /> allowing metrics to be reported to
        ///     Wavefront.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The Wavefront reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToWavefront(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            MetricsReportingWavefrontOptions options)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var provider = new WavefrontReporter(options);

            return(metricReporterProviderBuilder.Using(provider));
        }
Ejemplo n.º 16
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));
        }
Ejemplo n.º 17
0
        public static IMetricsBuilder ToAliTSDB(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            MetricsReportingAliTSDBOptions options)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var httpClient = CreateClient(options.AliTSDB, options.HttpPolicy);
            var reporter   = new AliTSDBMetricsReporter(options, httpClient);

            return(metricReporterProviderBuilder.Using(reporter));
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     Add the <see cref="DatadogReporter" /> allowing metrics to be reported to Datadog.
        /// </summary>
        /// <param name="metricsReportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The Datadog reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToDatadogHttp(
            this IMetricsReportingBuilder metricsReportingBuilder,
            MetricsReportingDatadogOptions options)
        {
            if (metricsReportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricsReportingBuilder));
            }

            var httpClient = CreateClient(options, options.HttpPolicy);
            var reporter   = new DatadogReporter(options, httpClient);

            return(metricsReportingBuilder.Using(reporter));
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     Add the <see cref="GraphiteReporter" /> allowing metrics to be reported to Graphite.
        /// </summary>
        /// <param name="metricsReportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The Graphite reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToGraphite(
            this IMetricsReportingBuilder metricsReportingBuilder,
            MetricsReportingGraphiteOptions options)
        {
            if (metricsReportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricsReportingBuilder));
            }

            var httpClient = CreateClient(options, options.ClientPolicy);
            var reporter   = new GraphiteReporter(options, httpClient);

            return(metricsReportingBuilder.Using(reporter));
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The Socket reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverTcp(
            this IMetricsReportingBuilder reportingBuilder,
            MetricsReportingSocketOptions options)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            options.SocketSettings.ProtocolType = ProtocolType.Tcp;

            var provider = new SocketMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
        /// <summary>
        ///     Add the <see cref="ApplicationInsightsReporter" /> allowing metrics to be reported to Azure Application Insights.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToApplicationInsights(
            this IMetricsReportingBuilder reportingBuilder,
            Action <ApplicationInsightsReporterOptions> setupAction)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new ApplicationInsightsReporterOptions();

            setupAction?.Invoke(options);
            var reporter = new ApplicationInsightsReporter(options);

            return(reportingBuilder.Using(reporter));
        }
        /// <summary>
        ///     Add the <see cref="ConsoleMetricsReporter" /> allowing metrics to be reported to console.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The console reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToConsole(
            this IMetricsReportingBuilder reportingBuilder,
            Action <MetricsReportingConsoleOptions> setupAction)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new MetricsReportingConsoleOptions();

            setupAction?.Invoke(options);

            var provider = new ConsoleMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
        /// <summary>
        ///     Add the <see cref="SerilogMetricsReporter" /> allowing metrics to be reported to Serilog.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The Serilog reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToSerilog(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            Action <SerilogMetricsReporterOptions> setupAction)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var options = new SerilogMetricsReporterOptions();

            setupAction?.Invoke(options);

            var reporter = new SerilogMetricsReporter(options);

            return(metricReporterProviderBuilder.Using(reporter));
        }
        public static IMetricsBuilder ToMackerel(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            Action <MetricsReportingMackerelOptions> setupAction)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var options = new MetricsReportingMackerelOptions();

            setupAction?.Invoke(options);

            var provider = new MackerelMetricsReporter(options);

            return(metricReporterProviderBuilder.Using(provider));
        }
Ejemplo n.º 25
0
        /// <summary>
        ///     Add the <see cref="DatadogReporter" /> allowing metrics to be reported to Datadog.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The Datadog reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToDatadogHttp(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            Action <MetricsReportingDatadogOptions> setupAction)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var options = new MetricsReportingDatadogOptions();

            setupAction?.Invoke(options);

            var httpClient = CreateClient(options, options.HttpPolicy);
            var reporter   = new DatadogReporter(options, httpClient);

            return(metricReporterProviderBuilder.Using(reporter));
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Add the <see cref="TextFileMetricsReporter" /> allowing metrics to be reported to text file. Default output
        ///     ./metrics.txt
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="output">The absolute directory and file name of the file where metric values are written.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToTextFile(
            this IMetricsReportingBuilder reportingBuilder,
            string output)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new MetricsReportingTextFileOptions
            {
                OutputPathAndFileName = output
            };

            var reporter = new TextFileMetricsReporter(options);

            return(reportingBuilder.Using(reporter));
        }
Ejemplo n.º 27
0
        /// <summary>
        ///     Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The Socket reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverTcp(
            this IMetricsReportingBuilder reportingBuilder,
            Action <MetricsReportingSocketOptions> setupAction)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new MetricsReportingSocketOptions();

            setupAction?.Invoke(options);

            options.SocketSettings.ProtocolType = ProtocolType.Tcp;

            var provider = new SocketMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
Ejemplo n.º 28
0
        /// <summary>
        ///     Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over Unix Domain Sockets.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="metricsOutputFormatter">
        ///     The <see cref="IMetricsOutputFormatter" /> used to configure metrics output formatter.
        /// </param>
        /// <param name="address">The Unix Domain Socket endpoint address where metrics are POSTed.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverUds(
            this IMetricsReportingBuilder reportingBuilder,
            IMetricsOutputFormatter metricsOutputFormatter,
            string address)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new MetricsReportingSocketOptions
            {
                SocketSettings         = new SocketSettings(ProtocolType.IP, address, 0),
                MetricsOutputFormatter = metricsOutputFormatter
            };
            var provider = new SocketMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
        /// <summary>
        ///     Add the <see cref="WavefrontReporter" /> allowing metrics to be reported to
        ///     Wavefront.
        /// </summary>
        /// <param name="metricReporterProviderBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="wavefrontSender">
        ///     The <see cref="IWavefrontSender" /> that handles the formatting and flushing of
        ///     metrics to Wavefront, either via direct ingestion or the Wavefront Proxy Agent.
        /// </param>
        /// <param name="source">
        ///     The source of your metrics.
        /// </param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToWavefront(
            this IMetricsReportingBuilder metricReporterProviderBuilder,
            IWavefrontSender wavefrontSender,
            string source)
        {
            if (metricReporterProviderBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricReporterProviderBuilder));
            }

            var options = new MetricsReportingWavefrontOptions
            {
                WavefrontSender = wavefrontSender,
                Source          = source
            };

            var provider = new WavefrontReporter(options);

            return(metricReporterProviderBuilder.Using(provider));
        }
Ejemplo n.º 30
0
        /// <summary>
        ///     Add the <see cref="MetricsStatsDStringOutputFormatter" /> allowing metrics to be reported to StatsD over UDP.
        /// </summary>
        /// <param name="metricsReportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The StatsD reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToStatsDUdp(
            this IMetricsReportingBuilder metricsReportingBuilder,
            MetricsReportingStatsDOptions options)
        {
            if (metricsReportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricsReportingBuilder));
            }

            var formatter = new MetricsStatsDStringOutputFormatter(options.StatsDOptions);

            return(metricsReportingBuilder.OverUdp(
                       opt =>
            {
                opt.MetricsOutputFormatter = formatter;
                opt.FlushInterval = TimeSpan.Zero;
                opt.SocketSettings = options.SocketSettings;
                opt.SocketPolicy = options.SocketPolicy;
                opt.Filter = options.Filter;
            }));
        }