Data

The Metrics Data library provides common handler functions used by threaded applications to save and manage metric data.

Synopsis

use Assure1::Metrics::Data;

Functions

The Metrics Data library contains the functions described below.

CreateMeasurement

Creates an Influx Measurement hash for passing to InsertMetricWorker. Data tags are not automatically sanitized; use Metrics::SanitizeInfluxTag to handle special characters.

CreateMeasurement($host, $instance, $shard, $zone, $measurement, $status, $value, $utilization, $currentTime)

Arguments

host        -> Device Host (DNSName, IPv6, IPv4)
instance    -> Instance Name
shard       -> Influx ShardID
zone        -> Device Zone
measurement -> Measurement (for example, metrictype_Metric_Type_Name)
status      -> (optional) Availability of the metric. Boolean. When true, store the value and utilization if they are defined.
value       -> Metric value
utilization -> (optional) Calculated utilization for measurement.
currentTime -> Epoch time collected. Oracle recommends using the epoch from time() rounded to nearest poll time.

Returns

{
    measurement     => metrictype_Metric_Type_Name,
    tags {
            host        => Hostname,
            instance    => InstanceName,
    }
    fields {
            value       => 0.12345,
            utilization => 0.5
    }
    epochTime       => 1596927600
}

Synopsis

my $MeasurementHash = CreateMeasurement($host, $instance, $shard, $zone, $measurement, $status, $value, $utilization, $currentTime);

InsertDBDataWorker

A data thread function to handle processing metric data. Data tags in modern format are automatically sanitized.

Because it implements blocking logic, this function is meant to be instantiated as a continuously running thread.

InsertDBDataWorker(\%options)

Options

DataQueue        -> Thread::Queue handle to listen for data
ThresholdQueue   -> (optional) Thread::Queue handle to send data for violation checking
Log              -> Assure1::Log handle for logging output
MetricBatchQueue -> Thread::Queue handle to send data to insert
StorageHash      -> Cache (for example, $StorageHash)

Returns

none

Synopsis

threads->new(\&Assure1::Metrics::Data::InsertDBDataWorker, {
    DataQueue        => $DataQueue,
    Log              => $Log,
    MetricBatchQueue => $MetricBatchQueue,
    StorageHash      => $StorageHash
});

# RECOMMENDED (hash reference)
#   measurement     -> Measurement (e.g. metrictype_Metric_Type_Name)
#   tags            -> hash reference of:
#       host        -> Device Host (DNSName, IPv6, IPv4)
#       instance    -> Instance Name
#   fields          -> hash reference of:
#       value       -> value to send
#       utilization -> (optional) Utilization of value if a max value is known
#   epochTime       -> Epoch time collected. Strongly recommend using the epoch from time() rounded to nearest poll time
$DataQueue->enqueue({
    measurement => $measurement,
    tags        => {
        host     => $host,
        instance => $instanceName
    },
    fields      => {
        value => $value
    },
    epochTime   => $currentTime
});

DEPRECATED (string)

$DataQueue->enqueue("$metricID:$value:$status:$currentTime");

InsertMetric

Inserts a single metric to InfluxDB by way of Telegraf. Data tags are automatically sanitized.

InsertMetric($Queue, \%Metric)

Options

Queue   -> Thread::Queue handle to send data to insert
Metric  -> Hash reference of:
    measurement     -> Measurement (for example, metrictype_Metric_Type_Name)
    tags            -> A hash reference of:
        host        -> Device Host (DNSName, IPv6, IPv4)
        instance    -> Instance Name
    fields          -> A hash reference of:
        value       -> The value to send
        utilization -> (optional) Utilization of value if a max value is known
    epochTime       -> Epoch time collected. Oracle recommends using the epoch from time() rounded to nearest poll time.

Returns

none

Synopsis

InsertMetric($queue, {
    measurement => $measurement,
    tags        => {
        host     => $host,
        instance => $instanceName
    },
    fields      => {
        value => $value
    },
    epochTime   => $currentTime
 });