示例#1
0
        public async Task <IActionResult> OldAsync(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(Json(""));
            }

            var metrics = await _services.AccessPageAndGetResources(url.NormalizeUrl());

            StringBuilder sb = new StringBuilder();

            foreach (var metric in metrics)
            {
                var fields = typeof(AssetPerformance).GetProperties()
                             .Where(methodInfo => methodInfo.GetCustomAttributes(typeof(PrometheusAttribute), true).Length > 0)
                             .ToList();
                foreach (var field in fields)
                {
                    var name = field.GetCustomAttributes(typeof(PrometheusAttribute), true)[0].ToString();

                    sb.AppendLine($"# HELP {name} TRL");
                    sb.AppendLine($"# TYPE {name} gauge");
                    sb.AppendLine($"{name}{{asset=\"{metric.name}\",type=\"{metric.entryType}\"}} {field.GetValue(metric)}");
                }
            }

            return(Ok(sb.ToString()));
        }