java.lang.Object
org.elasticsearch.xpack.core.watcher.common.stats.Counters
All Implemented Interfaces:
Writeable

public final class Counters extends Object implements Writeable
Helper class to create simple usage stat counters based on longs Internally this is a map mapping from String to a long, which is the counter Calling toNestedMap() will create a nested map, where each dot of the key name will nest deeper The main reason for this class is that the stats producer should not be worried about how the map is actually nested
  • Constructor Details

  • Method Details

    • set

      public void set(String name)
      Sets a counter. This ensures that the counter is there, even though it is never incremented.
      Parameters:
      name - Name of the counter
    • inc

      public void inc(String name)
      Increment the counter by one
      Parameters:
      name - Name of the counter
    • inc

      public void inc(String name, long count)
      Increment the counter by configured number
      Parameters:
      name - The name of the counter
      count - Incremental value
    • get

      public long get(String name)
    • size

      public long size()
    • hasCounters

      public boolean hasCounters()
    • toNestedMap

      public Map<String,Object> toNestedMap()
      Convert the counters to a nested map, using the "." as a splitter to create deeper maps
      Returns:
      A nested map with all the current configured counters
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • merge

      public static Counters merge(List<Counters> counters)