santoshannie
Contributor
Contributor

I need help with script for getting back dated information for eg : 1st Jan to 31st Jan . For CPU , Ram and Storage for billing purpose . I used below sript for storage

# Connect to vcenter

connect-viserver "VC01";

# Create an empty array

$table = @();

# Get all VMs

$vms = get-vm | sort name;

# Loop through each VM

foreach ($vm in $vms) {

    # Get hard disks

    $harddisks = $vm | get-harddisk | sort name;

    # Loop through each disk in each VM

    foreach ($harddisk in $harddisks) {

        # Create an empty row       

        $row = "" | select name, harddiskname, datastore, vmdkpath, vmdkused, vmdkallocated;

        $row.name = $vm.name;

        $row.harddiskname = $harddisk.name;

        $row.datastore = $harddisk.filename.split("]")[0].trimstart("[");

        $row.vmdkpath = $harddisk.FileName;

        $row.vmdkused = [int](($vm.extensiondata.layoutex.file| where {$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB);

        $row.vmdkallocated = [int]$harddisk.capacitygb;

        # Add row to array

        $table = $table + $row;     

    }

}

 

# Export array to CSV

$table | export-csv c:\temp\vmdisks.csv;

0 Kudos
6 Replies
LucD
Leadership
Leadership

Not sure what you are actually asking.

For billing purposes, I would expect a script to look at the usage over the time period, not just at the current situation.

Which is what you seem to be doing for storage.

Shouldn't you be looking at the resource consumption over the time interval?

That would mean looking at performance data over the time interval via the Get-Stat cmdlet.

If yes, the next question is what kind of metric you would be using for your billing.

Is that the average usage?

Which could mean that an over-dimensioned VM is charged less than a correctly dimensioned VM?

If you need help with your script, you will first have to determine a few basic concepts for yourself on billing and how it is done.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
santoshannie
Contributor
Contributor

Thanks LucD , I only require information for CPU , Ram and Storage for Month 1stJan to 31st Jan . We dont bill as per current usage . for eg customer is using 2VCPu and 4GB ram and 500GB harddisk , we bill it directly .

0 Kudos
LucD
Leadership
Leadership

But what exactly do you want?

The average CPU, memory and storage over the month?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
santoshannie
Contributor
Contributor

Hi LucD ,

I need information like this below :

1] VMname

2] CPU

3] RAM

4] Storage

5] Datastore Name for Jan month .

Regards,
Santosh Dalvi

0 Kudos
LucD
Leadership
Leadership

I understand that, but how would you calculate the values for CPU, RAM and storage?

Are these averages over the month?
And what about the Datastore.

Is that the space the VM takes on one datastore?

At the end of the mont

Is there only 1 datastore in use per VM?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
santoshannie
Contributor
Contributor

Hi LucD ,

Allicated CPU , Allocated RAM and VM disk is split into C drive ( Gold) and D drive (platinum) . Below is the output i get from VRA but i dont get historical data from IAAS database and vm shows only one storage path .

Regards,
Santosh Dalvi

pastedImage_0.png

0 Kudos