Skip to content

hardware monitoring thread

Muhammad Yafi edited this page Jun 15, 2016 · 1 revision

Hardware Monitoring Thread

The hardware monitoring uses JMX for profiling memory and CPU usage using MemoryPoolMXBean and OperatingSystemMXBean. It is located at agent\src\main\java\com\github\yafithekid\project_y\agent\daemons.

The hardware monitors 4 resource:

  1. Memory Pool in the Java Virtual Machine
  2. Memory used in the operating system
  3. CPU usage in the Java Virtual Machine
  4. CPU usage in the operating system

Prerequisites

  1. Gradle Build Tool
  2. Understand the first setup

Steps

Ensure you have modified the DEFAULT_FILE_CONFIG_LOCATION in Config.java

package com.github.yafithekid.project_y.commons.config;

/**
 * This class represents data in the config file
 */
public class Config {
    public static final String DEFAULT_FILE_CONFIG_LOCATION = "change_to_your_config.json";

Modify the resourceMonitor in config.json. Set active key to true, sendToCollector to false, and debug to true.

...
"resourceMonitor" : {
    "active": true,
    "sendToCollector": false,
    "collectRateMillis": 1000,
    "debug": true
  },
...

Run example-java project with following command

java -javaagent:agent/build/libs/agent.jar -jar example-java/build/libs/example-java.jar

The result can be seen as follows

{"_prefix":"memspc","max":"251658240","name":"Code Cache","used":"2102336","type":"non_heap","timestamp":"1465975174000","commited":"2555904"}
{"_prefix":"memspc","max":"-1","name":"Metaspace","used":"5895584","type":"non_heap","timestamp":"1465975174000","commited":"6553600"}
{"_prefix":"memspc","max":"1073741824","name":"Compressed Class Space","used":"661048","type":"non_heap","timestamp":"1465975174000","commited":"786432"}
{"_prefix":"memspc","max":"697303040","name":"PS Eden Space","used":"11631416","type":"heap","timestamp":"1465975174000","commited":"34078720"}
{"_prefix":"memspc","max":"5242880","name":"PS Survivor Space","used":"0","type":"heap","timestamp":"1465975174000","commited":"5242880"}
{"_prefix":"memspc","max":"1416626176","name":"PS Old Gen","used":"0","type":"heap","timestamp":"1465975174000","commited":"89653248"}
{"_prefix":"appmem","max":"1888485376","used":"11631416","type":"heap","timestamp":"1465975174000","commited":"128974848"}
{"_prefix":"appmem","max":"-1","used":"8658968","type":"non_heap","timestamp":"1465975174000","commited":"9895936"}
{"load":"-1.0","_prefix":"appcpu","timestamp":"1465975174000"}
{"_prefix":"sysmem","max":"8497414144","used":"4604661760","timestamp":"1465975174000"}
{"load":"-1.0","_prefix":"syscpu","timestamp":"1465975174000"}

Explanation of prefix:

  1. memspc - Memory pool in JVM
  2. appmem - Memory usage in JVM
  3. sysmem - Memoy usage in operating system
  4. appcpu - CPU usage in JVM
  5. syscpu - CPU usage in operating system