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.com
to your jKool/XRay streaming endpoint URL. - Change the
jkool-access-token
placeholder 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.xml
files. The only file you will need to change istnt-data-source.xml
.
-
Download the latest version of the TNT4J-Streams
war
package from GitHub releases. It will be available in theassets
section of the release. -
Deploy the
tnt4j-streams-<VERSION>.war
ortnt4j-streams-servlet-<VERSION>.war
file 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-streams
project, Maven will produce atnt4j-streams-<VERSION>.war
package with all reactor-enabled modules and dependencies built in. - When individually building the
tnt4j-streams-servlet
module, Maven will produce atnt4j-streams-servlet-<VERSION>.war
package 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.xml
within awar
package (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.TNT4J
configuration 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.xml
within war package)
Web-app deployment descriptor (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.xml
files 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.xml
streams.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.
tnt-data-source.xml
)
Stream (The major entities in stream configuration are as follows:
- The
CloudWatchMetricsStream
entity of classcom.jkoolcloud.tnt4j.streams.inputs.HttpServletStream
picks up the HTTP POST transmitted request payload as streamed input data. - The
ResponseTemplate
property defines the stream servlet response template. AWS Kinesis FireHose requires a particular JSON response to ensure successful communication. - The
tnt4j-properties
section defines individual stream TNT4J configuration:- The
event.sink.factory.BroadcastSequence
property 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.ap
defines 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.jkool
defines 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
KinesisFirehoseParser
Reference to bootstrap parser of incoming metrics data package.
parsers.xml
)
Parsers (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 wrappingACTIVITY
entity for AutoPilot sink, containingSNAPSHOT
s representing individual metrics lines (one snapshot per metrics line).MetricLineParserAP
- Builds metrics line parsedSNAPSHOT
entity for AutoPilot sink.MetricEntryParserXRay
- Builds metrics data wrappingACTIVITY
entity for jKool/XRay sink, containingSNAPSHOT
s representing individual metrics line.MetricLineParserXRay
- Builds metrics line parsedSNAPSHOT
entity for jKool/XRay sink.ValueParser
- Metrics linevalue
fields group parser.DimensionsParserAP
- Metrics linedimensions
fields group parser for AutoPilot sink.DimensionsParserXRay
- Metrics linedimensions
fields 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:
Name
has valueAWSCloudWatchMetrics
RoutePath
has valueap
StartTime
/EndTime
have the current stream runtime timestampDataCenter
has valueAmazon_AWS
Metrics lines are placed as child SNAPSHOT
s of that ACTIVITY
entity. The Snapshot contains the following set of fields:
StartTime
/EndTime
value from metrics line fieldtimestamp
Unit
value from metrics line fieldunit
EventName
provides stream name and set of properties key/value pairs used to lay out AP tree nodes (see propertyevent.sink.factory.EventSinkFactory.ap.Formatter.PathLevelAttributes
):MetricStreamName
value from metrics line fieldmetric_stream_name
as metricsdomain
namespace=${Namespace}
value from metrics line fieldnamespace
region=${Region}
value from metrics line fieldregion
cluster=${ClusterName}
value fromdimensions
group fieldCluster Name
broker=${BrokerId}
value fromdimensions
group fieldBroker ID
. If value is numeric then number is prefixed byb-
topic=${Topic}
value fromdimensions
group fieldTopic
streamName=${DeliveryStreamName}
value fromdimensions
group fieldDeliveryStreamName
cGroup=${ConsumerGroup}
value fromdimensions
group fieldConsumer Group
cAuth=${ClientAuth}
value fromdimensions
group fieldClient Authentication
metric=${MetricName}
value from metrics line fieldmetric_name
- The Metrics line field group
value
produces the following fields:Max
value from group fieldmax
Min
value from group fieldmin
Sum
value from group fieldsum
Count
value from group fieldcount
P99
value from group fieldp99
P99_9
value from group fieldp99.9
Median
value from group fieldTM(25%:75%)
jKool/XRay activities
-
For CloudWatch-provided metrics package, TNT4J-Streams produces an
ACTIVITY
entity containing the following fields:Name
has valueAWSCloudWatchMetrics
RoutePath
has valuexray
StartTime
/EndTime
use current stream runtime timestampDataCenter
has valueAmazon_AWS
-
Metrics lines are placed as child
SNAPSHOT
s of thatACTIVITY
entity. The Snapshot contains the following set of fields:MetricStreamName
value from metrics line fieldmetric_stream_name
UserName
value from metrics line fieldaccount_id
Region
value from metrics line fieldregion
Namespace
value from metrics line fieldnamespace
MetricName
value from metrics line fieldmetric_name
StartTime
/EndTime
value from metrics line fieldtimestamp
Unit
value from metrics line fieldunit
Category
has valueAWSCloudWatchMetric
- The Metrics line field group
dimensions
produces the following fields:BrokerId
value from group fieldBroker ID
. If the value is numeric, then the number is prefixed byb-
.InstanceId
value from group fieldInstanceId
ClusterName
value from group fieldCluster Name
Topic
value from group fieldTopic
ConsumerGroup
value from group fieldConsumer Group
ClientAuth
value from group fieldClient Authentication
DeliveryStreamName
value from group fieldDeliveryStreamName
- The Metrics line field group
value
produces the following fields:Max
value from group fieldmax
Min
value from group fieldmin
Sum
value from group fieldsum
Count
value from group fieldcount
P99
value from group fieldp99
P99_9
value from group fieldp99.9
Median
value from group fieldTM(25%:75%)
Name
combines theNamespace
,Region
,ClusterName
,BrokerId
, andMetricName
fields, delimited by|
.Guid
combines theStartTime
field (formatted asyyyy-MM-dd_HH:mm:ss
in theUTC
timezone) with theName
field 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.