Skip to content

Calculations

Calculations is a standard configuration interface to define the handling of the Meta Metrics defined in the Collections interface. These Meta Metrics use Perl-syntax code to do special processing on the metric data. An example of a meta-metric is the creation of a total inbound bandwidth metric, where the metric data for all inbound interfaces is summed up and saved as a separate metric.

Configuration -> Metrics -> Collections

Refer to the Standard Configuration Interface guide for details on interacting with the grid and form.

This user interface calls REST methods from api/metric/calculations.

The UI path for this interface is Configuration -> Metrics -> Calculations.

Form Fields

  • Name - The name of the calculation.

  • Description - The description of the calculation.

  • Status - The state of the calculation.

  • Collections - The collections selected here will have the metrics retrieved and be processed by the calculation.

  • Policy - The Perl based processing logic of the calculation.

Policy Code Toolbar

  • Line Numbers - Toggle on/off line numbers.

  • Check Syntax - Run Perl syntax checking on content

  • Search - Search code.

  • Previous - Previous result for current search.

  • Next - Next result for current search.

  • Replace One - Search and replace code.

  • Replace All - Search and replace all in code.

Meta

Default Calculations

  • Total Bandwidth Consolidation

    $Log->Message('INFO', " -> Total Interface Bandwidth -> Log Received Data:\n" . Dumper($Data) . "\n-------------------\n");
    
    # This is an example consolidation policy.  It consolidates the bandwidth on all interfaces on
    # a device into a single MetricType called "Interface Total Bandwidth".
    
    my $DBH = undef;
    my $MetricTypeID = FindMetricTypeID({
        DBH           => \$DBH,
        StorageHash   => $MetricHash,
        Name          => "Interface Total Bandwidth",
        FormatID      => 1,
        Direction     => 0,
        Unit          => "Bits Per Second",
        UnitDivision  => 1000,
        Abbreviation  => "b/s",
        TopNTypeID    => 0,
        TopNScopeID   => 0,
        MetricGroupID => 1,
        MaxDefault    => 0,
        Create        => 1
    });
    
    my $InstanceName = $Data->{Collection}->{Name};
    my $CollectionID = $Data->{Collection}->{ID};
    my $DeviceID     = 0;
    my $InstanceID   = 0;
    my $MetricID     = 0;
    my $PollInterval = 0;
    my $Value        = 0;
    my $Maximum      = 0;
    my $Status       = 0;
    my $PolledTime   = 0;
    my $Measurement;
    my $DeviceHost;
    my $DeviceZoneID;
    my $Error;
    
    foreach my $MetricID (keys %{$Data->{'Metrics'}}) {
        # Exclude 0 Max and unavailable metrics
        if ((int($Data->{Metrics}->{$MetricID}->{Maximum}) > 0) && (int($Data->{Metrics}->{$MetricID}->{State}) > 0)) {
            $Value       += $Data->{Metrics}->{$MetricID}->{Value};
            $Maximum     += $Data->{Metrics}->{$MetricID}->{Maximum};
            $DeviceID     = $Data->{Metrics}->{$MetricID}->{DeviceID};
            $PollInterval = $Data->{Metrics}->{$MetricID}->{PollTime};
            $PolledTime   = $Data->{Metrics}->{$MetricID}->{Time}; 
            $Measurement  = $Data->{Metrics}->{$MetricID}->{Measurement};
            $DeviceHost   = $Data->{Metrics}->{$MetricID}->{DeviceHost};
            $DeviceZoneID = $Data->{Metrics}->{$MetricID}->{DeviceZoneID};
            $Status       = 1;
        }
    }
    #make name of meta metrictype / measurement be the name here and look fine
    $Measurement = "Interface Total Bandwidth";
    $Measurement =~ s/\s+/_/g;
    $Measurement= 'metrictype_' . $Measurement;
    # DeviceID set based on metrics
    if (int($DeviceID) == 0) {
        $Log->Message('ERROR', " -> Total Interface Bandwidth -> Missing DeviceID for Collection [$InstanceName].");
    }
    else {
        # Find InstanceID
        $InstanceID = FindInstanceID({
            DBH         => \$DBH,
            StorageHash => $MetricHash,
            Name        => $InstanceName,
            DeviceID    => $DeviceID,
            TypeID      => 0,
            Create      => 1
        });
    
        if (int($InstanceID) == 0) {
            $Log->Message('ERROR', " -> Total Interface Bandwidth -> Missing InstanceID for Collection [$InstanceName] on DeviceID=[$DeviceID].");
        }
        else {
            # Find MetricID
            $MetricID = FindMetricID({
                DBH          => \$DBH,
                StorageHash  => $MetricHash,
                DeviceID     => $DeviceID,
                InstanceID   => $InstanceID,
                MetricTypeID => $MetricTypeID,
                Factor       => 1,
                Max          => $Maximum,
                PollInterval => $PollInterval,
                Create       => 1
            });
    
            my $ShardID = FindShardID({
                    DBH         => \$DBH,
                    StorageHash => $MetricHash,
                    DeviceID    => $DeviceID
            });
    
            if (int($MetricID) > 0) {
                # Store Metric Value / Measurement
                my $tags = {
                    host     => $DeviceHost,
                    instance => $InstanceName
                };
    
                if (defined $ShardID && $ShardID > 1) {
                    $tags->{shard} = $ShardID;
                }
    
                if (defined $DeviceZoneID && $DeviceZoneID > 1) {
                    $tags->{zone} = $DeviceZoneID;
                }
                $DataQueue->enqueue({
                        measurement      => $Measurement,
                        tags             => $tags,
                        fields           => {
                            value        => $Value,
                            availability => $Status
                        },
                        epochTime        => $PolledTime
                });
            }
        }
    }