java.lang.Object
org.elasticsearch.common.metrics.Counters
- All Implemented Interfaces:
Writeable
Simple usage stat counters based on longs. Internally this is a map mapping from String which is the counter's label to a CounterMetric
which is the value. This class also provides a helper method that converts the counters to a nested map, using the "." in the label as a
splitter. This allows the stats producer to not worry about how the map is actually nested.
IMPORTANT: if the consumer of the metrics will make use of the nested map, it is the responsibility of the producer to provide labels
that will not have conflicts, which means that there no counter will have a label which is a substring of the label of another counter.
For example, the counters `foo: 1` and `foo.bar: 3` cannot co-exist in a nested map.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
boolean
void
Increment the counter by onevoid
Increment the counter by configured numberstatic Counters
long
size()
Convert the counters to a nested map, using the "." as a splitter to create a nested map.void
writeTo
(StreamOutput out) Write this into the StreamOutput.
-
Constructor Details
-
Counters
- Throws:
IOException
-
Counters
-
-
Method Details
-
inc
Increment the counter by one- Parameters:
name
- Name of the counter
-
inc
Increment the counter by configured number- Parameters:
name
- The name of the countercount
- Incremental value
-
get
-
size
public long size() -
hasCounters
public boolean hasCounters() -
toMutableNestedMap
Convert the counters to a nested map, using the "." as a splitter to create a nested map. For example, the counters `foo.bar`: 2, `foo.baz`: 1, `foobar`: 5 would become: { "foo": { "bar": 2, "baz": 1 }, "foobar": 5 }- Returns:
- A mutable nested map with all the current configured counters. The map is mutable to allow the client to further enrich it.
- Throws:
IllegalStateException
- if there is a conflict in a path of two counters for example `foo`: 1 and `foo.bar`: 1.
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput.- Specified by:
writeTo
in interfaceWriteable
- Throws:
IOException
-
merge
-