Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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中的动态度量计数器-prometheus pushgateway_Spring Boot_Prometheus_Prometheus Pushgateway - Fatal编程技术网

Spring boot spring boot中的动态度量计数器-prometheus pushgateway

Spring boot spring boot中的动态度量计数器-prometheus pushgateway,spring-boot,prometheus,prometheus-pushgateway,Spring Boot,Prometheus,Prometheus Pushgateway,我有一个json格式的传入事件(到spring boot应用程序),其中包含一个名为“component”的字段。 我需要创建一个度量计数器,并将每个组件推送到prometheus pushgateway。 每种类型的组件都应该有单独的计数器。 如何实现这一点?您可以为此实现组件。 自动接线仪表注册 private MeterRegistry registry; 把柜台的地图放进去 private Map<String, Counter> counters = new Concur

我有一个json格式的传入事件(到spring boot应用程序),其中包含一个名为“component”的字段。 我需要创建一个度量计数器,并将每个组件推送到prometheus pushgateway。 每种类型的组件都应该有单独的计数器。
如何实现这一点?

您可以为此实现组件。 自动接线仪表注册

private MeterRegistry registry;
把柜台的地图放进去

private Map<String, Counter> counters = new ConcurrentHashMap<>();

您可以为此使用哈希映射。hashmap.put(component.name(),counter++)将解决这个问题。如何使用prometheus pushgateway实现计数器度量?什么是curl命令?谢谢
public void increment(String componentName){
  Counter counter = counters.get(componentName);
  if(counter == null) {
    counter = Counter.builder("your.metrics.name").tags("component", componentName).register(registry);
    counters.put(tagValue, counter);
  }
  counter.increment();
}