@Override
   public void bindTo(MeterRegistry registry) {
      List<BufferPoolMXBean> bufferPoolBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
      for (BufferPoolMXBean bufferPoolBean : bufferPoolBeans) {
         String name = bufferPoolBean.getName();
         // avoid illegal characters due to beans named for example: "mapped - 'non-volatile memory'"
         String metricName = normalizeMetricName(name);
         Gauge.builder(PREFIX + "BufferPool.used.memory." + metricName, bufferPoolBean, BufferPoolMXBean::getMemoryUsed)
               .baseUnit(BaseUnits.BYTES)
               .description("The memory used by the NIO pool:" + name)
               .register(registry);
      }

      List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
      for (MemoryPoolMXBean memoryPoolBean : memoryPoolBeans) {
         String name = memoryPoolBean.getName();
         // avoid illegal characters due to beans named for example: "CodeHeap 'non-nmethods'"
         String metricName = normalizeMetricName(name);

         Gauge.builder(PREFIX + "memoryPool." + metricName + ".usage", memoryPoolBean, (mem) -> mem.getUsage().getUsed())
               .baseUnit(BaseUnits.BYTES)
               .description("Current usage of the " + name + " memory pool")
               .register(registry);

         Gauge.builder(PREFIX + "memoryPool." + metricName + ".usage.max", memoryPoolBean, (mem) -> mem.getPeakUsage().getUsed())
               .baseUnit(BaseUnits.BYTES)
               .description("Peak usage of the " + name + " memory pool")
               .register(registry);
      }
   }
@Test
    public void testMetricNamesContainOnlyValidCharacters() {
        SimpleMeterRegistry registry = new SimpleMeterRegistry();
        new VendorAdditionalMetrics().bindTo(registry);
        SoftAssert asserts = new SoftAssert();
        registry.getMeters().forEach(meter -> {
            asserts.assertTrue(meter.getId().getName().matches("[.\\w]+"), "metric name contains invalid characters: " + meter.getId().getName());
            asserts.assertTrue(meter.getId().getName().matches("^[^_].*[^_]$"), "metric name should not begin or end with an underscore: " + meter.getId().getName());
        });
        asserts.assertAll();
        registry.close();
    }