Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/_docs/monitoring-metrics/new-metrics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,28 @@ Register name: `failure.ignored`
The `ignite-cdc.sh` application runs in a separate JVM and exports its own registers, `cdc` and `cdc.consumer`, through the exporters configured in `CdcConfiguration`.
See link:persistence/change-data-capture#metrics[Change Data Capture] for the list of metrics.

== Logging

Counters of log messages passed through the node's logger proxies, grouped by logging level.
Counters are shared across all logger categories of the node and start accumulating when the node's logger proxy is created, before the metrics are registered.

Register name: `log.count`

The CDC application also registers these counters in its own metric manager.
Connect to the Ignite node and CDC application separately to read their respective log counters.

[cols="2,1,3",opts="header"]
|===
|Name | Type | Description
|trace | long | Number of TRACE messages counted while the TRACE level is enabled.
|debug | long | Number of DEBUG messages counted while the DEBUG level is enabled.
|info | long | Number of INFO messages counted while the INFO level is enabled.
|warning | long | Number of WARN messages passed to the logger.
|error | long | Number of ERROR messages passed to the logger.
|===

These counters do not guarantee that messages were written to a file or another destination: the logging backend may apply additional filters.

== Custom Metrics

Registers created by the application through `Ignite.metrics()`. Their names start with `custom.`, see link:monitoring-metrics/custom-metrics[Custom Metrics].
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.io.ObjectStreamException;
import java.util.Collections;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.internal.processors.metric.GridMetricManager;
import org.apache.ignite.internal.processors.metric.MetricRegistryImpl;
import org.apache.ignite.internal.processors.metric.impl.LongAdderMetric;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand All @@ -34,6 +37,7 @@

import static org.apache.ignite.IgniteSystemProperties.IGNITE_LOG_GRID_NAME;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_LOG_INSTANCE_NAME;
import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;

/**
*
Expand All @@ -42,6 +46,9 @@ public class GridLoggerProxy implements IgniteLogger, LifecycleAware, Externaliz
/** */
private static final long serialVersionUID = 0L;

/** Log messages count metrics registry name. */
static final String LOG_COUNT_METRICS = metricName("log", "count");

/** */
private static ThreadLocal<IgniteBiTuple<String, Object>> stash = new ThreadLocal<IgniteBiTuple<String, Object>>() {
@Override protected IgniteBiTuple<String, Object> initialValue() {
Expand All @@ -62,6 +69,10 @@ public class GridLoggerProxy implements IgniteLogger, LifecycleAware, Externaliz
@GridToStringExclude
private Object ctgr;

/** Shared log message metrics. */
@GridToStringExclude
private final LogMetrics metrics;

/** Whether or not to log Ignite instance name. */
private static final boolean logIgniteInstanceName = System.getProperty(IGNITE_LOG_INSTANCE_NAME) != null ||
System.getProperty(IGNITE_LOG_GRID_NAME) != null;
Expand All @@ -70,7 +81,7 @@ public class GridLoggerProxy implements IgniteLogger, LifecycleAware, Externaliz
* No-arg constructor is required by externalization.
*/
public GridLoggerProxy() {
// No-op.
metrics = new LogMetrics();
}

/**
Expand All @@ -81,12 +92,30 @@ public GridLoggerProxy() {
* @param id8 Node ID.
*/
public GridLoggerProxy(IgniteLogger impl, @Nullable Object ctgr, @Nullable String igniteInstanceName, String id8) {
this(impl, ctgr, igniteInstanceName, id8, new LogMetrics());
}

/**
* @param impl Logger implementation to proxy to.
* @param ctgr Optional logger category.
* @param igniteInstanceName Ignite instance name (can be {@code null} for default grid).
* @param id8 Node ID.
* @param metrics Shared log message metrics.
*/
private GridLoggerProxy(
IgniteLogger impl,
@Nullable Object ctgr,
@Nullable String igniteInstanceName,
String id8,
LogMetrics metrics
) {
assert impl != null;

this.impl = impl;
this.ctgr = ctgr;
this.igniteInstanceName = igniteInstanceName;
this.id8 = id8;
this.metrics = metrics;
}

/** {@inheritDoc} */
Expand All @@ -104,7 +133,7 @@ public GridLoggerProxy(IgniteLogger impl, @Nullable Object ctgr, @Nullable Strin
@Override public IgniteLogger getLogger(Object ctgr) {
assert ctgr != null;

return new GridLoggerProxy(impl.getLogger(ctgr), ctgr, igniteInstanceName, id8);
return new GridLoggerProxy(impl.getLogger(ctgr), ctgr, igniteInstanceName, id8, metrics);
}

/** {@inheritDoc} */
Expand All @@ -114,64 +143,103 @@ public GridLoggerProxy(IgniteLogger impl, @Nullable Object ctgr, @Nullable Strin

/** {@inheritDoc} */
@Override public void trace(String msg) {
if (impl.isTraceEnabled())
metrics.trace.increment();

impl.trace(enrich(msg));
}

/** {@inheritDoc} */
@Override public void trace(@Nullable String marker, String msg) {
if (impl.isTraceEnabled())
metrics.trace.increment();

impl.trace(marker, enrich(msg));
}

/** {@inheritDoc} */
@Override public void debug(String msg) {
if (impl.isDebugEnabled())
metrics.debug.increment();

impl.debug(enrich(msg));
}

/** {@inheritDoc} */
@Override public void debug(@Nullable String marker, String msg) {
if (impl.isDebugEnabled())
metrics.debug.increment();

impl.debug(marker, enrich(msg));
}

/** {@inheritDoc} */
@Override public void info(String msg) {
if (impl.isInfoEnabled())
metrics.info.increment();

impl.info(enrich(msg));
}

/** {@inheritDoc} */
@Override public void info(@Nullable String marker, String msg) {
if (impl.isInfoEnabled())
metrics.info.increment();

impl.info(marker, enrich(msg));
}

/** {@inheritDoc} */
@Override public void warning(String msg) {
metrics.warning.increment();

impl.warning(enrich(msg));
}

/** {@inheritDoc} */
@Override public void warning(String msg, Throwable e) {
metrics.warning.increment();

impl.warning(enrich(msg), e);
}

/** {@inheritDoc} */
@Override public void warning(@Nullable String marker, String msg, @Nullable Throwable e) {
metrics.warning.increment();

impl.warning(marker, enrich(msg), e);
}

/** {@inheritDoc} */
@Override public void error(String msg) {
metrics.error.increment();

impl.error(enrich(msg));
}

/** {@inheritDoc} */
@Override public void error(String msg, Throwable e) {
metrics.error.increment();

impl.error(enrich(msg), e);
}

/** {@inheritDoc} */
@Override public void error(@Nullable String marker, String msg, @Nullable Throwable e) {
metrics.error.increment();

impl.error(marker, enrich(msg), e);
}

/**
* Registers log metrics with the metric manager of this logger's node or application.
*
* @param metricMgr Metric manager.
*/
public void registerMetrics(GridMetricManager metricMgr) {
metrics.register(metricMgr.registry(LOG_COUNT_METRICS));
}

/** {@inheritDoc} */
@Override public boolean isTraceEnabled() {
return impl.isTraceEnabled();
Expand Down Expand Up @@ -210,7 +278,9 @@ public String getLoggerInfo() {
* @return Enriched message or the original one.
*/
private String enrich(@Nullable String m) {
return logIgniteInstanceName && m != null ? "<" + igniteInstanceName + '-' + id8 + "> " + m : m;
return logIgniteInstanceName && m != null
? "<" + igniteInstanceName + (id8 == null ? "" : '-' + id8) + "> " + m
: m;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -255,4 +325,42 @@ protected Object readResolve() throws ObjectStreamException {
@Override public String toString() {
return S.toString(GridLoggerProxy.class, this);
}

/** Shared log message metrics for all logger categories of a node. */
private static class LogMetrics {
/** Trace messages count. */
private final LongAdderMetric trace = metric("trace", "Total number of TRACE log messages.");

/** Debug messages count. */
private final LongAdderMetric debug = metric("debug", "Total number of DEBUG log messages.");

/** Info messages count. */
private final LongAdderMetric info = metric("info", "Total number of INFO log messages.");

/** Warning messages count. */
private final LongAdderMetric warning = metric("warning", "Total number of WARN log messages.");

/** Error messages count. */
private final LongAdderMetric error = metric("error", "Total number of ERROR log messages.");

/**
* @param name Metric name.
* @param desc Metric description.
* @return Metric.
*/
private static LongAdderMetric metric(String name, String desc) {
return new LongAdderMetric(metricName(LOG_COUNT_METRICS, name), desc);
}

/**
* @param mreg Metrics registry.
*/
private void register(MetricRegistryImpl mreg) {
mreg.register(trace);
mreg.register(debug);
mreg.register(info);
mreg.register(warning);
mreg.register(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,9 @@ public void start(

ctx.pools().registerMetrics();

if (ctx.metric().enabled())
log.registerMetrics(ctx.metric());

registerMetrics();

registerConfigurationSystemView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ public CdcMain(
try {
U.initWorkDir(igniteCfg);

log = U.initLogger(igniteCfg, "ignite-cdc");
log = new GridLoggerProxy(
U.initLogger(igniteCfg, "ignite-cdc"),
null,
cdcInstanceName(igniteCfg.getIgniteInstanceName()),
igniteCfg.getNodeId() == null ? null : U.id8(igniteCfg.getNodeId())
);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
Expand Down Expand Up @@ -402,6 +407,9 @@ private void startStandaloneKernal() throws IgniteCheckedException {
metricSpi.onContextInitialized(new StandaloneSpiContext());
}

if (kctx.metric().enabled())
((GridLoggerProxy)log).registerMetrics(kctx.metric());

mreg = kctx.metric().registry("cdc");
}

Expand Down
Loading
Loading