Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 在spring boot 2.1.9.0版本中查找匹配的CachePublicMetrics_Spring Boot_Spring Mvc_Spring Cache - Fatal编程技术网

Spring boot 在spring boot 2.1.9.0版本中查找匹配的CachePublicMetrics

Spring boot 在spring boot 2.1.9.0版本中查找匹配的CachePublicMetrics,spring-boot,spring-mvc,spring-cache,Spring Boot,Spring Mvc,Spring Cache,我在(spring-boot.1.5.12版本)的一个控制器中使用以下类 我在Spring2.1.9版本中找不到匹配的类 下面是代码片段 import org.springframework.boot.actuate.endpoint.CachePublicMetrics; import org.springframework.boot.actuate.metrics.Metric; public class CachingControlle

我在(spring-boot.1.5.12版本)的一个控制器中使用以下类

我在Spring2.1.9版本中找不到匹配的类

下面是代码片段

        import org.springframework.boot.actuate.endpoint.CachePublicMetrics;
        import org.springframework.boot.actuate.metrics.Metric;  

        public class CachingController extends CloudRestTemplate {

        @Autowired
        private CachePublicMetrics metrics;

        public @ResponseBody Map<String, Object> getData(@Pattern(regexp=Constants.STRING_VALID_PATTERN, message=Constants.STRING_INVALID_MSG) @PathVariable(required = true) final String name) throws Exception {
        boolean success = false;
        Map<String, Object> m = Maps.newHashMap();
        Collection<Metric<?>> resp = new ArrayList<>();
        Collection<Metric<?>> mets = metrics.metrics();

        for (Iterator<Metric<?>> iterator = mets.iterator(); iterator.hasNext();) {
        Metric<?> met = iterator.next();
        String metName = met.getName();
        logger.debug(metName+":"+met.getValue());

        if(StringUtils.isNotEmpty(metName)
        && metName.indexOf(name) != -1 ){
        resp.add(met);
        }
        }
        }
import org.springframework.boot.actuate.endpoint.CachePublicMetrics;
导入org.springframework.boot.actuate.metrics.Metric;
公共类CachingController扩展CloudRestTemplate{
@自动连线
私有缓存公共度量;
public@ResponseBody映射getData(@Pattern(regexp=Constants.STRING\u VALID\u Pattern,message=Constants.STRING\u INVALID\u MSG)@PathVariable(required=true)最终字符串名)引发异常{
布尔成功=假;
Map m=Maps.newHashMap();
Collection>mets=metrics.metrics();

对于(迭代器我认为您应该更深入地研究Spring boot actuator,一旦您公开了所有端点,您可能会找到您要查找的内容。Spring boot提供了一系列预定义的端点,下面是Spring boot actuator端点的列表()

  • /auditevents:公开当前应用程序的审核事件信息
  • /bean:返回应用程序中所有springbean的列表
  • /缓存:提供有关可用缓存的信息
  • /运行状况:提供应用程序运行状况信息
  • /条件:提供自动配置期间评估的条件列表
  • /configprops:返回应用程序级属性的列表
  • /信息:提供有关当前应用程序的信息。可以在属性文件中配置此信息
  • /记录器:显示日志记录配置。此外,此端点可用于修改配置
  • /headdump:生成一个headdump文件并返回它
  • /度量:返回有关应用程序的各种度量。包括内存、堆和线程信息。但是,此终结点不返回任何度量。虽然它只返回可用度量的列表,但 可以在单独的请求中使用度量名称来获取各自的详细信息
  • /scheduledtasks:返回应用程序中计划任务的列表
  • /httptrace:以请求和响应的形式返回最后100个http交互。包括执行器端点
  • /映射:所有Http请求映射的列表。还包括执行器端点
编辑:

正如在评论中所讨论的,您需要访问/exactor/metrics/jvm.memory.max,您可以使用RestTemplate调用相同的命令。如果您想使用Java访问,您需要探索exactor API,我编写了一个快速程序,您可以参考相同的命令

@Autowired
private MetricsEndpoint metricsEndpoint;

public MetricResponse printJavaMaxMemMetrics() {

        ListNamesResponse listNames = metricsEndpoint.listNames();

        listNames.getNames().stream().forEach(name -> System.out.println(name));

        MetricResponse metric = metricsEndpoint.metric("jvm.memory.max", new ArrayList<>());
        System.out.println("metric (jvm.memory.max) ->" + metric);

        List<AvailableTag> availableTags = metric.getAvailableTags();

        availableTags.forEach(tag -> System.out.println(tag.getTag() + " : " + tag.getValues()));

        List<Sample> measurements = metric.getMeasurements();
        measurements.forEach(sample -> System.out.println(sample.getStatistic() + " : " + sample.getValue()));

        return metric;

    }
@Autowired
私有度量终点度量终点;
公共度量响应printJavaMaxMemMetrics(){
ListNamesResponse listNames=metricsEndpoint.listNames();
listNames.getNames().stream().forEach(name->System.out.println(name));
MetricResponse metric=metricsEndpoint.metric(“jvm.memory.max”,new ArrayList());
System.out.println(“metric(jvm.memory.max)->”+metric);
List availableTags=metric.getAvailableTags();
availableTags.forEach(tag->System.out.println(tag.getTag()+”:“+tag.getValues());
列表度量值=metric.getMeasures();
measurements.forEach(sample->System.out.println(sample.getStatistic()+“:”+sample.getValue());
返回度量;
}

@Shailesh你能检查一下吗。我已经看到了。{MetricName}。我如何调用getData()中的这个端点来读取给定名称的度量值?是的。它们已经给出了。/exactor/metrics/jvm.memory.max示例。这个。我应该在getData()中使用rest模板调用我吗是的,这是一种方式,编辑了我的答案,添加了一些代码。是的。我做了。但我还没有测试。我测试后会告诉你