This article explains how Stream-JMX sends collected JMX metrics to different destinations such as meshIQ, sockets, files, or multiple endpoints. It shows configuration examples for each sink and how to format the output.
Stream-JMX streams all collected metrics based on a scheduled interval via the TNT4J event streaming framework. All streams are written into TNT4J event sinks defined in tnt4j.properties file, which is specified by the -Dtnt4j.config=tnt4j.properties property.
To meshIQ (requires JESL libraries)
Below is an example of TNT4J stream configuration writing collected JMX samples to the jKoolCloud server, formatted as JSON:
;Stanza used for Stream-JMX sources
{
source: com.jkoolcloud.tnt4j.stream.jmx
source.factory: com.jkoolcloud.tnt4j.stream.jmx.source.JMXSourceFactoryImpl
source.factory.GENERIC: Streams
source.factory.GEOADDR: New York
source.factory.DATACENTER: YourDC
source.factory.SERVICE: $sjmx.serviceId
source.factory.RootFQN: SERVICE=?#SERVER=?#DATACENTER=?#GEOADDR=?#GENERIC=?
source.factory.RootSSN: tnt4j-stream-jmx
source.factory.RetryIntervalSec: 1
source.factory.RetryMaxAttempts: 10
source.factory.ExpIntervalAfter: 0
source.factory.RetryMaxIntervalSec: 120
tracker.factory: com.jkoolcloud.tnt4j.tracker.DefaultTrackerFactory
dump.sink.factory: com.jkoolcloud.tnt4j.dump.DefaultDumpSinkFactory
event.sink.factory: com.jkoolcloud.tnt4j.sink.impl.BroadcastingEventSinkFactory
event.sink.factory.BroadcastSequence: track
; Event Sink configuration for streaming to jKoolCloud
; NOTE: Requires JESL libraries (http://nastel.github.io/JESL/)
event.sink.factory.EventSinkFactory.track: com.jkoolcloud.jesl.tnt4j.sink.JKCloudEventSinkFactory
event.sink.factory.EventSinkFactory.track.LogSink: file:./logs/stream-jmx_activities.json
event.sink.factory.EventSinkFactory.track.Url: https://stream.meshiq.com
event.sink.factory.EventSinkFactory.track.Token: YOUR-ACCESS-TOKEN
event.formatter: com.jkoolcloud.tnt4j.format.JSONFormatter
; Configure default sink filter based on level and time (elapsed/wait)
event.sink.factory.Filter: com.jkoolcloud.tnt4j.filters.EventLevelTimeFilter
event.sink.factory.Filter.Level: TRACE
tracking.selector: com.jkoolcloud.tnt4j.selector.DefaultTrackingSelector
tracking.selector.Repository: com.jkoolcloud.tnt4j.repository.FileTokenRepository
}To Socket
Below is an example of a TNT4J stream configuration writing collected JMX samples to a socket event sink com.jkoolcloud.tnt4j.sink.impl.SocketEventSinkFactory, formatted by com.jkoolcloud.tnt4j.stream.jmx.format.FactNameValueFormatter:
;Stanza used for Stream-JMX sources
{
source: com.jkoolcloud.tnt4j.stream.jmx
source.factory: com.jkoolcloud.tnt4j.stream.jmx.source.JMXSourceFactoryImpl
source.factory.GENERIC: Streams
source.factory.GEOADDR: New York
source.factory.DATACENTER: YourDC
source.factory.SERVICE: $sjmx.serviceId
source.factory.RootFQN: SERVICE=?#SERVER=?#DATACENTER=?#GEOADDR=?#GENERIC=?
source.factory.RootSSN: tnt4j-stream-jmx
source.factory.RetryIntervalSec: 1
source.factory.RetryMaxAttempts: 10
source.factory.ExpIntervalAfter: 0
source.factory.RetryMaxIntervalSec: 120
tracker.factory: com.jkoolcloud.tnt4j.tracker.DefaultTrackerFactory
dump.sink.factory: com.jkoolcloud.tnt4j.dump.DefaultDumpSinkFactory
event.sink.factory: com.jkoolcloud.tnt4j.sink.impl.BroadcastingEventSinkFactory
event.sink.factory.BroadcastSequence: ap
event.sink.factory.EventSinkFactory.ap: com.jkoolcloud.tnt4j.sink.impl.SocketEventSinkFactory
; If socket sent data should not be logged anywhere else
event.sink.factory.EventSinkFactory.ap.LogSink: null
; If socket-sent data should be logged to a file
#event.sink.factory.EventSinkFactory.ap.LogSink: file:./logs/tnt4j-stream-jmx_samples_socket.log
event.sink.factory.EventSinkFactory.ap.Endpoint: localhost:6060
; NOTE: DO NOT define "event.formatter" property value if there is no need for custom formatter.
; SamplerFactory will take care to set appropriate one for a context.
#event.formatter: com.jkoolcloud.tnt4j.format.JSONFormatter
; If JMX attributes should be formatted as JMX object names
event.formatter: com.jkoolcloud.tnt4j.stream.jmx.format.FactNameValueFormatter
; If JMX attributes should be formatted as JMX object paths
#event.formatter: com.jkoolcloud.tnt4j.stream.jmx.format.FactPathValueFormatter
; If JMX attributes should be formatted as JMX object paths for IBM WAS and Liberty
#event.formatter: com.jkoolcloud.tnt4j.stream.jmx.format.SLIFactPathValueFormatter
; Whether to add Activity/Event context data snapshot 'Self'
#event.formatter.AddSelfSnapshot: false
; Whether to add AutoPilot fact value type prefixes for fact names
#event.formatter.AddAPValueTypePrefix: true
; Mapping of attribute key string symbol replacements
#event.formatter.KeyReplacements: " "->"_" "\""->"'" "/"->"%" "="->"\\" ","->"!" "\\\\"->"\\"
; Mapping of attribute value string symbol replacements
#event.formatter.ValueReplacements: "\r"->"\\r" "\n"->"\\n" ";"->"|" ","->"|" "["->"{(" "]"->")}" "\""->"'"
; Definitions ObjectName attributes sets used when building path: ';' is level set delimiter and ',' is set attribute names delimiter
#event.formatter.PathLevelAttributes: domain; type; name, brokerName; service, connector, destinationType; instanceName, connectorName, destinationName
; Defines JMX sample attribute key suffix to be added when duplicate keys for "branch" and "leaf" nodes are found.
; NOTE: AP does not allow to have same name for "branch" and "leaf" nodes at same tree level
#event.formatter.DuplicateKeySuffix: ___
; Configure default sink filter based on level and time (elapsed/wait)
event.sink.factory.Filter: com.jkoolcloud.tnt4j.filters.EventLevelTimeFilter
event.sink.factory.Filter.Level: TRACE
tracking.selector: com.jkoolcloud.tnt4j.selector.DefaultTrackingSelector
tracking.selector.Repository: com.jkoolcloud.tnt4j.repository.FileTokenRepository
}To File
Below is an example of TNT4J stream configuration writing collected JMX samples to a log file MyStream.log, formatted by com.jkoolcloud.tnt4j.stream.jmx.format.FactNameValueFormatter:
;Stanza used for Stream-JMX sources
{
source: com.jkoolcloud.tnt4j.stream.jmx
source.factory: com.jkoolcloud.tnt4j.stream.jmx.source.JMXSourceFactoryImpl
source.factory.GENERIC: Streams
source.factory.GEOADDR: New York
source.factory.DATACENTER: YourDC
source.factory.SERVICE: $sjmx.serviceId
source.factory.RootFQN: SERVICE=?#SERVER=?#DATACENTER=?#GEOADDR=?#GENERIC=?
source.factory.RootSSN: tnt4j-stream-jmx
source.factory.RetryIntervalSec: 1
source.factory.RetryMaxAttempts: 10
source.factory.ExpIntervalAfter: 0
source.factory.RetryMaxIntervalSec: 120
tracker.factory: com.jkoolcloud.tnt4j.tracker.DefaultTrackerFactory
dump.sink.factory: com.jkoolcloud.tnt4j.dump.DefaultDumpSinkFactory
event.sink.factory: com.jkoolcloud.tnt4j.sink.impl.BroadcastingEventSinkFactory
event.sink.factory.BroadcastSequence: file
event.sink.factory.EventSinkFactory.file: com.jkoolcloud.tnt4j.sink.impl.FileEventSinkFactory
event.sink.factory.EventSinkFactory.file.FileName: ./MyStream.log
; NOTE: DO NOT define "event.formatter" property value if there is no need for custom formatter.
; SamplerFactory will take care to set appropriate one for a context.
#event.formatter: com.jkoolcloud.tnt4j.format.JSONFormatter
; If JMX attributes should be formatted as JMX object names
event.formatter: com.jkoolcloud.tnt4j.stream.jmx.format.FactNameValueFormatter
; If JMX attributes should be formatted as JMX object paths
#event.formatter: com.jkoolcloud.tnt4j.stream.jmx.format.FactPathValueFormatter
; If JMX attributes should be formatted as JMX object paths for IBM WAS and Liberty
#event.formatter: com.jkoolcloud.tnt4j.stream.jmx.format.SLIFactPathValueFormatter
; Whether to add Activity/Event context data snapshot 'Self'
#event.formatter.AddSelfSnapshot: false
; Whether to add AutoPilot fact value type prefixes for fact names
#event.formatter.AddAPValueTypePrefix: true
; Mapping of attribute key string symbol replacements
#event.formatter.KeyReplacements: " "->"_" "\""->"'" "/"->"%" "="->"\\" ","->"!" "\\\\"->"\\"
; Mapping of attribute value string symbol replacements
#event.formatter.ValueReplacements: "\r"->"\\r" "\n"->"\\n" ";"->"|" ","->"|" "["->"{(" "]"->")}" "\""->"'"
; Definitions ObjectName attributes sets used when building path: ';' is level set delimiter and ',' is set attribute names delimiter
#event.formatter.PathLevelAttributes: domain; type; name, brokerName; service, connector, destinationType; instanceName, connectorName, destinationName
; Defines JMX sample attribute key suffix to be added when duplicate keys for "branch" and "leaf" nodes are found.
; NOTE: AP does not allow to have same name for "branch" and "leaf" nodes at same tree level
#event.formatter.DuplicateKeySuffix: ___
; Configure default sink filter based on level and time (elapsed/wait)
event.sink.factory.Filter: com.jkoolcloud.tnt4j.filters.EventLevelTimeFilter
event.sink.factory.Filter.Level: TRACE
tracking.selector: com.jkoolcloud.tnt4j.selector.DefaultTrackingSelector
tracking.selector.Repository: com.jkoolcloud.tnt4j.repository.FileTokenRepository
}And Even More
You can also write your own custom event sinks (HTTPS, HTTP, etc.) and your own stream formatters without having to change Stream-JMX code or your application. TNT4J comes with a set of built-in event sink implementations such as:
-
com.jkoolcloud.tnt4j.logger.Log4JEventSinkFactory-- log4j -
com.jkoolcloud.tnt4j.sink.impl.BufferedEventSinkFactory-- buffered sink -
com.jkoolcloud.tnt4j.sink.impl.FileEventSinkFactory- standard log file -
com.jkoolcloud.tnt4j.sink.impl.SocketEventSinkFactory-- socket (tcp/ip) -
com.jkoolcloud.tnt4j.sink.impl.NullEventSinkFactory-- null (empty)
Streaming to Multiple Endpoints
Consider one of the most common cases, where Stream-JMX-produced samples should appear on both AutoPilot and jKool at the same time. To achieve that, BroadcastingEventSinkFactory shall be used and have two sinks bound: for AutoPilot endpoint - ap (SocketEventSinkFactory) and for jKool endpoint - jkool (JKCloudEventSinkFactory). This way, the same JMX sample will be sent to AutoPilot over a configured socket with data formatted by FactNameValueFormatter, and to jKool repository defined by an access token, with sample data formatted by JSONFormatter.
;Stanza used for Stream-JMX sources
{
source: com.jkoolcloud.tnt4j.stream.jmx
source.factory: com.jkoolcloud.tnt4j.stream.jmx.source.JMXSourceFactoryImpl
source.factory.GENERIC: Streams
source.factory.GEOADDR: New York
source.factory.DATACENTER: YourDC
source.factory.SERVICE: $sjmx.serviceId
source.factory.RootFQN: SERVICE=?#SERVER=?#DATACENTER=?#GEOADDR=?#GENERIC=?
source.factory.RootSSN: tnt4j-stream-jmx
source.factory.RetryIntervalSec: 1
source.factory.RetryMaxAttempts: 10
source.factory.ExpIntervalAfter: 0
source.factory.RetryMaxIntervalSec: 120
tracker.factory: com.jkoolcloud.tnt4j.tracker.DefaultTrackerFactory
dump.sink.factory: com.jkoolcloud.tnt4j.dump.DefaultDumpSinkFactory
event.sink.factory: com.jkoolcloud.tnt4j.sink.impl.BroadcastingEventSinkFactory
event.sink.factory.BroadcastSequence: ap,jkool
event.sink.factory.EventSinkFactory.ap: com.jkoolcloud.tnt4j.sink.impl.SocketEventSinkFactory
; If socket-sent data should not be logged anywhere else
event.sink.factory.EventSinkFactory.ap.LogSink: null
; If socket sent data should be logged to file
#event.sink.factory.EventSinkFactory.ap.LogSink: file:./logs/tnt4j-stream-jmx_samples_socket.log
event.sink.factory.EventSinkFactory.ap.Endpoint: localhost:6060
event.sink.factory.EventSinkFactory.ap.Formatter: com.jkoolcloud.tnt4j.stream.jmx.format.FactNameValueFormatter
#event.sink.factory.EventSinkFactory.ap.Formatter.AddSelfSnapshot: false
#event.sink.factory.EventSinkFactory.ap.Formatter.AddAPValueTypePrefix: true
event.sink.factory.EventSinkFactory.ap.Formatter.KeyReplacements: " "->"_" "\""->"'" "/"->"%" "="->"\\" ","->"!" "\\\\"->"\\"
event.sink.factory.EventSinkFactory.ap.Formatter.ValueReplacements: "\r"->"\\r" "\n"->"\\n" ";"->"&" ","->"&" "["->"{(" "]"->")}" "\""->"'"
event.sink.factory.EventSinkFactory.jkool: com.jkoolcloud.jesl.tnt4j.sink.JKCloudEventSinkFactory
event.sink.factory.EventSinkFactory.jkool.LogSink: file:./logs/stream-jmx_activities.json
event.sink.factory.EventSinkFactory.jkool.Url: https://stream.meshiq.com
event.sink.factory.EventSinkFactory.jkool.Token: YOUR-ACCESS-TOKEN
event.sink.factory.EventSinkFactory.jkool.Formatter: com.jkoolcloud.tnt4j.format.JSONFormatter
; Configure default sink filter based on level and time (elapsed/wait)
event.sink.factory.Filter: com.jkoolcloud.tnt4j.filters.EventLevelTimeFilter
event.sink.factory.Filter.Level: TRACE
tracking.selector: com.jkoolcloud.tnt4j.selector.DefaultTrackingSelector
tracking.selector.Repository: com.jkoolcloud.tnt4j.repository.FileTokenRepository
}