Note: If you cannot find a topic, go to docs.rightscale.com where all RightScale documentation will soon be located. Also, feel free to Chat with us!
Home > Partners > Documents for Partners > ISV Metering > Creating Custom Metering Reports

Creating Custom Metering Reports

 

 icon-Beta-v1.png  Service-level response times are the same as for general-release features. Although this new feature/technology has undergone significant testing and is not expected to change significantly prior to general release, the use of this feature/technology is not recommended for production environments. You are encouraged to use this feature/technology for development and testing purposes only. 

Objective

To send custom metering data to the RightScale system so that you can generate reports (by customer) for billing purposes.  Custom metrics will be displayed as additional columns in the metering reports.  Each ISV account can add up to two (2) custom metrics.

Steps

  1. Calculate up to two (2) custom metrics elsewhere in your application.
    • Metrics are comprised of a string, the 'label', and an integer
    • The values or quantity key(s) can contain any alpha, numeric, space, and forward-slash character.   Special characters may become supported in future releases.
  2. Send these metrics to RightScale using our 'set_custom_lodgement' API call.  (See the PHP example code provided below.)
    • Send the latest total - RightScale will not sum the data for the month or day that you are updating.
    • RightScale will, however, aggregate any daily data into monthly data.  However, you cannot update a previous day's or a previous month's data.
  3. View this data in the Dashboard under Reports -> Customer Usage as separate columns.
    • You must be enabled as an ISV account with 'admin' role privileges to see this report.  Please contact us at sales@rightscale.com if you do not see this menu item.
    • You will only be able to see customer names and contact information for those ServerTemplates that you have shared through a private sharing group.  Otherwise, customer info will not be shown.  So, if you've published your ServerTemplate to the community and it can be found in the MultiCloud Marketplace, you will not see associated customer names and contact information.

Example Code

<?php
/**** SEND CUSTOM USAGE DATA TO RIGHTSCALE ****/
$custom_metric1 = 0; // Your custom metrics are calculated elsewhere
$custom_metric2 = 0; // They must be integers

/** Construct API URL using RightScale environment **/
$api_url = `source /var/spool/ec2/user-data.sh; env | grep RS_API_URL`;
$uri = split("=",$api_url);
$uri = trim($uri[1]) . "/set_custom_lodgement"; // The API call to send custom data

/** Set Period and Usage Data **/
// Set the time to current month or day in format YYYY_MM or YYYY_MM_DD
// Note that any previous value for that time will be overwritten
// Day values are automatically aggregated into month values by RightScale
$time = date('Y_m_d'); // return current date in format YYYY_MM_DD (Ex: '2010_08_27')
//$time = date('Y_m'); // return current date in format YYYY_MM (Ex: '2010_08')
// Set both the label for the custom metric and the actual usage
$quantity = '{"MB/s":'.$custom_metric1.',"DB Size":'.$custom_metric2.'}';
 
$ch = curl_init($uri);
$encoded = '';
$encoded .= urlencode('api_version').'='.urlencode('1.0').'&';
$encoded .= urlencode('time').'='.urlencode($time).'&';
$encoded .= urlencode('quantity').'='.urlencode($quantity);

curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_exec($ch);
curl_close($ch);

?>  
Curl Example
curl -H 'X-API-VERSION:1.0' -d api_version='1.0' -d time='2010_11_18' -d quantity='{"custom_metric":1}' -X PUT https://my.rightscale.com/api/inst/ec2_instances/$APITOKEN/set_custom_lodgement
Create a Cron Job

On Linux instances, this bash command will create an hourly cron job to execute the lodgements script at /root/rs_lodgements.php

echo "* */1 * * * root php -e /root/rs_lodgements.php >> /var/log/rs_lodgements.log 2>&1" > /etc/cron.d/rs_lodgements

You must to post a comment.
Last modified
23:39, 16 May 2013

Tags

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.