This article applies to XRay versions 1.5 and 1.6 and to the meshIQ Platform versions 11 and later.
Jump ahead |
Quick setup steps
-
See the Cloudwatch Metrics document for information about how to configure AWS to feed metrics data.
-
You must have HTTPS enabled on your web server. AWS allows sending metrics only to HTTPS-enabled web endpoints with a valid certificate (a valid certificate is not expired and is not self-signed).
-
Copy configuration files to your web server configuration dir (for example,
<TOMCAT_DIR>/conf). By default, TNT4J-Streams will try to use the internal configuration dir path/Catalina/localhost/tnt4j-streams:- log4j2.xml - Log4j V2 configuration used by TNT4J-Streams.
- tnt4j.properties - Base TNT4J configuration.
- tnt4j-common.properties - Common TNT4J configuration.
- tnt4j-streams.properties - TNT4J-Streams dedicated TNT4J configuration.
- tnt-data-source.xml - TNT4J-Streams data source (stream) configuration. This file has a TNT4J properties configuration section that is dedicated to streams:
- The default configuration broadcasts CloudWatch metrics to AutoPilot (sink id
ap) and jKool/XRay (sink idjkool) simultaneously. If you want to use just one of these sinks, then change the following<tnt4j-properties>configuration line:<tnt4j-properties> <...> <!-- FROM --> <propertyname="event.sink.factory.BroadcastSequence"value="ap,jkool"/> <!-- TO for streaming just to AutoPilot --> <propertyname="event.sink.factory.BroadcastSequence"value="ap"/> <!-- TO for streaming just to jKool/XRay --> <propertyname="event.sink.factory.BroadcastSequence"value="jkool"/> <...> </tnt4j-properties>
- Change the AutoPilot sink host value (property
event.sink.factory.EventSinkFactory.ap.Host) to match your AutoPilot instance. The default value islocalhost. - Change the AutoPilot sink port value (property
event.sink.factory.EventSinkFactory.ap.Port) to match your AutoPilot instance. The default value is6060. - Change
https://data.jkoolcloud.comto your jKool/XRay streaming endpoint URL. - Change the
jkool-access-tokenplaceholder to your jKool/XRay streaming token, if you want to stream into that repo.
- The default configuration broadcasts CloudWatch metrics to AutoPilot (sink id
- Parsers.xml - TNT4J-Streams parsers configuration.
In most cases, you do not need to change the
log4j2.xml,tnt4j*.properties, andparsers.xmlfiles. The only file you will need to change istnt-data-source.xml.
-
Download the latest version of the TNT4J-Streams
warpackage from GitHub releases. It will be available in theassetssection of the release. -
Deploy the
tnt4j-streams-<VERSION>.warortnt4j-streams-servlet-<VERSION>.warfile to your web server web-apps dir, for example,<TOMCAT_DIR>/webapps.
Remove the version token from the war package file name to preserve the web-app context on every deployment.
-
Start the web server, if it is not already running.
Details: Building the TNT4J-Streams Servlet and Configuring the AWS CloudWatch Metrics Streaming Endpoint
Build TNT4J-Streams servlet
There are two ways to build the TNT4J-Streams war package:
- When building the whole
tnt4j-streamsproject, Maven will produce atnt4j-streams-<VERSION>.warpackage with all reactor-enabled modules and dependencies built in. - When individually building the
tnt4j-streams-servletmodule, Maven will produce atnt4j-streams-servlet-<VERSION>.warpackage with all module dependencies built in.
Whichever way you choose to build it, the war package contains classes and resources (like web.xml) provided by the tnt4j-streams-servlet module.
Configuration
AWS CloudWatch metrics streaming HTTP endpoint (servlet) configuration is a combination of the following:
- Web-app deployment descriptor
web.xmlwithin awarpackage (by default) or within your web server configuration dir (for example,<TOMCAT_DIR>/conf/Catalina/localhost/tnt4j-streams). log4j2.xml, which defines the Log4j V2 configuration used by the TNT4J-Streams API.TNT4Jconfiguration properties files split into dedicated scopes (base, common, streams).tnt-data-source.xml, which defines the stream configuration.parsers.xml, which defines parsers used by TNT4-Streams to map metrics fields to the TNT4J activities data model.
In most cases, you do not need to change the web.xml, log4j2.xml, tnt4j*.properties, and parsers.xml files.
Web-app deployment descriptor (web.xml within war package)
The web-app deployment descriptor defines servlet initialization parameter sets and servlet mapping:
- init params
streams.configs.dir- TNT4J-Streams configuration files location path wheretnt4j.properties,log4j2.xml, andtnt-data-source.xmlfiles can be found. The default value is${catalina.base}/conf/Catalina/localhost/tnt4j-streams. This setting is optional if you are defining the full path to the individual configuration files with init paramstnt4j.config,log4j2.config, andstreams.config.tnt4j.config- TNT4J configuration file path. The default value istnt4j.properties.log4j2.config- Log4j V2 configuration file path. The default value islog4j2.xmlstreams.config- TNT4J-Streams datasource/parsers configuration file path. The default value istnt-data-source.xml.
- servlet mapping
- The default URL pattern is
/.
- The default URL pattern is
Log4j2
In general, Log4j2 configuration is the same as for common TNT4-Streams logging, except that this config uses the ${sys:catalina.base}/logs dir to locate produced log files.
Also note that loggers are named to match the broadcasting sink ids defined in the stream configuration: ap and jkool instead of prod and qa.
TNT4J
In general, TNT4J configuration is the same as for common TNT4-Streams configuration, except that the streams scope (tnt4j-streams.properties file) defines broadcasting sink ids ap and jkool to match the sink target endpoint.
Individual TNT4J streams scope configuration is handled in the <tnt4j-properties> section of the tnt-data-source.xml file.
Stream (tnt-data-source.xml)
The major entities in stream configuration are as follows:
- The
CloudWatchMetricsStreamentity of classcom.jkoolcloud.tnt4j.streams.inputs.HttpServletStreampicks up the HTTP POST transmitted request payload as streamed input data. - The
ResponseTemplateproperty defines the stream servlet response template. AWS Kinesis FireHose requires a particular JSON response to ensure successful communication. - The
tnt4j-propertiessection defines individual stream TNT4J configuration:- The
event.sink.factory.BroadcastSequenceproperty defines the produced activities broadcasting sinks. The default configuration for this property includes sinks for both AutoPilot (sink idap) and jKool/XRay (sink idjkool). Therefore the default set of sinks to broadcast stream produced activities isap,jkool. If you want to use just one of these sinks, then change the following<tnt4j-properties>configuration:<tnt4j-properties> <...> <!-- FROM --> <propertyname="event.sink.factory.BroadcastSequence"value="ap,jkool"/> <!-- TO for streaming just to AutoPilot --> <propertyname="event.sink.factory.BroadcastSequence"value="ap"/> <!-- TO for streaming just to jKool/XRay --> <propertyname="event.sink.factory.BroadcastSequence"value="jkool"/> <...> </tnt4j-properties>
- The properties group starting with
event.sink.factory.EventSinkFactory.apdefines the AutoPilot dedicated sink configuration:- Change the AutoPilot sink (id
ap) host value (propertyevent.sink.factory.EventSinkFactory.ap.Host) to match your AutoPilot instance. The default value islocalhost. - Change the AutoPilot sink (id
ap) port value (propertyevent.sink.factory.EventSinkFactory.ap.Port) to match your AutoPilot instance. The default value is6060.
- Change the AutoPilot sink (id
- The properties group starting with
event.sink.factory.EventSinkFactory.jkooldefines jKool/XRay dedicated sink configuration:- Change the jKool/XRay sink (id
jkool) URL value (propertyevent.sink.factory.EventSinkFactory.jkool.Url) to match your jKool/XRay instance. The default value ishttps://data.jkoolcloud.com. - Change the jKool/XRay sink (id
jkool) token placeholder value (propertyevent.sink.factory.EventSinkFactory.jkool.Token) to your jKool/XRay streaming token, if you want to stream into that repo. The placeholder value isjkool-access-token.
- Change the jKool/XRay sink (id
- The
KinesisFirehoseParserReference to bootstrap parser of incoming metrics data package.
Parsers (parsers.xml)
The parsers unwrap the metrics data package sent by AWS Kinesis FireHose into metrics JSON lines. This allows for metrics to be filtered (see the Metrics filtering section) and for the field values from the metrics lines to be parsed into TNT4J activities and snapshots.
This file defines these parsers:
KinesisFirehoseParser- Bootstrap parser that recognizes the format of the received metrics data package.KinesisFirehoseParserStr- Parses Kinesis Firehose JSON metrics batch package where metrics data package is a Base64 encoded string.MetricsParserStr- Filters metric lines before passing them for further parsing.MetricEntryParserAP- Builds metrics data wrappingACTIVITYentity for AutoPilot sink, containingSNAPSHOTs representing individual metrics lines (one snapshot per metrics line).MetricLineParserAP- Builds metrics line parsedSNAPSHOTentity for AutoPilot sink.MetricEntryParserXRay- Builds metrics data wrappingACTIVITYentity for jKool/XRay sink, containingSNAPSHOTs representing individual metrics line.MetricLineParserXRay- Builds metrics line parsedSNAPSHOTentity for jKool/XRay sink.ValueParser- Metrics linevaluefields group parser.DimensionsParserAP- Metrics linedimensionsfields group parser for AutoPilot sink.DimensionsParserXRay- Metrics linedimensionsfields group parser for jKool/XRay sink.
Metrics filtering
You may want to pick just a set of provided metrics to be streamed. In this case, you can filter metrics. Filtering logic can be done in the MetricsParserStr parser field (embedded activity) MetricsData transformation. The default filter removes all available empty lines:
boolean pass =StringUtils.isNotEmpty(line);
Additionally, you can define regular expressions (RegEx) to match metrics lines you want to stream. For example. to pick only kafka_server metrics, you would specify the following:
pass &=Matchers.evaluate("regex:kafka_server_.+", line);
Or you can pick some metrics by name for a particular AWS service. For example, if the service is AWS/Kafka, then you can pick a set of metric names like this:
String[] kafkaIncludeMetrics =newString[] {
"ActiveControllerCount",
"CpuIdle",
"CpuSystem",
"CpuUser",
"GlobalPartitionCount",
"GlobalTopicCount",
"KafkaAppLogsDiskUsed",
"KafkaDataLogsDiskUsed",
"MemoryBuffered",
"MemoryCached",
"MemoryFree",
"MemoryUsed",
"NetworkRxDropped",
"NetworkRxErrors",
"NetworkRxPackets",
"NetworkTxDropped",
"NetworkTxErrors",
"NetworkTxPackets",
"OfflinePartitionsCount",
"RootDiskUsed",
"SwapFree",
"SwapUsed",
"ZooKeeperRequestLatencyMsMean",
"ZooKeeperRequestLatencyMsMean"
};
if (StringUtils.contains(line, "AWS/Kafka")) {
pass &=StringUtils.containsAny(line, kafkaIncludeMetrics);
}
Streamed metrics data
AutoPilot facts
For CloudWatch provided metrics package, TNT4J-Streams produces an ACTIVITY entity containing the following fields:
Namehas valueAWSCloudWatchMetricsRoutePathhas valueapStartTime/EndTimehave the current stream runtime timestampDataCenterhas valueAmazon_AWS
Metrics lines are placed as child SNAPSHOTs of that ACTIVITY entity. The Snapshot contains the following set of fields:
StartTime/EndTimevalue from metrics line fieldtimestampUnitvalue from metrics line fieldunitEventNameprovides stream name and set of properties key/value pairs used to lay out AP tree nodes (see propertyevent.sink.factory.EventSinkFactory.ap.Formatter.PathLevelAttributes):MetricStreamNamevalue from metrics line fieldmetric_stream_nameas metricsdomainnamespace=${Namespace}value from metrics line fieldnamespaceregion=${Region}value from metrics line fieldregioncluster=${ClusterName}value fromdimensionsgroup fieldCluster Namebroker=${BrokerId}value fromdimensionsgroup fieldBroker ID. If value is numeric then number is prefixed byb-topic=${Topic}value fromdimensionsgroup fieldTopicstreamName=${DeliveryStreamName}value fromdimensionsgroup fieldDeliveryStreamNamecGroup=${ConsumerGroup}value fromdimensionsgroup fieldConsumer GroupcAuth=${ClientAuth}value fromdimensionsgroup fieldClient Authenticationmetric=${MetricName}value from metrics line fieldmetric_name
- The Metrics line field group
valueproduces the following fields:Maxvalue from group fieldmaxMinvalue from group fieldminSumvalue from group fieldsumCountvalue from group fieldcountP99value from group fieldp99P99_9value from group fieldp99.9Medianvalue from group fieldTM(25%:75%)
jKool/XRay activities
-
For CloudWatch-provided metrics package, TNT4J-Streams produces an
ACTIVITYentity containing the following fields:Namehas valueAWSCloudWatchMetricsRoutePathhas valuexrayStartTime/EndTimeuse current stream runtime timestampDataCenterhas valueAmazon_AWS
-
Metrics lines are placed as child
SNAPSHOTs of thatACTIVITYentity. The Snapshot contains the following set of fields:MetricStreamNamevalue from metrics line fieldmetric_stream_nameUserNamevalue from metrics line fieldaccount_idRegionvalue from metrics line fieldregionNamespacevalue from metrics line fieldnamespaceMetricNamevalue from metrics line fieldmetric_nameStartTime/EndTimevalue from metrics line fieldtimestampUnitvalue from metrics line fieldunitCategoryhas valueAWSCloudWatchMetric- The Metrics line field group
dimensionsproduces the following fields:BrokerIdvalue from group fieldBroker ID. If the value is numeric, then the number is prefixed byb-.InstanceIdvalue from group fieldInstanceIdClusterNamevalue from group fieldCluster NameTopicvalue from group fieldTopicConsumerGroupvalue from group fieldConsumer GroupClientAuthvalue from group fieldClient AuthenticationDeliveryStreamNamevalue from group fieldDeliveryStreamName
- The Metrics line field group
valueproduces the following fields:Maxvalue from group fieldmaxMinvalue from group fieldminSumvalue from group fieldsumCountvalue from group fieldcountP99value from group fieldp99P99_9value from group fieldp99.9Medianvalue from group fieldTM(25%:75%)
Namecombines theNamespace,Region,ClusterName,BrokerId, andMetricNamefields, delimited by|.Guidcombines theStartTimefield (formatted asyyyy-MM-dd_HH:mm:ssin theUTCtimezone) with theNamefield values delimited by|- The rest of the metrics line fields are mapped into snapshot properties using their original names
1:1. Usually these fields are either new or very rare.