Skip to content
Merged
2 changes: 1 addition & 1 deletion docs/_docs/monitoring-metrics/new-metrics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Register name: `io.dataregion.{data_region_name}`
[cols="2,1,3",opts="header"]
|===
|Name | Type | Description
|AllocationRate | long| Allocation rate (pages per second) averaged across rateTimeInternal.
|AllocationRate | long| Allocation rate (pages per second) averaged across rateTimeInterval.
|CheckpointBufferSize | long | Checkpoint buffer size in bytes.
|DirtyPages | long| Number of pages in memory not yet synchronized with persistent storage.
|EmptyDataPages| long| Calculates empty data pages count for region. It counts only totally free pages that can be reused (e. g. pages that are contained in reuse bucket of free list).
Expand Down
11 changes: 11 additions & 0 deletions docs/_docs/monitoring-metrics/system-views.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,17 @@ This view exposes the contents of the metastorage cache.
|VALUE | string | String or raw binary (if data could not be deserialized for some reason) representation of an element
|===

== DISTRIBUTED_METASTORAGE

This view exposes the contents of the distributed metastorage cache.

[{table_opts}]
|===
|Column | Data type | Description
|NAME | string | Name
|VALUE | string | String or raw binary (if data could not be deserialized for some reason) representation of an element
|===

== DS_QUEUES

This view exposes the list of `IgniteQueue`.
Expand Down
20 changes: 20 additions & 0 deletions docs/_docs/tools/control-script.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,26 @@ io.dataregion.default.PagesReplaceAge 0
io.dataregion.default.PhysicalMemoryPages 0
Command [METRIC] finished with code: 0

== Metric configure command

The metrics command configure bounds of histogram metrics or rate time interval of hitrate metric.

[tabs]
--
tab:Unix[]
[source,shell,subs="verbatim,quotes"]
----
control.sh --metric --configure-histogram histogram-metric-name 1,2,3
control.sh --metric --configure-hitrate hitrate-metric-name 1000
----
tab:Windows[]
[source,shell,subs="verbatim,quotes"]
----
control.bat --metric --configure-histogram histogram-metric-name 1,2,3
control.bat --metric --configure-hitrate hitrate-metric-name 1000
----
--

== Indexes Management

The commands below allow to get a specific information on indexes and to trigger the indexes rebuild process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.apache.ignite.internal.commandline.metric;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.ignite.IgniteLogger;
Expand All @@ -31,13 +31,18 @@
import org.apache.ignite.internal.commandline.CommandArgIterator;
import org.apache.ignite.internal.commandline.CommandLogger;
import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.visor.metric.VisorMetricTask;
import org.apache.ignite.internal.visor.metric.VisorMetricTaskArg;

import static java.util.Arrays.asList;
import static org.apache.ignite.internal.commandline.CommandList.METRIC;
import static org.apache.ignite.internal.commandline.CommandLogger.grouped;
import static org.apache.ignite.internal.commandline.CommandLogger.optional;
import static org.apache.ignite.internal.commandline.CommandLogger.or;
import static org.apache.ignite.internal.commandline.TaskExecutor.executeTaskByNameOnNode;
import static org.apache.ignite.internal.commandline.metric.MetricCommandArg.CONFIGURE_HISTOGRAM;
import static org.apache.ignite.internal.commandline.metric.MetricCommandArg.CONFIGURE_HITRATE;
import static org.apache.ignite.internal.commandline.metric.MetricCommandArg.NODE_ID;
import static org.apache.ignite.internal.commandline.systemview.SystemViewCommand.printTable;
import static org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;
Expand Down Expand Up @@ -75,7 +80,7 @@ public class MetricCommand extends AbstractCommand<VisorMetricTaskArg> {

printTable(asList("metric", "value"), asList(STRING, STRING), data, log);
}
else
else if (arg().bounds() == null && arg().rateTimeInterval() < 0)
log.info("No metric with specified name was found [name=" + taskArg.name() + "]");

return res;
Expand All @@ -93,6 +98,8 @@ public class MetricCommand extends AbstractCommand<VisorMetricTaskArg> {
nodeId = null;

String metricName = null;
Object val = null;
boolean configureHistogram = false;

while (argIter.hasNextSubArg()) {
String arg = argIter.nextArg("Failed to read command argument.");
Expand All @@ -112,6 +119,31 @@ public class MetricCommand extends AbstractCommand<VisorMetricTaskArg> {
" 123e4567-e89b-42d3-a456-556642440000", e);
}
}
else if (cmdArg == CONFIGURE_HISTOGRAM || cmdArg == CONFIGURE_HITRATE) {
if (metricName != null) {
throw new IllegalArgumentException(
"One of " + CONFIGURE_HISTOGRAM + ", " + CONFIGURE_HITRATE + " must be specified"
);
}

configureHistogram = cmdArg == CONFIGURE_HISTOGRAM;
metricName = argIter.nextArg("Name of metric to configure expected");

if (configureHistogram) {
val = Arrays.stream(argIter.nextArg("Comma-separated histogram bounds expected").split(","))
.mapToLong(Long::parseLong)
.toArray();

if (!F.isSorted((long[])val))
throw new IllegalArgumentException("Bounds must be sorted");
}
else {
val = argIter.nextNonNegativeLongArg("Hitrate time interval");

if ((long)val == 0)
throw new IllegalArgumentException("Positive value expected");
}
}
else {
if (metricName != null)
throw new IllegalArgumentException("Multiple metric(metric registry) names are not supported.");
Expand All @@ -123,7 +155,11 @@ public class MetricCommand extends AbstractCommand<VisorMetricTaskArg> {
if (metricName == null)
throw new IllegalArgumentException("The name of a metric(metric registry) is expected.");

taskArg = new VisorMetricTaskArg(metricName);
taskArg = new VisorMetricTaskArg(
metricName,
val != null && configureHistogram ? (long[])val : null,
val != null && !configureHistogram ? (Long)val : -1
);
}

/** {@inheritDoc} */
Expand All @@ -133,14 +169,27 @@ public class MetricCommand extends AbstractCommand<VisorMetricTaskArg> {

/** {@inheritDoc} */
@Override public void printUsage(IgniteLogger log) {
Map<String, String> params = new HashMap<>();
Map<String, String> params = new TreeMap<>();

params.put("node_id", "ID of the node to get the metric values from. If not set, random node will be chosen.");
params.put("name", "Name of the metric which value should be printed." +
" If name of the metric registry is specified, value of all its metrics will be printed.");

usage(log, "Print metric value:", METRIC, params, optional(NODE_ID, "node_id"),
"name");

params.remove("node_id");
params.put("name", "Name of the metric which value should be configured.");
params.put("newBounds", "Comma-separated list of longs to configure histogram.");
params.put("newRateTimeInterval", "Rate time interval of hitrate.");

usage(
log,
"Configure metric:", METRIC,
params,
or(grouped(CONFIGURE_HISTOGRAM, "name", "newBounds"),
grouped(CONFIGURE_HITRATE, "name", "newRateTimeInterval"))
);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
/** Represents all possible arguments for {@link MetricCommand}. */
public enum MetricCommandArg implements CommandArg {
/** Id of the node to get metric values from. */
NODE_ID("--node-id");
NODE_ID("--node-id"),

/** Configure histograme. */
CONFIGURE_HISTOGRAM("--configure-histogram"),

/** Configure histograme. */
CONFIGURE_HITRATE("--configure-hitrate");

/** Name of the argument. */
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
import org.apache.ignite.internal.commandline.metric.MetricCommandArg;
import org.apache.ignite.internal.processors.metric.MetricRegistry;
import org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl;
import org.apache.ignite.internal.processors.metric.impl.HitRateMetric;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.junit.Test;

import static java.util.regex.Pattern.quote;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.internal.commandline.CommandList.METRIC;
import static org.apache.ignite.internal.commandline.metric.MetricCommandArg.CONFIGURE_HISTOGRAM;
import static org.apache.ignite.internal.commandline.metric.MetricCommandArg.CONFIGURE_HITRATE;
import static org.apache.ignite.internal.commandline.metric.MetricCommandArg.NODE_ID;
import static org.apache.ignite.internal.commandline.systemview.SystemViewCommand.COLUMN_SEPARATOR;
import static org.apache.ignite.internal.processors.metric.GridMetricManager.IGNITE_METRICS;
Expand Down Expand Up @@ -114,6 +117,107 @@ public void testNonExistentMetric() {
"No metric with specified name was found [name=nonexistent.metric]");
}

/** Tests command error output in case of invalid arguments for configure command. */
@Test
public void testInvalidConfigureMetricParameter() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the a check both config arguments: hitrate & bounds

assertContains(log, executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HISTOGRAM.argName()),
"Name of metric to configure expected");

assertContains(log, executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HITRATE.argName()),
"Name of metric to configure expected");

assertContains(log,
executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HISTOGRAM.argName(), "some.metric"),
"Comma-separated histogram bounds expected"
);

assertContains(
log,
executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HITRATE.argName(), "some.metric"),
"Hitrate time interval"
);

assertContains(
log,
executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HISTOGRAM.argName(), "some.metric", "not_a_number"),
"Check arguments. For input string: \"not_a_number\""
);

assertContains(
log,
executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HITRATE.argName(), "some.metric", "not_a_number"),
"Check arguments. Invalid value for Hitrate time interval: not_a_number"
);

assertContains(
log,
executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HISTOGRAM.argName(), "some.metric", "1,not_a_number"),
"Check arguments. For input string: \"not_a_number\""
);

assertContains(
log,
executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, CONFIGURE_HISTOGRAM.argName(), "some.metric", "3,2,1"),
"Bounds must be sorted"
);

assertContains(
log,
executeCommand(
EXIT_CODE_INVALID_ARGUMENTS,
CMD_METRIC,
CONFIGURE_HISTOGRAM.argName(),
"some.metric",
"1,2,3",
CONFIGURE_HITRATE.argName()
),
"One of " + CONFIGURE_HISTOGRAM.argName() + ", " + CONFIGURE_HITRATE.argName() + " must be specified"
);
}

/** Tests configuration of histgoram metric. */
@Test
public void testConfigureHistogram() {
String mregName = "configure-registry";

MetricRegistry mreg = ignite0.context().metric().registry(mregName);

long[] bounds = new long[] {50, 500};

HistogramMetricImpl histogram = mreg.histogram("histogram", bounds, null);

bounds = histogram.bounds();

assertEquals(2, bounds.length);
assertEquals(50, bounds[0]);
assertEquals(500, bounds[1]);

executeCommand(EXIT_CODE_OK, CMD_METRIC, CONFIGURE_HISTOGRAM.argName(), histogram.name(), "1,2,3");

bounds = histogram.bounds();

assertEquals(3, bounds.length);
assertEquals(1, bounds[0]);
assertEquals(2, bounds[1]);
assertEquals(3, bounds[2]);
}

/** Tests configuration of hitrate metric. */
@Test
public void testConfigureHitrate() {
String mregName = "configure-registry";

MetricRegistry mreg = ignite0.context().metric().registry(mregName);

HitRateMetric hitrate = mreg.hitRateMetric("hitrate", null, 500, 5);

assertEquals(500, hitrate.rateTimeInterval());

executeCommand(EXIT_CODE_OK, CMD_METRIC, CONFIGURE_HITRATE.argName(), hitrate.name(), "100");

assertEquals(100, hitrate.rateTimeInterval());
}

/** */
@Test
public void testHistogramMetrics() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public DataRegionMetricsImpl(
MetricRegistry mreg = metricRegistry();

allocRate = mreg.hitRateMetric("AllocationRate",
"Allocation rate (pages per second) averaged across rateTimeInternal.",
"Allocation rate (pages per second) averaged across rateTimeInterval.",
60_000,
5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ private void registerSystemView() {
try {
List<MetastorageView> data = new ArrayList<>();

iterate("", (key, val) -> data.add(new MetastorageView(key, IgniteUtils.toStringSafe(val))));
iterate("", (key, val) -> data.add(new MetastorageView(key, val == null || !val.getClass().isArray()
? IgniteUtils.toStringSafe(val)
: S.arrayToString(val))));

return data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class PoolProcessor extends GridProcessorAdapter {
public static final String THREAD_POOLS = "threadPools";

/** Histogram buckets for the task execution time metric (in milliseconds). */
public static final long[] TASK_EXEC_TIME_HISTOGRAM_BUCKETS = new long[] {100, 1000, 10000, 30000, 60000};
public static final long[] TASK_EXEC_TIME_HISTOGRAM_BUCKETS = new long[] {10, 50, 100, 500, 1000};

/** Executor service. */
@GridToStringExclude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.processors.metric.GridMetricManager;
import org.apache.ignite.internal.processors.task.GridInternal;
Expand Down Expand Up @@ -71,6 +72,22 @@ protected VisorMetricJob(@Nullable VisorMetricTaskArg arg, boolean debug) {

GridMetricManager mmgr = ignite.context().metric();

try {
if (arg.bounds() != null) {
mmgr.configureHistogram(arg.name(), arg.bounds());

return null;
}
else if (arg.rateTimeInterval() > 0) {
mmgr.configureHitRate(arg.name(), arg.rateTimeInterval());

return null;
}
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}

for (ReadOnlyMetricRegistry mreg : mmgr) {
String mregName = mreg.name();

Expand Down
Loading