Ejemplo n.º 1
0
        private ActionResult <MetricsData> GetByNameAndTag(string metric, string drilldown)
        {
            var splitted = drilldown.Split(':');

            if (splitted.Length != 2)
            {
                // ugly hack for the single sba request for: metrics/jvm.memory.used?tag=area:nonheap,id:Metaspace
                if (drilldown.ToUpperInvariant().Contains("METASPACE", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(new MetricsData()
                    {
                        Name = "jvm.memory.used",
                        BaseUnit = "bytes",
                        Description = "The amount of used memory",
                        Measurements = new List <Measurement>()
                        {
                            new Measurement
                            {
                                Statistic = "VALUE",
                                Value = 0,
                            },
                        },
                    });
                }

                return(BadRequest()); // todo return rfc error
            }

            var tag   = splitted[0];
            var value = splitted[1];

            var actuatorTag = new ActuatorTag(tag, value);

            try
            {
                var metricData = provider.GetMetricByNameAndTag(metric, actuatorTag);

                var result = new JsonResult(metricData)
                {
                    ContentType = Constants.ActuatorContentType,
                };

                return(result);
            }
            catch (KeyNotFoundException)
            {
                logger.LogDebug("'{metric}' not found", metric);
                return(NotFound());
            }
        }