This is an automated email from the ASF dual-hosted git repository. kbhatt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/atlas.git
commit 5dffddd005827137e35b72d837fdd51cd1ce4d5b Author: nikhilbonte <[email protected]> AuthorDate: Fri Oct 4 18:16:18 2019 +0530 ATLAS-3441 Add JVM resource metrics for Atlas monitoring Signed-off-by: kevalbhatt <[email protected]> --- .../org/apache/atlas/services/MetricsService.java | 8 ++ .../org/apache/atlas/util/AtlasMetricJVMUtil.java | 110 +++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/repository/src/main/java/org/apache/atlas/services/MetricsService.java b/repository/src/main/java/org/apache/atlas/services/MetricsService.java index 2a65b55..d566f73 100644 --- a/repository/src/main/java/org/apache/atlas/services/MetricsService.java +++ b/repository/src/main/java/org/apache/atlas/services/MetricsService.java @@ -27,6 +27,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.util.AtlasMetricsUtil; +import org.apache.atlas.util.AtlasMetricJVMUtil; import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,6 +51,7 @@ public class MetricsService { public static final String ENTITY = "entity"; public static final String TAG = "tag"; public static final String GENERAL = "general"; + public static final String SYSTEM = "system"; // Query names protected static final String METRIC_COLLECTION_TIME = "collectionTime"; @@ -62,6 +64,9 @@ public class MetricsService { protected static final String METRIC_ENTITY_SHELL = ENTITY + "Shell"; protected static final String METRIC_TAG_COUNT = TAG + "Count"; protected static final String METRIC_ENTITIES_PER_TAG = TAG + "Entities"; + protected static final String METRIC_RUNTIME = "runtime"; + protected static final String METRIC_MEMORY = "memory"; + protected static final String METRIC_OS = "os"; private final AtlasGraph atlasGraph; private final AtlasTypeRegistry typeRegistry; @@ -131,6 +136,9 @@ public class MetricsService { metrics.addMetric(ENTITY, METRIC_ENTITY_SHELL, getShellEntityCount()); metrics.addMetric(TAG, METRIC_ENTITIES_PER_TAG, taggedEntityCount); + metrics.addMetric(SYSTEM, METRIC_MEMORY, AtlasMetricJVMUtil.getMemoryDetails()); + metrics.addMetric(SYSTEM, METRIC_OS, AtlasMetricJVMUtil.getSystemInfo()); + metrics.addMetric(SYSTEM, METRIC_RUNTIME, AtlasMetricJVMUtil.getRuntimeInfo()); return metrics; } diff --git a/repository/src/main/java/org/apache/atlas/util/AtlasMetricJVMUtil.java b/repository/src/main/java/org/apache/atlas/util/AtlasMetricJVMUtil.java new file mode 100644 index 0000000..f1becf8 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/util/AtlasMetricJVMUtil.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.atlas.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.lang.management.MemoryPoolMXBean; +import java.lang.management.MemoryType; +import java.lang.management.MemoryUsage; +import java.lang.management.OperatingSystemMXBean; +import java.lang.management.RuntimeMXBean; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; + +public class AtlasMetricJVMUtil { + private static final Logger LOG = LoggerFactory.getLogger(AtlasMetricJVMUtil.class); + + private static final RuntimeMXBean RUNTIME; + private static final OperatingSystemMXBean OS; + private static final MemoryMXBean memBean; + + static { + RUNTIME = ManagementFactory.getRuntimeMXBean(); + OS = ManagementFactory.getOperatingSystemMXBean(); + memBean = ManagementFactory.getMemoryMXBean(); + } + + /** + * Collect general runtime information. + */ + public static Map<String, Object> getRuntimeInfo() { + Map<String, Object> vmDetails = new LinkedHashMap<>(); + vmDetails.put("name", RUNTIME.getVmName()); + vmDetails.put("version", RUNTIME.getSystemProperties().get("java.version")); + return vmDetails; + } + + /** + * Add memory details + */ + public static Map<String, Object> getMemoryDetails() { + Map<String, Object> memory = new LinkedHashMap<>(); + heapDetails(memory); + pooldivision(memory); + return memory; + } + + /** + * Collect system information. + */ + public static Map<String, Object> getSystemInfo() { + Map<String, Object> values = new LinkedHashMap<>(); + String[] osInfo = {OS.getName(), OS.getArch(), OS.getVersion()}; + values.put("os.spec", String.join(", ", osInfo)); + values.put("os.vcpus", String.valueOf(OS.getAvailableProcessors())); + return values; + } + + /** + * collect the pool division of java + */ + private static void pooldivision(Map<String, Object> memory) { + Map<String, Object> poolDivisionValues = new LinkedHashMap<>(); + for (MemoryPoolMXBean mpBean : ManagementFactory.getMemoryPoolMXBeans()) { + if (mpBean.getType() == MemoryType.HEAP) { + poolDivisionValues.put(mpBean.getName(), mpBean.getUsage()); + } + } + memory.put("memory_pool_usages", poolDivisionValues); + } + + /** + * Collect java heap details + */ + private static void heapDetails(Map<String, Object> memory) { + MemoryUsage memHeapUsage = memBean.getHeapMemoryUsage(); + MemoryUsage nonHeapUsage = memBean.getNonHeapMemoryUsage(); + memory.put("heapInit", String.valueOf(memHeapUsage.getInit())); + memory.put("heapMax", String.valueOf(memHeapUsage.getMax())); + memory.put("heapCommitted", String.valueOf(memHeapUsage.getCommitted())); + memory.put("heapUsed", String.valueOf(memHeapUsage.getUsed())); + memory.put("nonHeapInit", String.valueOf(nonHeapUsage.getInit())); + memory.put("nonHeapMax", String.valueOf(nonHeapUsage.getMax())); + memory.put("nonHeapCommitted", String.valueOf(nonHeapUsage.getCommitted())); + memory.put("nonHeapUsed", String.valueOf(nonHeapUsage.getUsed())); + } +} \ No newline at end of file
