Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
Java Dropwizard指标获取每个REST请求的平均项目数_Java_Spring_Spring Boot_Dropwizard_Metrics - Fatal编程技术网

Java Dropwizard指标获取每个REST请求的平均项目数

Java Dropwizard指标获取每个REST请求的平均项目数,java,spring,spring-boot,dropwizard,metrics,Java,Spring,Spring Boot,Dropwizard,Metrics,我想使用Dropwizard metrics获得spring boot REST controller服务的每个请求列表中的平均项目数。我的控制器接收一个字符串,该字符串被序列化为RequestCollectionRequestCollection有一个由ID列表组成的列表ID字段。我想知道ids字段中所有请求的平均项数是多少 控制器 @RestController @RequestMapping("/api") public class ApiController { private

我想使用Dropwizard metrics获得spring boot REST controller服务的每个请求列表中的平均项目数。我的控制器接收一个字符串,该字符串被序列化为
RequestCollection
RequestCollection
有一个由ID列表组成的
列表ID
字段。我想知道
ids
字段中所有请求的平均项数是多少

控制器

@RestController
@RequestMapping("/api")
public class ApiController {

    private MetricRegistry metricRegistry;

    public ApiController(MetricRegistry metricRegistry) {
        this.metricRegistry = metricRegistry;
    }

    @GetMapping
    public String getFooBarred(
            @RequestParam(value = "params") String requestItem
    ) {
        RequestCollection request = request = new ObjectMapper()
                .registerModule(new JavaTimeModule())
                .readValue(requestItem, RequestCollection.class);

        // Add metric here to metricRegistry for average number of items 
        // in RequestCollection across all requests.
        // RequestCollection has a single property which is a List<Integer> ids

        return "foobar";
    }
}
在表、量表、计数器、直方图、仪表和计时器中,最适合您需要的可能是,它“测量数据流中的值分布:例如,搜索返回的结果数”

在每个请求中,只需使用集合的计数更新直方图

itemCount.update(collection.getIds().size());
报告会给你一些不同的统计数据,以及你想要的平均值

-- Histograms ----------------------------
com.example.RequestCollection.id-count
             count = 100
               min = 0
               max = 99
              mean = 45.47
            stddev = 31.65
            median = 45.00
              75% <= 73.00
              95% <= 94.00
              98% <= 99.00
              99% <= 99.00
            99.9% <= 99.00
——直方图----------------------------
com.example.RequestCollection.id-count
计数=100
最小值=0
最大值=99
平均值=45.47
STDEV=31.65
中位数=45.00

75%这太好了,谢谢!直方图数据保存多长时间?也就是说,它是一个跨特定时间跨度的移动窗口吗?它应该在应用程序的生命周期内存储。
itemCount.update(collection.getIds().size());
-- Histograms ----------------------------
com.example.RequestCollection.id-count
             count = 100
               min = 0
               max = 99
              mean = 45.47
            stddev = 31.65
            median = 45.00
              75% <= 73.00
              95% <= 94.00
              98% <= 99.00
              99% <= 99.00
            99.9% <= 99.00