{"id":18865926,"url":"https://github.com/pnerg/jmx-runtime-json","last_synced_at":"2026-05-05T04:02:35.228Z","repository":{"id":37828778,"uuid":"331221918","full_name":"pnerg/jmx-runtime-json","owner":"pnerg","description":"Extracts runtime information using the JMX MxBeans and produces a json","archived":false,"fork":false,"pushed_at":"2024-04-10T18:08:46.000Z","size":123,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-30T22:14:56.679Z","etag":null,"topics":["java","jmx","json","memory","runtime","thread"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pnerg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-20T07:05:50.000Z","updated_at":"2021-11-23T09:29:31.000Z","dependencies_parsed_at":"2024-03-31T12:25:07.075Z","dependency_job_id":"87a659fb-c75e-4f72-82e5-0090476517bc","html_url":"https://github.com/pnerg/jmx-runtime-json","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnerg%2Fjmx-runtime-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnerg%2Fjmx-runtime-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnerg%2Fjmx-runtime-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnerg%2Fjmx-runtime-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pnerg","download_url":"https://codeload.github.com/pnerg/jmx-runtime-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239810014,"owners_count":19700723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jmx","json","memory","runtime","thread"],"created_at":"2024-11-08T05:05:01.206Z","updated_at":"2026-02-12T15:30:15.612Z","avatar_url":"https://github.com/pnerg.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build \u0026 Test](https://github.com/pnerg/jmx-runtime-json/workflows/Build%20\u0026%20Test/badge.svg)\n[![codecov](https://codecov.io/gh/pnerg/jmx-runtime-json/branch/master/graph/badge.svg?token=O8I3FS7RSI)](https://codecov.io/gh/pnerg/jmx-runtime-json)\n[![Javadoc](http://javadoc-badge.appspot.com/org.dmonix/jmx-runtime-json.svg?label=javadoc)](http://javadoc-badge.appspot.com/org.dmonix/jmx-runtime-json)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.dmonix/jmx-runtime-json/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.dmonix/jmx-runtime-json)\n\nJMX Runtime Information As Json\n-------\n\nThis little library helps to generate a json out of a selected set of the runtime information available in the JVM.   \nAll of the data is accessible over various managed beans (mbeans) available in the JVM.\n\nBut accessing this data over JMX when running the application in a Docker container is difficult the least to say.  \nMost applications however expose a web interface and possibly even health and or meta-information over HTTP.\n\nThe use case for this library is to convert JMX internal information into Json format that can be transported as e.g. a\nHTTP response for debugging purposes or just to be logged.\n\n# Usage\n\nThe Json is modularised into allowing for a builder pattern approach where one can choose to use one or more of the '\nmodules'.\n\n* class-loading - `withClassLoadingInfo`\n* garbage-collectors - `withGarbageCollectionInfo`\n* memory - `withMemoryInfo`\n* operating-system - `withOperatingSystemInfo`\n* runtime - `withRuntimeInfo`\n* thread - `withThreadInfo`\n\nBuilder pattern example:\n\n```\nJMXJsonBuilder.apply().withMemoryInfo().withRuntimeInfo();\n```\n\nThe easiest way to produce a Json with all the data supported by the library is to use one of the `allInfo()` methods.  \nOne can choose to get an optional stack trace for every thread by supplying the depth desired to print (three in this\nexample).  \nNot providing a depth defaults to zero, i.e. no stack trace at all.\n\n```\nString json = JMXJsonBuilder.allInfo(3).prettyPrint();\n```\n\nThis will create a Json like the one below (cut in some places for brevity).\n\n```\n{\n  \"operating-system\": {\n    \"name\": \"Mac OS X\",\n    \"architecture\": \"x86_64\",\n    \"version\": \"10.16\",\n    \"available-processors\": 16,\n    \"system-load-average\": 2.81396484375\n  },\n  \"memory\": {\n    \"heap\": {\n      \"init\": 1073741824,\n      \"committed\": 1073741824,\n      \"max\": 1073741824,\n      \"used\": 286342112,\n      \"pools\": [\n         {\n          \"name\": \"G1 Eden Space\",\n          \"usage\": {\n            \"init\": 54525952,\n            \"committed\": 46137344,\n            \"max\": -1,\n            \"used\": 4194304\n          },\n          \"peak-usage\": {\n            \"init\": 54525952,\n            \"committed\": 671088640,\n            \"max\": -1,\n            \"used\": 50331648\n          }\n        },\n        ...\n      ]   \n    },\n    \"non-heap\": {\n      \"init\": 2555904,\n      \"committed\": 178573312,\n      \"max\": -1,\n      \"used\": 164771184,\n      \"pools\": [\n       {\n          \"name\": \"CodeHeap 'non-nmethods'\",\n          \"usage\": {\n            \"init\": 2555904,\n            \"committed\": 2949120,\n            \"max\": 7598080,\n            \"used\": 2866048\n          },\n          \"peak-usage\": {\n            \"init\": 2555904,\n            \"committed\": 2949120,\n            \"max\": 7598080,\n            \"used\": 2885248\n          },\n         ...\n      ]          \n    }\n  },\n  \"garbage-collectors\": [\n    {\n      \"name\": \"G1 Young Generation\",\n      \"collection-count\": 8,\n      \"collection-time\": 66,\n      \"memory-pool-names\": [\n        \"G1 Eden Space\",\n        \"G1 Survivor Space\",\n        \"G1 Old Gen\"\n      ]\n    },\n    ...\n  ],\n  \"runtime\": {\n    \"vm-name\": \"OpenJDK 64-Bit Server VM\",\n    \"vm-vendor\": \"AdoptOpenJDK\",\n    \"vm-version\": \"11.0.9+11\",\n    \"uptime\": 7448,\n    \"start-time\": 1611145735991,\n    \"input-arguments\": [\n      \"-Dfile.encoding=UTF-8\",\n      \"-Xms1024m\",\n      \"-Xmx1024m\",\n      \"-Xss256k\",\n      \"-XX:ReservedCodeCacheSize=128m\"\n    ],\n    \"classpath\": [\n      \"/opt/sbt/bin/sbt-launch.jar\"\n    ]\n  },\n  \"thread\": {\n    \"current-thread-count\": 46,\n    \"daemon-thread-count\": 24,\n    \"peak-thread-count\": 46,\n    \"thread-cpu-time-enabled\": true,\n    \"thread-contention-monitoring-enabled\": true,\n    \"threads\": [\n      {\n        \"name\": \"main\",\n        \"id\": 1,\n        \"blocked-count\": 222,\n        \"blocked-time\": 0,\n        \"waited-count\": 564,\n        \"waited-time\": 0,\n        \"state\": \"WAITING\",\n        \"stack-trace\": [\n          \"jdk.internal.misc.Unsafe.park(Native method)\",\n          \"java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)\",\n          \"java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2081)\"\n        ]\n      },\n      {\n        \"name\": \"Reference Handler\",\n        \"id\": 2,\n        \"blocked-count\": 8,\n        \"blocked-time\": 0,\n        \"waited-count\": 0,\n        \"waited-time\": 0,\n        \"state\": \"RUNNABLE\",\n        \"stack-trace\": [\n          \"java.lang.ref.Reference.waitForReferencePendingList(Native method)\",\n          \"java.lang.ref.Reference.processPendingReferences(Reference.java:241)\",\n          \"java.lang.ref.Reference$ReferenceHandler.run(Reference.java:213)\"\n        ]\n      },\n     ...\n    ]\n  },\n  \"class-loading\": {\n    \"loaded-classes\": 16123,\n    \"total-loaded-classes\": 16128,\n    \"unloaded-classes\": 5\n  }\n}\n```\n\n## withClassLoadingInfo\n\nProvides information on the total of all class loaders in the JVM.\n\n```\nJMXJsonBuilder.apply().withClassLoadingInfo();\n```\n\n## withGarbageCollectionInfo\n\nProvides information on the garbage collectors in the JVM.\n\n```\nJMXJsonBuilder.apply().withGarbageCollectionInfo();\n```\n\n## withMemoryInfo\n\nProvides insights into the allocated memory of the JVM, heap as well as off/non-heap (e.g thread stacks).     \nOptionally one can get statistics on all memory pools.\n\n```\nJMXJsonBuilder.apply().withMemoryInfo(); //defaults to withMemoryInfo(false)\nJMXJsonBuilder.apply().withMemoryInfo(true);\n```\n\n## withOperatingSystemInfo\n\nAdds information on the operating system the JVM runs on.\n\n```\nJMXJsonBuilder.apply().withOperatingSystemInfo();\n```\n\n## withRuntimeInfo\n\nProvides runtime information such as:\n\n* when the JVM was started\n* total uptime\n* JVM vendor/version\n* all input arguments\n* classpath\n\n```\nJMXJsonBuilder.apply().withRuntimeInfo();\n```\n\n## withThreadInfo\n\nAs threads may be in abundance this is the most verbose part.   \nApart from providing general counters for threads it also provides insights into every thread in the system.\n\n* name and id\n* state\n* blocked/waited counters\n* blocked/waited time - These may be -1 depending on if the JVM is configured for measuring the information or not\n* stack trace - The stack trace is optional and one can choose how many rows/lines from the stack trace to print for\n  each thread (0 is default)\n\n```\nJMXJsonBuilder.apply().withThreadInfo(); //same as withThreadInfo(3)\nJMXJsonBuilder.apply().withThreadInfo(0); //disables stack trace\n```\n\n**Note** The blocked/waited time measurements may not be enabled on the JVM.  \nTo enable invoke `ManagementFactory.getThreadMXBean().setThreadContentionMonitoringEnabled(true)`.   \nThis may have an impact on the performance so do it with caution.\n\n## Formatting options\n\nThe Json printout can be in compact or pretty-printed format.  \nThere is a few functions basically with two different results, use the one where the name fit your application.  \nAll print related functions invoke the `toString(boolean)` the difference being the value of the argument.\n\n| Function        | Result |\n| ------------- |:-------------:|\n| `compactPrint()`     | compact |\n| `toString()`     | compact |\n| `toString(false)`     | compact |\n| `toString(true)`     | pretty-print |\n| `prettyPrint()`     | pretty-print |\n\n# Dockerized example\n\nFor a full example on the printout from a dockerized Java application refer to the [docker](docker/) submodule.  \nIt contains small application that easily be built into a Docker and executed locally.\n\n# Dependencies\n\nThis library uses [minimal-json](https://github.com/ralfstx/minimal-json) for managing Json format.  \nIt is a small no-dependencies library fit for the purpose.\n\n# Download\n\nThe libraries are plain Java (the Scala part is only unit tests), compiled for compatibility with Java 8+.   \nSimply add the following dependency:\n\nsbt\n\n```\n\"org.dmonix\" % \"jmx-runtime-json\" % [version]\n```\n\nmaven\n\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.dmonix\u003c/groupId\u003e\n  \u003cartifactId\u003ejmx-runtime-json\u003c/artifactId\u003e\n  \u003cversion\u003e[version]\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n# License\n\nThe library is licensed under [Apache 2](LICENSE) \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnerg%2Fjmx-runtime-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpnerg%2Fjmx-runtime-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnerg%2Fjmx-runtime-json/lists"}