Example #1
0
        /// <summary>
        /// Will send the given metrics in the specified format.  The IEnumerable will be materialized, and all data will be sent together
        /// asynchronously.  This call is not appropriate if the IEnumerable is infinite.
        /// </summary>
        /// <exception cref="ArgumentNullException">	Thrown when the configuration or metrics are null. </exception>
        /// <param name="configuration">	The configuration. </param>
        /// <param name="metrics">			The metrics. </param>
        public static void Send(IMetricPublishingConfiguration configuration, IEnumerable<IMetric> metrics)
        {
            if (null == configuration) { throw new ArgumentNullException("configuration"); }
            if (null == metrics) { throw new ArgumentNullException("metrics"); }

            Send(configuration.HostNameOrAddress, configuration.Port, configuration.Format, configuration.PrefixKey, metrics);
        }
Example #2
0
        /// <summary>	Initializes a new instance of the MetricClient class. </summary>
        /// <exception cref="ArgumentNullException">	Thrown when the configuration object is null. </exception>
        /// <param name="configuration">	The configuration. </param>
        public MetricClient(IMetricPublishingConfiguration configuration)
        {
            if (null == configuration) { throw new ArgumentNullException("configuration"); }
            if (string.IsNullOrEmpty(configuration.HostNameOrAddress)) { throw new ArgumentException("HostNameOrAddress cannot be null or empty", "configuration"); }
            if (!configuration.PrefixKey.IsValidKey()) { throw new ArgumentException("PrefixKey contains invalid characters", "configuration"); }

            _messenger = new UdpMessenger(configuration.HostNameOrAddress, configuration.Port);
            _key = configuration.PrefixKey;
            _format = configuration.Format;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the MonitoringTaskFactory class.
        /// </summary>
        /// <param name="counterSamplingConfig"></param>
        public MonitoringTaskFactory(ICounterSamplingConfiguration counterSamplingConfig, IMetricPublishingConfiguration metricPublishingConfig)
        {
            if (null == counterSamplingConfig) { throw new ArgumentNullException("counterSamplingConfig"); }
            if (null == metricPublishingConfig) { throw new ArgumentNullException("metricPublishingConfig"); }

            _counterSamplingConfig = counterSamplingConfig;
            _counterPaths = counterSamplingConfig.DefinitionFilePaths
                .SelectMany(path => CounterFileParser.ReadCountersFromFile(path.Path))
                .Union(_counterSamplingConfig.CounterNames.Select(name => name.Name.Trim()))
                .Distinct(StringComparer.CurrentCultureIgnoreCase)
                .ToList();
            _metricPublishingConfig = metricPublishingConfig;
        }
Example #4
0
        /// <summary>	Times a given Action and reports it as a Timing metrics to the server. </summary>
        /// <remarks>	Exceptions generated by the Action are not handled. </remarks>
        /// <exception cref="ArgumentNullException">	Thrown when the configuration or action are null. </exception>
        /// <param name="configuration">	The configuration. </param>
        /// <param name="action">			The action. </param>
        public static void Time(IMetricPublishingConfiguration configuration, Action action)
        {
            if (null == configuration)
            {
                throw new ArgumentNullException("configuration");
            }
            if (null == action)
            {
                throw new ArgumentNullException("action");
            }

            Time(configuration.HostNameOrAddress, configuration.Port, configuration.Format, configuration.PrefixKey, action);
        }
Example #5
0
        /// <summary>
        /// Will stream the given metrics in the specified format, breaking up the metrics into 10 packets at a time, where multiple metrics may
        /// comprise a single packet.  This call is appropriate for infinite IEnumerables.
        /// </summary>
        /// <exception cref="ArgumentNullException">	Thrown when the configuration or metrics are null. </exception>
        /// <param name="configuration">	The configuration. </param>
        /// <param name="metrics">			The metrics. </param>
        public static void Stream(IMetricPublishingConfiguration configuration, IEnumerable <IMetric> metrics)
        {
            if (null == configuration)
            {
                throw new ArgumentNullException("configuration");
            }
            if (null == metrics)
            {
                throw new ArgumentNullException("metrics");
            }

            Stream(configuration.HostNameOrAddress, configuration.Port, configuration.Format, configuration.PrefixKey, metrics);
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the MonitoringTaskFactory class.
        /// </summary>
        /// <param name="counterSamplingConfig"></param>
        public MonitoringTaskFactory(ICounterSamplingConfiguration counterSamplingConfig, IMetricPublishingConfiguration metricPublishingConfig)
        {
            if (null == counterSamplingConfig)
            {
                throw new ArgumentNullException("counterSamplingConfig");
            }
            if (null == metricPublishingConfig)
            {
                throw new ArgumentNullException("metricPublishingConfig");
            }

            _counterSamplingConfig = counterSamplingConfig;
            _counterPaths          = counterSamplingConfig.DefinitionFilePaths
                                     .SelectMany(path => CounterFileParser.ReadCountersFromFile(path.Path))
                                     .Union(_counterSamplingConfig.CounterNames.Select(name => name.Name.Trim()))
                                     .Distinct(StringComparer.CurrentCultureIgnoreCase)
                                     .ToList();
            _metricPublishingConfig = metricPublishingConfig;
        }
Example #7
0
        /// <summary>	Initializes a new instance of the MetricClient class. </summary>
        /// <exception cref="ArgumentNullException">	Thrown when the configuration object is null. </exception>
        /// <param name="configuration">	The configuration. </param>
        public MetricClient(IMetricPublishingConfiguration configuration)
        {
            if (null == configuration)
            {
                throw new ArgumentNullException("configuration");
            }
            if (string.IsNullOrEmpty(configuration.HostNameOrAddress))
            {
                throw new ArgumentException("HostNameOrAddress cannot be null or empty", "configuration");
            }
            if (!configuration.PrefixKey.IsValidKey())
            {
                throw new ArgumentException("PrefixKey contains invalid characters", "configuration");
            }

            _messenger = new UdpMessenger(configuration.HostNameOrAddress, configuration.Port);
            _key       = configuration.PrefixKey;
            _format    = configuration.Format;
        }
Example #8
0
        /// <summary>	Times a given Action and reports it as a Timing metrics to the server. </summary>
        /// <remarks>	Exceptions generated by the Action are not handled. </remarks>
        /// <exception cref="ArgumentNullException">	Thrown when the configuration or action are null. </exception>
        /// <param name="configuration">	The configuration. </param>
        /// <param name="action">			The action. </param>
        public static void Time(IMetricPublishingConfiguration configuration, Action action)
        {
            if (null == configuration) { throw new ArgumentNullException("configuration"); }
            if (null == action) { throw new ArgumentNullException("action"); }

            Time(configuration.HostNameOrAddress, configuration.Port, configuration.Format, configuration.PrefixKey, action);
        }