protected MetricHandler(CollectorRegistry registry = null)
 {
     _registry = registry ?? Metrics.DefaultRegistry;
 }
 internal MetricFactory(CollectorRegistry registry)
 {
     _registry = registry ?? throw new ArgumentNullException(nameof(registry));
 }
        public MetricServer(string hostname, int port, string url = "metrics/", CollectorRegistry registry = null, bool useHttps = false) : base(registry)
        {
            var s = useHttps ? "s" : "";

            _httpListener.Prefixes.Add($"http{s}://{hostname}:{port}/{url}");
        }
Example #4
0
        public MetricPusher(string endpoint, string job, string instance = null, long intervalMilliseconds = 1000, IEnumerable <Tuple <string, string> > additionalLabels = null, CollectorRegistry registry = null) : base(registry)
        {
            if (string.IsNullOrEmpty(endpoint))
            {
                throw new ArgumentNullException("endpoint");
            }
            if (string.IsNullOrEmpty(job))
            {
                throw new ArgumentNullException("job");
            }
            if (intervalMilliseconds <= 0)
            {
                throw new ArgumentException("Interval must be greater than zero", "intervalMilliseconds");
            }

            StringBuilder sb = new StringBuilder(string.Format("{0}/job/{1}", endpoint.TrimEnd('/'), job));

            if (!string.IsNullOrEmpty(instance))
            {
                sb.AppendFormat("/instance/{0}", instance);
            }

            if (additionalLabels != null)
            {
                foreach (var pair in additionalLabels)
                {
                    if (pair == null || string.IsNullOrEmpty(pair.Item1) || string.IsNullOrEmpty(pair.Item2))
                    {
                        throw new NotSupportedException($"Invalid {nameof(MetricPusher)} additional label: ({pair?.Item1}):({pair?.Item2})");
                    }

                    sb.AppendFormat("/{0}/{1}", pair.Item1, pair.Item2);
                }
            }

            if (!Uri.TryCreate(sb.ToString(), UriKind.Absolute, out _targetUrl))
            {
                throw new ArgumentException("Endpoint must be a valid url", "endpoint");
            }

            _pushInterval = TimeSpan.FromMilliseconds(intervalMilliseconds);
        }
 public MetricServer(int port, string url = "metrics/", CollectorRegistry registry = null, bool useHttps = false) : this("+", port, url, registry, useHttps)
 {
 }