/**
 * Copyright 2017 Pivotal Software, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micrometer.core.instrument.binder;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;

import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;

import static java.util.Collections.singletonList;

/**
 * Record metrics that report utilization of various memory and buffer pools.
 *
 * @see MemoryPoolMXBean
 * @see BufferPoolMXBean
 */
public class JvmMemoryMetrics implements MeterBinder {

    @Override
    public void bindTo(MeterRegistry registry) {
        for (BufferPoolMXBean bufferPoolBean : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
            Iterable<Tag> tags = singletonList(Tag.of("id", bufferPoolBean.getName()));

            registry.gauge("jvm.buffer.count", tags, bufferPoolBean, BufferPoolMXBean::getCount);
            registry.gauge("jvm.buffer.memory.used", tags, bufferPoolBean, BufferPoolMXBean::getMemoryUsed);
            registry.gauge("jvm.buffer.total.capacity", tags, bufferPoolBean, BufferPoolMXBean::getTotalCapacity);
        }

        for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class)) {
            Iterable<Tag> tags = singletonList(Tag.of("id", memoryPoolBean.getName()));

            registry.gauge("jvm.memory.used", tags, memoryPoolBean, (mem) -> mem.getUsage().getUsed());
            registry.gauge("jvm.memory.committed", tags, memoryPoolBean, (mem) -> mem.getUsage().getCommitted());
            registry.gauge("jvm.memory.max", tags, memoryPoolBean, (mem) -> mem.getUsage().getMax());
        }
    }
}

@@ -740,16 +740,59 @@
 ent.Tag;
+%0Aimport io.micrometer.core.instrument.Tags;
 %0A%0Aimport
@@ -1379,36 +1379,24 @@
  tags = 
-singletonList(Tag.of
+Tags.zip
 (%22id%22, b
@@ -1411,33 +1411,32 @@
 lBean.getName())
-)
 ;%0A%0A            r
@@ -1520,16 +1520,17 @@
 Count);%0A
+%0A
         
@@ -1539,32 +1539,39 @@
   registry.gauge
+Builder
 (%22jvm.buffer.mem
@@ -1580,22 +1580,16 @@
 y.used%22,
- tags,
  bufferP
@@ -1629,17 +1629,107 @@
 oryUsed)
-;
+%0A                .baseUnit(%22bytes%22)%0A                .tags(tags)%0A                .create();%0A
 %0A       
@@ -1739,32 +1739,39 @@
   registry.gauge
+Builder
 (%22jvm.buffer.tot
@@ -1783,22 +1783,16 @@
 pacity%22,
- tags,
  bufferP
@@ -1835,16 +1835,105 @@
 apacity)
+%0A                .baseUnit(%22bytes%22)%0A                .tags(tags)%0A                .create()
 ;%0A      
@@ -2085,28 +2085,16 @@
 s = 
-singletonList(Tag.of
+Tags.zip
 (%22id
@@ -2121,17 +2121,16 @@
 tName())
-)
 ;%0A%0A     
@@ -2142,32 +2142,39 @@
   registry.gauge
+Builder
 (%22jvm.memory.use
@@ -2172,30 +2172,24 @@
 emory.used%22,
- tags,
  memoryPoolB
@@ -2223,25 +2223,115 @@
 ).getUsed())
-;
+%0A                .baseUnit(%22bytes%22)%0A                .tags(tags)%0A                .create();%0A
 %0A           
@@ -2337,32 +2337,39 @@
   registry.gauge
+Builder
 (%22jvm.memory.com
@@ -2376,22 +2376,16 @@
 mitted%22,
- tags,
  memoryP
@@ -2432,17 +2432,107 @@
 itted())
-;
+%0A                .baseUnit(%22bytes%22)%0A                .tags(tags)%0A                .create();%0A
 %0A       
@@ -2546,24 +2546,31 @@
 gistry.gauge
+Builder
 (%22jvm.memory
@@ -2575,22 +2575,16 @@
 ry.max%22,
- tags,
  memoryP
@@ -2625,16 +2625,105 @@
 etMax())
+%0A                .baseUnit(%22bytes%22)%0A                .tags(tags)%0A                .create()
 ;%0A      

Add bytes base unit to JvmMemoryMetrics (issue #97)