Class MetricFactory
java.lang.Object
org.sentrysoftware.metricshub.engine.telemetry.MetricFactory
Factory class for creating and collecting metrics for a Monitor based on information provided by a Connector.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckForStateAttribute(Map<String, String> attributes) Checks whether the state attribute exists in the metric attributes.collectMetricUsingConnector(Connector connector, Monitor monitor, long strategyTime, String metricName, String metricValue) This method collects a metric using the connector metricsvoidcollectMonitorMetrics(String monitorType, Connector connector, Monitor monitor, String connectorId, Map<String, String> metrics, long strategyTime, boolean isDiscovery) This method collects monitor metricscollectNumberMetric(Monitor monitor, String name, @NonNull Double value, Long collectTime) This method sets number metric in the monitorcollectNumberMetric(Monitor monitor, String name, @NonNull String value, Long collectTime) This method sets number metric in the monitorcollectStateSetMetric(Monitor monitor, String metricName, String value, String[] stateSet, long collectTime) This method sets a stateSet metric in the monitorextractAttributesFromMetricName(String metricName) This method extracts the metric attributes from its namestatic final StringextractName(String name) This method removes attribute parts from the metric namegetMetricDefinitionFromExtractedMetricName(Connector connector, Monitor monitor, String metricName) This method returns a metric definition based on the extracted metric name (metric name without attributes)
-
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 monitormetricName- the metric's namevalue- the metric's valuestateSet- array of states values. E.g. [ "ok", "degraded", "failed" ]collectTime- the metric's collect time- Returns:
- collected metric
-
extractAttributesFromMetricName
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 monitorname- the metric's namevalue- the metric's valuecollectTime- 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 monitorname- the metric's namevalue- the metric's valuecollectTime- 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 connectormonitor- a given monitormetricName- 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 connectormonitor- a given monitorstrategyTime- strategy timemetricName- metric's namemetricValue- metric's value- Returns:
- AbstractMetric instance
-
extractName
This method removes attribute parts from the metric name- Parameters:
name- metric name with or without attributes- Returns:
- metric name without attributes
-
checkForStateAttribute
Checks whether the state attribute exists in the metric attributes.- Parameters:
attributes- Metric attributes.- Returns:
trueif the state attribute exists,falseotherwise.
-
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 typeconnector- connectormonitor- a given monitorconnectorId- connector idmetrics- metricsstrategyTime- time of the strategy in millisecondsisDiscovery- boolean whether it's a discovery operation
-