What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Can I monitor AWS Costs with PRTG

Votes:

0

I want to monitor how much my Consolidated Billing AWS infrastructure costs with PRTG. How can I do this?

amazon aws cloud consolidated-billing cost custom-script-exe custom-sensor powershell

Created on Feb 10, 2016 1:00:00 PM by  Greg Campion [Paessler Support]

Last change on Feb 2, 2017 3:24:41 PM by  Martina Wittmann [Paessler Support]



3 Replies

Accepted Answer

Votes:

0


Important notice: As of PRTG 20.1.56, you can use the native AWS Cost sensor to monitor the costs of an Amazon Web Services (AWS) account with PRTG.


This article applies as of PRTG 14

AWS Costs Sensor

With the following script, you can use PRTG to find out how much AWS is charging you for your AWS Cloud infrastructure.

Notes

  • You have to have the AWS Tools for Windows PowerShell installed on the probe running this sensor
  • The probe service must be allowed to copy data to the directory defined in the $localPath variable
  • I would not recommend running this sensor more than twice a day.
  • The parameters "-accesskey, -secretkey, -bucket, -localpath" must be set in the settings for this sensor or in the script itself for it to work but you can use some of the placeholders defined in the API under Custom Sensors to fill them out.
  • In your AWS account you have to set up Billing Reports and have them sent to the bucket defined in this script.
  • The amount of lines that are parsed out of the CSV in the Get-Content command (Line 35) depends on the amount of accounts you have in AWS. You will likely have to turn on billing reports and download one to see which lines are needed for the sensor.
param(
# Your account access key - must have read access to your S3 Bucket
$accessKey,
# Your account secret access key
$secretKey,
# The name of your S3 Bucket
$bucket,
# The folder in your bucket to copy, including trailing slash. Leave blank to copy the entire bucket
$keyPrefix,
# The local file path where files should be copied
$localPath = "C:\temp\"
)

#Get all objects from billing bucket
$objects = Get-S3Object -BucketName $bucket -KeyPrefix $keyPrefix -AccessKey $accessKey -SecretKey $secretKey -Region $region 

#Find the newest billing CSV Data
foreach($object in $objects) {
	$changedate = $object.LastModified
    $name = $object.Key
	if ($name -like  "*aws-billing-csv*" -and $changedate -gt (Get-Date).AddDays(-2)) {
		$billingdoc = $object.key
        Copy-S3Object -BucketName $bucket -Key $billingdoc -LocalFile "$localPath$billingdoc" -AccessKey $accessKey -SecretKey $secretKey -Region $region
	}
}



#Setup paths for temp data
$csvPath = $localPath + $billingdoc
$pscsvPath = $localPath + 'aws-billing.csv'

#Parse the lines necessary from the billing statements.  The number of lines depends on the number of accounts associated with the account
Get-Content -Path $csvPath | Select -First 1 | Out-File $pscsvPath
Get-Content -Path $csvPath | select -Last 9 | Out-File $pscsvPath -Append
#Import the newly created parsed CSV
$invoice = import-csv  -Path $pscsvPath | Where-Object {$_.TotalCost -ne ""}
$date = Get-Date

#Write the data for each account into PRTG
Write-Host "<prtg>"

foreach ($record in $invoice){
    [int]$total = $record.TotalCost
    $channelname = $record.LinkedAccountName
        IF([string]::IsNullOrEmpty($channelname)) {
            $channelname = $record.RecordType
            }

    write-host 
            "<result>
<channel>$channelname</channel>
<Unit>Custom</Unit>
<CustomUnit>$</CustomUnit>
<value>$total</value>
</result>"
    }
    write-host "<text>AWS Costs as of $date</text>
</prtg>"

Created on Feb 11, 2016 1:03:11 PM by  Greg Campion [Paessler Support]

Last change on Feb 27, 2020 12:36:50 PM by  Maike Guba [Paessler Support] (2,404) 2 1



Votes:

0

Greg,

What bucket is this referring to?

# The name of your S3 Bucket $bucket

Created on Apr 10, 2018 7:49:17 PM



Votes:

0

Hi there,

As the comment says, it is the name of the S3 bucket. :)
Or could you specify the question?

Best regards.

Created on Apr 11, 2018 10:50:31 AM by  Dariusz Gorka [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.