# Introduction

Whilst vROps supermetrics are awesome, there are two features that make them even better:

1. Resource entry aliasing
2. Creating condition based supermetrics

The first feature can make complex supermetrics easier to create by allowing a metric to be assigned an alias which can be reused later in the supermetric

The second feature allows logic to be applied to supermetric calculation resulting in the ability to create significantly more complex supermetrics.

The example below shows a supermetric using both of these features

`\${this, metric=cpu|corecount_provisioned} as cpucount>1?\${this, metric=cpu|actual.capacity}/cpucount:\${this, metric=cpu|actual.capacity}`

The cpu|corecount_provisioned metric is assigned an alias of cpucount, and this alias is reused later in the expression. The supermetric also makes use a conditional element to evaluate the number of cores provisioned to the virtual machine and calculating a value based on whether the result is true of false.

The supermetric is determining whether the virtual machine has more than one vCPUs. If it does then a calculation is made for the Mhz per core by dividing the current Mhz size of the virtual machine by the number of cores. If the VM doesn’t have more than one core then the Mhz per core is simply the current Mhz value. This super metric is only given as an example to show the use of aliases and conditional evaluation as the same result could be derived simply by dividing the current Mhz value by the number of cores.

The format of the conditional supermetric is as follows:

`Expression to evaluate ? If true : If false`

Transformation of the result can also be performed once the expression has been evaluated:

`Transformation(Expression to evaluate ? If true : If false)`

To better understand the use of conditionals consider the following examples:

`1+1 > 1 ? 10 : 20 - This would return 10 as 1 + 1 is greater than 1`

A super metric involving a transformative function is as follows:

`avg(2+2>3?[10,15,20]:[20,25,30]) - This would return 15 as this is the average of 10, 15 & 20`

Supermetrics support a number of different means of evaluation which are similar to those found in most programming languages:

 comparator Description > Greater than >= Greater than or equal to <= Less than or equal to < Less than == Equal to != Not equal to

Examples of the different comparators are as follows:

`sum(1+1>=3?[1,2,3]:[4,5,6]) - This would return 15 as 1+1 is not greater than or equal to 3 and the result is the sum of 4+5+6`

`sum(1+1<=3?[1,2,3]:[4,5,6]) - This would return 6 as 1+1 is less than or equal to 3 and the result is the sum of 1+2+3`

`count(1+1==3?[3,5,7]:[1,2,3,4,5,6]) - This would return 6 as 1+1 does not equal 3 and the result is the count of the objects`

`max(1+1!=3?[3,5,7]:[1,2,3,4,5,6]) - This would return 7 as 1+1 does not equal 3 and the result is the maximum value of 3,5 & 7`

The conditional supermetrics can be further enhanced  to include AND & OR statements:

 Logic Description && AND || OR
`1+1==2&&2+2==4?10:20 - This would return 10 as 1+1 does equal 2 and 2+2 does equal 4`

`1+1==2||2+2==5?10:20 - This would also return 10 as the expression is true if either 1+1  equals 2 OR 2+2 equals 5.`

These can also be combined into ever more complex supermetrics:

`1+1==2&&(2+2==4||3+3==7)?25:50 - To return true (and a value of 25), 1+1 must equal 2 AND either 2+2 must equal 4 OR 3+3 must equal 7 - This expression will return true`

The examples shown above all use simple integer based expressions to explain them more easily, but the real power is when these are used with actual metrics:

`\${this, metric=guestfilesystem|capacity_total} as totalcapacity > 200 &&\${this, metric=guestfilesystem|percentage_total} as percentused<95?totalcapacity:((totalcapacity/100)*percentused)+20`

In this example, the total capacity of the guest file system is evaluated to determine whether it is greater than 200GB. Also the disk usage is evaluated to determine whether it is less than 95%. If both conditions are true then the result is the total capacity but if either is false i.e the disk is less than 200GB in size or the usage is greater than 95% then the returned value is equal to the current usage plus 20GB. The result is that a value for all guests is calculated that gives at least 20GB of free space.