Usage & Metering
The usage.dataTransfer(start, end, detail) method allows you to retrieve data regarding the volume of data transfer to Watson IoT Platfrom in your organization.
Viewing Summary Data
By setting detail=False (or omitting the parameter entirely) the response will provide a month by month breakdown of your data transfer:
import wiotp.sdk.application
options = wiotp.sdk.application.parseEnvVars()
appClient = wiotp.sdk.application.ApplicationClient(options)
dataTransfer = appClient.usage.dataTransfer(datetime.today() - timedelta(days=10), datetime.today())
print("Time period = %s to %s" % (dataTransfer.start.isoformat(), dataTransfer.end.isoformat()))
print("- Average usage = %s" % (dataTransfer.average))
print("- Total usage = %s" % (dataTransfer.total))
Getting Detailed Breakdown of Data Transfer
In setting detail=True the response will additionally provide a day by day breakdown of data transfer.
import wiotp.sdk.application
options = wiotp.sdk.application.parseEnvVars()
appClient = wiotp.sdk.application.ApplicationClient(options)
dataTransfer = appClient.usage.dataTransfer(datetime.today() - timedelta(days=10), datetime.today(), True)
print("Time period = %s to %s" % (dataTransfer.start.isoformat(), dataTransfer.end.isoformat()))
print("- Average usage = %s bytes" % (dataTransfer.average))
print("- Total usage = %s bytes" % (dataTransfer.total))
for day in dataTransfer.days:
print(" * Usage on %s = %s bytes" % (day.date.isoformat(), day.total) )
Handling DataTransferSummary and DayDataTransfer data
The wiotp.sdk.api.usage.DataTransferSummary and wiotp.sdk.api.usage.DayDataTransfer classes provide an easy way to work with the data that is returned by the usage API. wiotp.sdk.api.usage.DataTransferSummary is the top level container and provides the following properties:
startThe start date for the summary report (datetime.date)endThe end date for the summary report (datetime.date)averageThe average usage across the summary periodtotalThe total usage across the summary perioddaysIfdetail=Truethen this will be a list ofDayDataTransferobjects
The wiotp.sdk.api.usage.DayDataTransfer allows you to work with the day by day breakdown of data usage, exposing the following properties:
dateThe day that usage is being reported for (datetime.date)totalThe total usage on this day