示例#1
0
        public static void PackMeterSetItems <T>(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <T> valueSource,
            MeterValue.SetItem setItem)
        {
            var itemData = new Dictionary <string, object>();

            setItem.Value.AddMeterValues(itemData);
            itemData.Add("percent", setItem.Percent);

            var keys   = itemData.Keys.ToList();
            var values = keys.Select(k => itemData[k]);

            var tags = MetricTags.Concat(valueSource.Tags, setItem.Tags);

            if (valueSource.Group.IsPresent())
            {
                var groupTag = new MetricTags(MetricGroupTagKey, metricNameFormatter(string.Empty, valueSource.Name));
                payloadBuilder.Pack(metricNameFormatter(context, valueSource.Group + MetricSetItemSuffix), keys, values, MetricTags.Concat(groupTag, tags));

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name + MetricSetItemSuffix), keys, values, setItem.Tags);
        }
        public static void PackMeterSetItems <T>(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <T> valueSource,
            MeterValue.SetItem setItem)
        {
            var itemData = new Dictionary <string, object>();

            setItem.Value.AddMeterValues(itemData);
            itemData.AddIfNotNanOrInfinity("percent", setItem.Percent);

            var keys   = itemData.Keys.ToList();
            var values = keys.Select(k => itemData[k]);

            var tags = MetricTags.Concat(valueSource.Tags, setItem.Tags);

            if (valueSource.IsMultidimensional)
            {
                payloadBuilder.Pack(
                    metricNameFormatter(context, valueSource.MultidimensionalName + MetricSetItemSuffix),
                    keys,
                    values,
                    tags);

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name + MetricSetItemSuffix), keys, values, setItem.Tags);
        }
        public void ReportHealth(
            GlobalMetricTags globalTags,
            IEnumerable <HealthCheck.Result> healthyChecks,
            IEnumerable <HealthCheck.Result> degradedChecks,
            IEnumerable <HealthCheck.Result> unhealthyChecks)
        {
            _logger.LogTrace($"Packing Health Checks for {Name}");

            var unhealthy = unhealthyChecks as HealthCheck.Result[] ?? unhealthyChecks.ToArray();
            var degraded  = degradedChecks as HealthCheck.Result[] ?? degradedChecks.ToArray();

            var isUnhealthy = unhealthy.Any();
            var isDegraded  = degraded.Any();
            var healthy     = !isUnhealthy && !isDegraded;

            var healthStatusValue = 2;

            if (isUnhealthy)
            {
                healthStatusValue = 3;
            }
            else if (healthy)
            {
                healthStatusValue = 1;
            }

            var tags = new MetricTags(globalTags.Select(t => t.Key).ToArray(), globalTags.Select(t => t.Value).ToArray());

            _payloadBuilder.Pack("health", healthStatusValue, tags);

            var checks = unhealthy.Concat(degraded).Concat(healthyChecks);

            foreach (var healthCheck in checks)
            {
                var allTags = MetricTags.Concat(tags, new MetricTags("health_check", healthCheck.Name));

                if (healthCheck.Check.Status == HealthCheckStatus.Unhealthy)
                {
                    _payloadBuilder.Pack("health_checks__unhealhty", healthCheck.Check.Message, allTags);
                }
                else if (healthCheck.Check.Status == HealthCheckStatus.Healthy)
                {
                    _payloadBuilder.Pack("health_checks__healthy", healthCheck.Check.Message, allTags);
                }
                else if (healthCheck.Check.Status == HealthCheckStatus.Degraded)
                {
                    _payloadBuilder.Pack("health_checks__degraded", healthCheck.Check.Message, allTags);
                }
            }

            _logger.LogTrace($"Packed Health Checks for {Name}");
        }
示例#4
0
        public static void PackValueSource(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <double> valueSource)
        {
            if (valueSource.Group.IsPresent())
            {
                var groupTag = new MetricTags(MetricGroupTagKey, metricNameFormatter(string.Empty, valueSource.Name));
                payloadBuilder.Pack(metricNameFormatter(context, valueSource.Group), valueSource.Value, MetricTags.Concat(groupTag, valueSource.Tags));

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name), valueSource.Value, valueSource.Tags);
        }
        public static void PackValueSource(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <double> valueSource)
        {
            if (valueSource.IsMultidimensional)
            {
                payloadBuilder.Pack(
                    metricNameFormatter(context, valueSource.MultidimensionalName),
                    valueSource.Value,
                    valueSource.Tags);

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name), valueSource.Value, valueSource.Tags);
        }
示例#6
0
        public static void PackValueSource(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <CounterValue> valueSource,
            CounterValueSource counterValueSource)
        {
            var count = valueSource.ValueProvider.GetValue(resetMetric: counterValueSource.ResetOnReporting).Count;

            if (valueSource.Group.IsPresent())
            {
                var groupTag = new MetricTags(MetricGroupTagKey, metricNameFormatter(string.Empty, valueSource.Name));
                payloadBuilder.Pack(metricNameFormatter(context, valueSource.Group), count, MetricTags.Concat(groupTag, valueSource.Tags));

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name), count, valueSource.Tags);
        }
示例#7
0
        public static void PackValueSource <T>(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <T> valueSource,
            Dictionary <string, object> data)
        {
            var keys   = data.Keys.ToList();
            var values = keys.Select(k => data[k]);

            if (valueSource.Group.IsPresent())
            {
                var groupTag = new MetricTags(MetricGroupTagKey, metricNameFormatter(string.Empty, valueSource.Name));
                payloadBuilder.Pack(metricNameFormatter(context, valueSource.Group), keys, values, MetricTags.Concat(groupTag, valueSource.Tags));

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name), keys, values, valueSource.Tags);
        }
        public static void PackValueSource(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <CounterValue> valueSource,
            CounterValueSource counterValueSource)
        {
            var count = valueSource.ValueProvider.GetValue(resetMetric: counterValueSource.ResetOnReporting).Count;

            if (valueSource.IsMultidimensional)
            {
                payloadBuilder.Pack(
                    metricNameFormatter(context, valueSource.MultidimensionalName),
                    count,
                    valueSource.Tags);

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name), count, valueSource.Tags);
        }
        public static void PackValueSource <T>(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <T> valueSource,
            Dictionary <string, object> data)
        {
            var keys   = data.Keys.ToList();
            var values = keys.Select(k => data[k]);

            if (valueSource.IsMultidimensional)
            {
                payloadBuilder.Pack(
                    metricNameFormatter(context, valueSource.MultidimensionalName),
                    keys,
                    values,
                    valueSource.Tags);

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name), keys, values, valueSource.Tags);
        }