Data

Description

Metrics data module to provide common handler functions used by threaded apps to save, manage metric data

Synopsis

use Assure1::Metrics::Data;

Functions

CreateMeasurement

Create Influx Measurement hash for passing to InsertMetricWorker. Data tags are not automatically sanitized and Metrics::SanitizeInfluxTag() should be used 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 (e.g. metrictype_Metric_Type_Name)
status      -> (optional) Availability of metric. Boolean, when true store value and utilization if defined
value       -> Metric value
utilization -> (optional) Calculated utilization for measurement
currentTime -> Epoch time collected. Strongly recommend 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

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

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

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 (i.e. $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 via 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 (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

Returns

none

Synopsis

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