Class MetricFactory

java.lang.Object
org.sentrysoftware.metricshub.engine.telemetry.MetricFactory

public class MetricFactory extends Object
Factory class for creating and collecting metrics for a Monitor based on information provided by a Connector.
  • Constructor Details

    • MetricFactory

      public MetricFactory()
  • Method Details

    • collectStateSetMetric

      public StateSetMetric collectStateSetMetric(Monitor monitor, String metricName, String value, String[] stateSet, long collectTime)
      This method sets a stateSet metric in the monitor
      Parameters:
      monitor - a given monitor
      metricName - the metric's name
      value - the metric's value
      stateSet - array of states values. E.g. [ "ok", "degraded", "failed" ]
      collectTime - the metric's collect time
      Returns:
      collected metric
    • extractAttributesFromMetricName

      public static Map<String,String> extractAttributesFromMetricName(String metricName)
      This method extracts the metric attributes from its name
      Parameters:
      metricName - the metric's name
      Returns:
      a Map with attributes names as keys and attributes values as values
    • collectNumberMetric

      public NumberMetric collectNumberMetric(Monitor monitor, String name, @NonNull @NonNull Double value, Long collectTime)
      This method sets number metric in the monitor
      Parameters:
      monitor - a given monitor
      name - the metric's name
      value - the metric's value
      collectTime - the metric's collect time
      Returns:
      collected metric
    • collectNumberMetric

      public NumberMetric collectNumberMetric(Monitor monitor, String name, @NonNull @NonNull String value, Long collectTime)
      This method sets number metric in the monitor
      Parameters:
      monitor - a given monitor
      name - the metric's name
      value - the metric's value
      collectTime - the metric's collect time
      Returns:
      collected metric
    • getMetricDefinitionFromExtractedMetricName

      public MetricDefinition getMetricDefinitionFromExtractedMetricName(Connector connector, Monitor monitor, String metricName)
      This method returns a metric definition based on the extracted metric name (metric name without attributes)
      Parameters:
      connector - a given connector
      monitor - a given monitor
      metricName - a given metric name
      Returns:
      MetricDefinition instance
    • collectMetricUsingConnector

      public AbstractMetric collectMetricUsingConnector(Connector connector, Monitor monitor, long strategyTime, String metricName, String metricValue)
      This method collects a metric using the connector metrics
      Parameters:
      connector - a given connector
      monitor - a given monitor
      strategyTime - strategy time
      metricName - metric's name
      metricValue - metric's value
      Returns:
      AbstractMetric instance
    • extractName

      public static final String extractName(String name)
      This method removes attribute parts from the metric name
      Parameters:
      name - metric name with or without attributes
      Returns:
      metric name without attributes
    • checkForStateAttribute

      public boolean checkForStateAttribute(Map<String,String> attributes)
      Checks whether the state attribute exists in the metric attributes.
      Parameters:
      attributes - Metric attributes.
      Returns:
      true if the state attribute exists, false otherwise.
    • collectMonitorMetrics

      public void collectMonitorMetrics(String monitorType, Connector connector, Monitor monitor, String connectorId, Map<String,String> metrics, long strategyTime, boolean isDiscovery)
      This method collects monitor metrics
      Parameters:
      monitorType - the monitor's type
      connector - connector
      monitor - a given monitor
      connectorId - connector id
      metrics - metrics
      strategyTime - time of the strategy in milliseconds
      isDiscovery - boolean whether it's a discovery operation