def __init__(self, name, value, collection_time=None, ttl_seconds=None, unit=None): """ Inits the datapoint @param name - String name of the metric @param value - Value of the metric @param collection_time - Time of collection @param ttl_seconds - Number of seconds for datapoint to live @param unit - String unit of the metric """ self['metricValue'] = value self['metricName'] = name if collection_time is None: self.logger.debug("No collection time provided. Generating now") collection_time = utils.time_in_ms() self['collectionTime'] = collection_time # Set ttl if not ttl_seconds: ttl_seconds = 60 * 60 * 24 * 180 ttl_seconds = max(ttl_seconds, 0) self['ttlInSeconds'] = ttl_seconds # Set units if unit: self['unit'] = unit self.logger.debug("Created datapoint:\n%s" % pprint.pformat(self))
from client import Blueflood, Datapoint from utils import time_in_ms import pprint auth_url = 'https://identity.api.rackspacecloud.com/v2.0/' apikey = '0e688a460988337e0e759524a2ccfc33' username = '******' client = Blueflood(auth_url=auth_url, apikey=apikey, username="******") point = { 'collectionTime': 1442262994835, 'metricName': 'james.test.number', 'metricValue': 55, 'ttlInSeconds': 3600 } #point = Datapoint('intel.suda-devstack-dfw.Threads_created', 55, collection_time=1442262994835, ttl_seconds=3600) print "Ingesting" client.ingest(point) print "Getting" resp = client.get_metrics(0, time_in_ms(), ['james.test.number'], points=100) pprint.pprint(resp)