Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Provides metricManager start-up, acquisition, and shutdown functions that can be used in the future after being registered as Iservice.

TODO pic

image2021-7-12_17-12-42.png

2.2 Class diagram

image2021-7-14_12-41-48.pngImage RemovedImage Added

2.3 IMetric

IMetric is the collector parent interface.

...

Code Block
public interface Counter extends MetricIMetric {
  void inc();
/**
   * Counter add 1
   */
  void inc(long n);

  long count();
}

2.3.2 Gauge

Gauge is a staging device for a value.

Code Block
public interface Gauge extends IMetric {
  long value();

  void set(long value/**
   * Counter add n
   * @param n
   */
  void inc(long n);

  /**
   * Get value of counter
   * @return
   */
  long count();
}

2.3.

...

2 Gauge

Gauge is a staging device for a valueCalculate the rate and average rate of a value over the last 1,5,15 minutes.

Code Block
public interface RateGauge extends IMetric {
	long getCount();

	double getOneMinuteRate();

	double getMeanRate();

	double getFiveMinuteRate();

	double getFifteenMinuteRate();

	void mark();

	void mark(long n);
}

2.3.4 Histogram and HistogramSnapshot

Snapshot is a class that hosts data, providing a percentile ratio and a list of numbers that are counted by interval cut-off.

Code Block
public interface Histogram extends IMetric {
 void update(int value);

 void update(long value);

 long count();

 HistogramSnapshot takeSnapshot();
}



public interface HistogramSnapshot {

  public abstract double getValue(double quantile);

  public abstract long[] getValues();

  public abstract int size();

  public double getMedian();

  public abstract long getMax();

  public abstract double getMean();

  public abstract long getMin();

  public abstract void dump(OutputStream output);
}

2.3.5 Timer

Timer records the histogram of time and the rate of research (Meter and Histogram).

Code Block
public interface Timer extends IMetric {
  void update(long duration, TimeUnit unit);

  default void updateMillis(long durationMillis) {
    update(durationMillis, TimeUnit.NANOSECONDS);
  }

  default void updateMicros(long durationMicros) {
    update(durationMicros, TimeUnit.MICROSECONDS);
  }

  default void updateNanos(long durationNanos) {
    update(durationNanos, TimeUnit.NANOSECONDS);
  }

  HistogramSnapshot takeSnapshot();

  Rate getImmutableRate();
}

2.4 MetricManager

  MetricManager provides interfaces for new, deleted, modified, and querying function for MetricReporter andMetric, as well as switches for data acquisition that are exposed.

Code Block
public interface MetricManager {

  Counter getOrCreateCounter(String metric, String... tags);

  Gauge getOrCreatGauge(String metric, String... tags);

  Rate getOrCreatRate(String metric, String... tags);

  Histogram getOrCreateHistogram(String metric, String... tags);

  Timer getOrCreateTimer(String metric, String... tags);

  void count(int delta, String metric, String... tags);

  void count(long delta, String metric, String... tags);

  void gauge(int value, String metric, String... tags);

  void gauge(long value, String metric, String... tags);

  void rate(int value, String metric, String... tags);

  void rate(long value, String metric, String... tags);

  void histogram(int value, String metric, String... tags);

  void histogram(long value, String metric, String... tags);

  void timer(long delta, TimeUnit timeUnit, String metric, String... tags);

  void removeCounter(String metric, String... tags);

  void removeGauge(String metric, String... tags);

  void removeRate(String metric, String... tags);

  void removeHistogram(String metric, String... tags);

  void removeTimer(String metric, String... tags);

  List<String[]> getAllMetricKeys();

  Map<String[], Counter> getAllCounters();

  Map<String[], Gauge> getAllGauges();

  Map<String[], Rate> getAllRates();

  Map<String[], Histogram> getAllHistograms();

  Map<String[], Timer> getAllTimers();

  boolean isEnable();

  void enableKnownMetric(KnownMetric metric);

  boolean init();

  boolean stop();

  boolean startReporter(String reporterName);

  boolean stopReporter(String reporterName);

  void setReporter(MetricReporter metricReporter);

  String getName();
}

2.5 MetricReporter

MetricReporter is a data push interface.

  /**
   * Set value to gauge
   * @return
   */
  void set(long value);

  /**
   * Get value stored in gauge
   * @return
   */
  long value();
}

2.3.3 Rate

Calculate the rate and average rate of a value over the last 1,5,15 minutes.

Code Block
public interface Rate extends IMetric {
  /**
   * Get value of Rate
   * @return
   */
  long getCount();

  /**
   * Get one minute rate
   * @return
   */
  double getOneMinuteRate();

  /**
   * Get mean rate
   * @return
   */
  double getMeanRate();

  /**
   * Get five minute rate
   * @return
   */
  double getFiveMinuteRate();

  /**
   * Get fifteen minute rate
   * @return
   */
  double getFifteenMinuteRate();

  /**
   * mark in rate
   */
  void mark();

  /**
   * mark n in rate
   * @param n
   */
  void mark(long n);
}

2.3.4 Histogram and HistogramSnapshot

Snapshot is a class that hosts data, providing a percentile ratio and a list of numbers that are counted by interval cut-off.

Code Block
public interface Histogram extends IMetric {
  /**
   * update histogram by value
   * @param value
   */
  void update(int value);

  /**
   * update histogram by value
   * @param value
   */
  void update(long value);

  /**
   * get value of histogram
   * @return
   */
  long count();

  /**
   * tak snapshot of histogram
   * @return
   */
  HistogramSnapshot takeSnapshot();
}




public interface HistogramSnapshot {

  /**
   * Get value by quantile
   * @param quantile
   * @return
   */
  public abstract double getValue(double quantile);

  /**
   * Get values in snapshot
   * @return
   */
  public abstract long[] getValues();

  /**
   * Get size of value in snapshot
   * @return
   */
  public abstract int size();

  /**
   * Get median of values
   * @return
   */
  public double getMedian();

  /**
   * Get min of values
   * @return
   */
  public abstract long getMin();

  /**
   * Get mean of values
   * @return
   */
  public abstract double getMean();

  /**
   * Get max of values
   * @return
   */
  public abstract long getMax();

  /**
   * Writes the values of the snapshot to the given stream.
   *
   * @param output an output stream
   */
  public abstract void dump(OutputStream output);
}

2.3.5 Timer

Timer records the histogram of time and the rate of research (Meter and Histogram).

Code Block
public interface Timer extends IMetric {

  /**
   * update time of timer
   * @param duration
   * @param unit
   */
  void update(long duration, TimeUnit unit);

  /**
   * update timer by millisecond
   * @param durationMillis
   */
  default void updateMillis(long durationMillis) {
    update(durationMillis, TimeUnit.MILLISECONDS);
  }

  /**
   * update timer by microseconds
   * @param durationMicros
   */
  default void updateMicros(long durationMicros) {
    update(durationMicros, TimeUnit.MICROSECONDS);
  }

  /**
   * update timer by nanoseconds
   * @param durationNanos
   */
  default void updateNanos(long durationNanos) {
    update(durationNanos, TimeUnit.NANOSECONDS);
  }

  /**
   * take snapshot of timer
   * @return
   */
  HistogramSnapshot takeSnapshot();

  /**
   * It's not safe to use the update interface.
   *
   * @return the getOrCreatRate related with the getOrCreateTimer
   */
  Rate getImmutableRate();
}


2.4 MetricManager

  MetricManager provides interfaces for new, deleted, modified, and querying function for MetricReporter andMetric, as well as switches for data acquisition that are exposed.

Code Block
public interface MetricManager {
  /**
   * Get Counter
   * If exists, then return
   * or create one to return
   * @param metric
   * @param tags string appear in pairs, like sg="ln" will be "sg", "ln"
   * @return
   */
  Counter getOrCreateCounter(String metric, String... tags);

  /**
   * Get Guage
   * If exists, then return
   * or create one to return
   * @param metric
   * @param tags string appear in pairs, like sg="ln" will be "sg", "ln"
   * @return
   */
  Gauge getOrCreatGauge(String metric, String... tags);

  /**
   * Get Rate
   * If exists, then return
   * or create one to return
   * @param metric
   * @param tags string appear in pairs, like sg="ln" will be "sg", "ln"
   * @return
   */
  Rate getOrCreatRate(String metric, String... tags);

  /**
   * Get Histogram
   * If exists, then return
   * or create one to return
   * @param metric
   * @param tags string appear in pairs, like sg="ln" will be "sg", "ln"
   * @return
   */
  Histogram getOrCreateHistogram(String metric, String... tags);

  /**
   * Get Timer
   * If exists, then return
   * or create one to return
   * @param metric
   * @param tags string appear in pairs, like sg="ln" will be "sg", "ln"
   * @return
   */
  Timer getOrCreateTimer(String metric, String... tags);

  /**
   * Update Counter
   * @param delta
   * @param metric
   * @param tags
   */
  void count(int delta, String metric, String... tags);

  /**
   * Update Counter
   * @param delta
   * @param metric
   * @param tags
   */
  void count(long delta, String metric, String... tags);

  /**
   * update Gauge
   * @param value
   * @param metric
   * @param tags
   */
  void gauge(int value, String metric, String... tags);

  /**
   * update Gauge
   * @param value
   * @param metric
   * @param tags
   */
  void gauge(long value, String metric, String... tags);

  /**
   * update Rate
   * @param value
   * @param metric
   * @param tags
   */
  void rate(int value, String metric, String... tags);

  /**
   * update Rate
   * @param value
   * @param metric
   * @param tags
   */
  void rate(long value, String metric, String... tags);

  /**
   * update Histogram
   * @param value
   * @param metric
   * @param tags
   */
  void histogram(int value, String metric, String... tags);

  /**
   * update Histogram
   * @param value
   * @param metric
   * @param tags
   */
  void histogram(long value, String metric, String... tags);

  /**
   * update Timer
   * @param delta
   * @param timeUnit
   * @param metric
   * @param tags
   */
  void timer(long delta, TimeUnit timeUnit, String metric, String... tags);

  /**
   * remove counter
   * @param metric
   * @param tags
   */
  void removeCounter(String metric, String... tags);

  /**
   * remove gauge
   * @param metric
   * @param tags
   */
  void removeGauge(String metric, String... tags);

  /**
   * remove rate
   * @param metric
   * @param tags
   */
  void removeRate(String metric, String... tags);

  /**
   * remove histogram
   * @param metric
   * @param tags
   */
  void removeHistogram(String metric, String... tags);

  /**
   * update timer
   * @param metric
   * @param tags
   */
  void removeTimer(String metric, String... tags);

  /**
   * get all metric keys.
   *
   * @return all MetricKeys, key is metric name, value is tags, which is a string array.
   */
  List<String[]> getAllMetricKeys();

  /**
   * Get all counters
   * @return [name, tags...] -> counter
   */
  Map<String[], Counter> getAllCounters();

  /**
   * Get all gauges
   * @return [name, tags...] -> gauge
   */
  Map<String[], Gauge> getAllGauges();

  /**
   * Get all rates
   * @return [name, tags...] -> rate
   */
  Map<String[], Rate> getAllRates();

  /**
   * Get all histogram
   * @return [name, tags...] -> histogram
   */
  Map<String[], Histogram> getAllHistograms();

  /**
   * Get all timers
   * @return [name, tags...] -> timer
   */
  Map<String[], Timer> getAllTimers();

  /**
   * whether is enable monitor
   * @return
   */
  boolean isEnable();

  /**
   * enable pre-defined metric set.
   *
   * @param metric which metric set we want to collect
   */
  void enablePredefinedMetric(PredefinedMetric metric);

  /**
   * init something.
   *
   * @return whether success
   */
  boolean init();

  /**
   * stop everything and clear
   *
   * @return
   */
  boolean stop();

  /**
   * Get name of manager
   * @return
   */
  String getName();
}

2.5 MetricReporter

MetricReporter is a data push interface.

Code Block
public interface CompositeReporter {

  /**
   * Start all reporter
   * @return
   */
  boolean start();

  /**
   * Start reporter by name
   * name values in jmx, prometheus, iotdb, internal
   * @param reporter
   * @return
   */
  boolean start(String reporter);

  /**
   * Stop all reporter
   * @return
   */
  boolean stop();

  /**
   * Stop reporter by name
   * name values in jmx, prometheus, iotdb, internal
   * @param reporter
   * @return
   */
  boolean stop(String reporter);

  /**
   * set manager to reporter
   * @param metricManager
   */
  void setMetricManager(MetricManager metricManager);

  /**
   * Get name of CompositeReporter
   * @return
   */
  String getName();
Code Block
public interface MetricReporter {
  boolean start();

  boolean start(String reporter);

  boolean stop();

  boolean stop(String reporter);

  String getName();
}

3. Test Report

We implemented the monitoring framework using Dropwizard and Micromometer respectively, and tested the results as follows:

...

To ensure the reliability of the features, we unit tested DrowizardMetricManager, covering the main function. To re-emerge the test, you need to modify the yml profile address in the init() method (the profile is stored under the conf of the statistical directory). The final result of the test is shown in the figure below.

Image RemovedImage Added

5. Dropwizard connects to Prometheus via PushGateway

...