首页 > 解决方案 > Spring Boot Micrometer 分层度量命名空间串联

问题描述

我有一个 Spring Boot Java 应用程序,并且正在将指标发送到分层 Graphite 指标系统。我正在使用 management.metrics.export.graphite.tags-as-prefix 并映射主机和应用程序来为我的指标添加前缀。然后我有一个带有命名空间jvm.memory.committed的度量,但度量命名空间是作为host.app.jvmMemoryCommitted.*. 所以它正在替换度量命名空间中的点(“.”),并替换命名空间的以下部分。

应用程序属性 management.metrics.export.graphite.tags-as-prefix=[host, app]

标签的定制器作为前缀。

    @Bean
    public MeterRegistryCustomizer<MeterRegistry> commonTags() {
        return r -> r.config().commonTags("host", "localhost", "app", "app");
    }

当我查看 .../actuator/metrics/jvm.memory.committed 端点时,我看到以下内容:

  "name": "jvm.memory.committed",
  "description": "The amount of memory in bytes that is committed for the Java virtual machine to use",
  "baseUnit": "bytes",
  "measurements": [
    {
      "statistic": "VALUE",
      "value": 759701504
    }
  ],
  "availableTags": [
    {
      "tag": "area",
      "values": [
        "heap",
        "nonheap"
      ]
    },
    {
      "tag": "app",
      "values": [
        "app"
      ]
    },
    {
      "tag": "host",
      "values": [
        "localhost"
      ]
    },
    {
      "tag": "id",
      "values": [
        "G1 Old Gen",
        "CodeHeap 'non-profiled nmethods'",
        "G1 Survivor Space",
        "Compressed Class Space",
        "Metaspace",
        "G1 Eden Space",
        "CodeHeap 'non-nmethods'"
      ]
    },
  ]
}

但是,当发送指标时,指标名称从 更改*.jvm.memory.committed.**.jvmMemoryCommitted.*。如何以点表示法保留指标命名空间?

请参阅下面的 tcpdump 输出:

$ sudo tcpdump -i any -A -s0 -vv udp port 2003 | grep -i committed
tcpdump: data link type PKTAP
tcpdump: listening on any, link-type PKTAP (Apple DLT_PKTAP), capture size 262144 bytes
....E....5..@............E...p..localhost.app.jvmMemoryCommitted.area.heap.id.G1_Eden_Space 178257920.00 1628102627
....E....5..@............E...p..localhost.app.jvmMemoryCommitted.area.heap.id.G1_Eden_Space 178257920.00 1628102627
....E...o...@............E...m..localhost.app.jvmMemoryCommitted.area.heap.id.G1_Old_Gen 465567744.00 1628102627
....E...o...@............E...m..localhost.app.jvmMemoryCommitted.area.heap.id.G1_Old_Gen 465567744.00 1628102627
....E.......@............E...s..localhost.app.jvmMemoryCommitted.area.heap.id.G1_Survivor_Space 10485760.00 1628102627
....E.......@............E...s..localhost.app.jvmMemoryCommitted.area.heap.id.G1_Survivor_Space 10485760.00 1628102627
....E...m...@............E...{..localhost.app.jvmMemoryCommitted.area.nonheap.id.CodeHeap_'non-nmethods' 3604480.00 1628102627
....E...m...@............E...{..localhost.app.jvmMemoryCommitted.area.nonheap.id.CodeHeap_'non-nmethods' 3604480.00 1628102627
....E....J..@............E......localhost.app.jvmMemoryCommitted.area.nonheap.id.CodeHeap_'non-profiled_nmethods' 10420224.00 1628102627
....E....J..@............E......localhost.app.jvmMemoryCommitted.area.nonheap.id.CodeHeap_'non-profiled_nmethods' 10420224.00 1628102627
....E.......@............E...z..localhost.app.jvmMemoryCommitted.area.nonheap.id.Compressed_Class_Space 9306112.00 1628102627
....E.......@............E...z..localhost.app.jvmMemoryCommitted.area.nonheap.id.Compressed_Class_Space 9306112.00 1628102627
....E....,..@............E...n..localhost.app.jvmMemoryCommitted.area.nonheap.id.Metaspace 69607424.00 1628102627
....E....,..@............E...n..localhost.app.jvmMemoryCommitted.area.nonheap.id.Metaspace 69607424.00 1628102627
^C444 packets captured
3200 packets received by filter
0 packets dropped by kernel```

I think the problem is that I'm using tags, but in a Hierarchical metrics system, but I can't figure out how to configure it properly. I can't seem to find my folly.

Spring Boot 2.5.2
Micrometer Core and Micrometer Registry Graphite 1.7.2

标签: graphitemicrometerspring-micrometer

解决方案


Graphite 使用 aHierarchicalNameMapper将指标名称和标签转换为分层字符串。

https://micrometer.io/docs/registry/graphite#_hierarchical_name_mapping

我不确定为什么您的映射器使用驼峰式命名您的指标名称,但是您可以HierarchicalNameMapper在构建自己的指标名称时进行设置,GraphiteMeterRegistry并对它们的生成方式进行微调控制。


推荐阅读