当前位置: 首页>>代码示例>>Python>>正文


Python tempodb.Client类代码示例

本文整理汇总了Python中tempodb.Client的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: push

 def push(self, database, series, value):
     """
     Pushes a single value with current timestamp to the given database/series
     """
     try:
         db =  self._databases[database]
         client = Client(db['api_key'], db['api_secret'])
         data = [DataPoint(datetime.now(), float(value))]
         client.write_key(series, data)
         self.last_response = 'OK'
         return True
     except Exception as e:
         self.last_response = e
         return False
开发者ID:xoseperez,项目名称:mqtt2cloud,代码行数:14,代码来源:TempoDB.py

示例2: TempoDBOutput

class TempoDBOutput(Output):
    def __init__(self, **tempo_kwargs):
        self.client = Client(**tempo_kwargs)

    def __repr__(self):
        return '<%s>' % self.__class__.__name__

    def send(self, key, value):
        if isinstance(value, bool):
            value = 1 if value else 0

        self.client.write_key(
            key,
            [DataPoint(datetime.now(), value)]
        )
开发者ID:BrianHicks,项目名称:probe,代码行数:15,代码来源:outputs.py

示例3: import_samples

def import_samples():
	sin = [math.sin(math.radians(d)) for d in range(0,3600)]
	cos = [math.cos(math.radians(d)) for d in range(0,3600)]

	sin_data = []
	cos_data = []
	start_time = datetime.datetime(2013,07,26)
	for i in range(len(sin)):
		current_time =  start_time + datetime.timedelta(minutes=i)
		sin_data.append(DataPoint(current_time, sin[i]))
		cos_data.append(DataPoint(current_time, cos[i]))

	client = Client(API_KEY, API_SECRET)
	client.write_key('type:trig.function:sin.1',sin_data)
	client.write_key('type:trig.function:cos.1', cos_data)
开发者ID:leonsas,项目名称:DSSG-workshop,代码行数:15,代码来源:sample_code.py

示例4: __init__

    def __init__(self, conf):
        TRUE_VALUES = set(('true', '1', 'yes', 'on', 't', 'y'))
        self.logger = logging.getLogger('statsdpy')
        self.logger.setLevel(logging.INFO)
        self.syslog = SysLogHandler()
        self.formatter = logging.Formatter('%(name)s: %(message)s')
        self.syslog.setFormatter(self.formatter)
        self.logger.addHandler(self.syslog)
        self.conf = conf
        self.graphite_host = conf.get('graphite_host', '127.0.0.1')
        self.graphite_port = int(conf.get('graphite_port', '2003'))
        self.listen_addr = conf.get('listen_addr', '127.0.0.1')
        self.listen_port = int(conf.get('listen_port', 8125))
        self.debug = conf.get('debug', 'yes') in TRUE_VALUES
        self.combined_events = conf.get('combined_events', 'no') in TRUE_VALUES
        self.flush_interval = int(conf.get('flush_interval', 10))
        self.pct_threshold = int(conf.get('percent_threshold', 90))
        self.graphite_addr = (self.graphite_host, self.graphite_port)
        self.keycheck = re.compile(r'\s+|/|[^a-zA-Z_\-0-9\.]')
        self.ratecheck = re.compile('^@([\d\.]+)')
        self.counters = {}
        self.timers = {}
        self.stats_seen = 0

        self.tempodb_enabled = conf.get('tempodb_enabled', 'false') in TRUE_VALUES
        self.tempodb_key = conf.get('tempodb_key', '')
        self.tempodb_secret = conf.get('tempodb_secret', '')
        self.tempodb_host = conf.get('tempodb_host', 'localhost')
        self.tempodb_port = int(conf.get('tempodb_port', 443))
        self.tempodb_secure = conf.get('tempodb_secure', "true") in TRUE_VALUES
        self.tempodb_client = TempoDBClient(self.tempodb_key, self.tempodb_secret, \
                                            self.tempodb_host, self.tempodb_port, \
                                            self.tempodb_secure)
开发者ID:tempodb,项目名称:statsdpy,代码行数:33,代码来源:statsd.py

示例5: read_samples

def read_samples():
	client = Client(API_KEY, API_SECRET)
	start_time = datetime.datetime(2013,07,26)
	end_time = start_time + datetime.timedelta(minutes=3600)
	dataset = client.read_key('type:trig.function:sin.1', start_time, end_time, interval="1min")
	print "Average of sin", round(dataset.summary.mean)
	print "Max of sin", dataset.summary.max


	attributes={
				"function": "sin"
				}

	datasets = client.read(start_time, end_time, attributes=attributes)

	for dset in datasets:
		print "Average of %s" % dset.series.attributes['function'], round(dset.summary.mean)

	attrs={'type':'trig'}
	datasets = client.read(start_time, end_time, attributes=attrs)
	for dset in datasets:
		print "Average of %s" % dset.series.attributes['function'], round(dset.summary.mean)
开发者ID:leonsas,项目名称:DSSG-workshop,代码行数:22,代码来源:sample_code.py

示例6: setUp

 def setUp(self):
     self.client = Client('key', 'secret', 'example.com', 443, True)
     self.client.session = mock.Mock()
     self.headers = {
         'User-Agent': 'tempodb-python/%s' % tempodb.get_version(),
         'Accept-Encoding': 'gzip',
     }
     self.get_headers = self.headers
     self.delete_headers = self.headers
     self.put_headers = dict({
         'Content-Type': 'application/json',
     }, **self.headers)
     self.post_headers = self.put_headers
开发者ID:InPermutation,项目名称:tempodb-python,代码行数:13,代码来源:tests.py

示例7: test_port_defaults

 def test_port_defaults(self):
     """ 80 is the default port for HTTP, 443 is the default for HTTPS """
     client = Client('key', 'secret', 'example.com', 80, False)
     self.assertEqual(client.build_full_url('/etc'), 'http://example.com/v1/etc')
     client = Client('key', 'secret', 'example.com', 88, False)
     self.assertEqual(client.build_full_url('/etc'), 'http://example.com:88/v1/etc')
     client = Client('key', 'secret', 'example.com', 443, False)
     self.assertEqual(client.build_full_url('/etc'), 'http://example.com:443/v1/etc')
     client = Client('key', 'secret', 'example.com', 443, True)
     self.assertEqual(client.build_full_url('/etc'), 'https://example.com/v1/etc')
     client = Client('key', 'secret', 'example.com', 88, True)
     self.assertEqual(client.build_full_url('/etc'), 'https://example.com:88/v1/etc')
     client = Client('key', 'secret', 'example.com', 80, True)
     self.assertEqual(client.build_full_url('/etc'), 'https://example.com:80/v1/etc')
开发者ID:InPermutation,项目名称:tempodb-python,代码行数:14,代码来源:tests.py

示例8: Client

"""
http://tempo-db.com/api/write-series/#write-series-by-key
"""

import datetime
import random
from tempodb import Client, DataPoint

client = Client('your-api-key', 'your-api-secret')

date = datetime.datetime(2012, 1, 1)

for day in range(1, 10):
    # print out the current day we are sending data for
    print date

    data = []
    # 1440 minutes in one day
    for min in range (1, 1441):
        data.append(DataPoint(date, random.random() * 50.0))
        date = date + datetime.timedelta(minutes=1)

    client.write_key('your-custom-key', data)
开发者ID:blakesmith,项目名称:tempodb-python,代码行数:23,代码来源:tempodb-write-demo.py

示例9: ClientTest

class ClientTest(TestCase):

    def setUp(self):
        self.client = Client('key', 'secret', 'example.com', 443, True)
        self.client.session = mock.Mock()
        self.headers = {
            'User-Agent': 'tempodb-python/%s' % tempodb.get_version(),
            'Accept-Encoding': 'gzip',
        }
        self.get_headers = self.headers
        self.delete_headers = self.headers
        self.put_headers = dict({
            'Content-Type': 'application/json',
        }, **self.headers)
        self.post_headers = self.put_headers

    def test_init(self):
        client = Client('key', 'secret', 'example.com', 80, False)
        self.assertEqual(client.key, 'key')
        self.assertEqual(client.secret, 'secret')
        self.assertEqual(client.host, 'example.com')
        self.assertEqual(client.port, 80)
        self.assertEqual(client.secure, False)

    def test_defaults(self):
        client = Client('key', 'secret')
        self.assertEqual(client.host, 'api.tempo-db.com')
        self.assertEqual(client.port, 443)
        self.assertEqual(client.secure, True)

    def test_port_defaults(self):
        """ 80 is the default port for HTTP, 443 is the default for HTTPS """
        client = Client('key', 'secret', 'example.com', 80, False)
        self.assertEqual(client.build_full_url('/etc'), 'http://example.com/v1/etc')
        client = Client('key', 'secret', 'example.com', 88, False)
        self.assertEqual(client.build_full_url('/etc'), 'http://example.com:88/v1/etc')
        client = Client('key', 'secret', 'example.com', 443, False)
        self.assertEqual(client.build_full_url('/etc'), 'http://example.com:443/v1/etc')
        client = Client('key', 'secret', 'example.com', 443, True)
        self.assertEqual(client.build_full_url('/etc'), 'https://example.com/v1/etc')
        client = Client('key', 'secret', 'example.com', 88, True)
        self.assertEqual(client.build_full_url('/etc'), 'https://example.com:88/v1/etc')
        client = Client('key', 'secret', 'example.com', 80, True)
        self.assertEqual(client.build_full_url('/etc'), 'https://example.com:80/v1/etc')

    def test_get_series(self):
        self.client.session.get.return_value = MockResponse(200, """[{
            "id": "id",
            "key": "key",
            "name": "name",
            "tags": ["tag1", "tag2"],
            "attributes": {"key1": "value1"}
        }]""")

        series = self.client.get_series()
        self.client.session.get.assert_called_once_with(
            'https://example.com/v1/series/',
            auth=('key', 'secret'),
            headers=self.get_headers
        )
        expected = [Series('id', 'key', 'name', {'key1': 'value1'}, ['tag1', 'tag2'])]
        self.assertEqual(series, expected)

    def test_create_series(self):
        self.client.session.post.return_value = MockResponse(200, """{
            "id": "id",
            "key": "my-key.tag1.1",
            "name": "",
            "tags": ["my-key", "tag1"],
            "attributes": {}
        }""")
        series = self.client.create_series("my-key.tag1.1")

        self.client.session.post.assert_called_once_with(
            'https://example.com/v1/series/',
            data="""{"key": "my-key.tag1.1"}""",
            auth=('key', 'secret'),
            headers=self.post_headers
        )
        expected = Series('id', 'my-key.tag1.1', '', {}, ['my-key', 'tag1'])
        self.assertEqual(series, expected)

    def test_create_series_validity_error(self):
        with self.assertRaises(ValueError):
            series = self.client.create_series('key.b%^.test')

    def test_update_series(self):
        update = Series('id', 'key', 'name', {'key1': 'value1'}, ['tag1'])
        self.client.session.put.return_value = MockResponse(200, simplejson.dumps(update.to_json()))

        updated = self.client.update_series(update)

        self.client.session.put.assert_called_once_with(
            'https://example.com/v1/series/id/id/',
            auth=('key', 'secret'),
            data=simplejson.dumps(update.to_json()),
            headers=self.put_headers
        )
        self.assertEqual(update, updated)

#.........这里部分代码省略.........
开发者ID:InPermutation,项目名称:tempodb-python,代码行数:101,代码来源:tests.py

示例10: Client

import pygal
import datetime
import json
from tempodb import Client
from pygal.style import BlueStyle

API_KEY = 'API_KEY'
API_SECRET = 'API_SECRET'
MILES_SERIES_KEY = 'divvy.trip.miles'

client = Client(API_KEY, API_SECRET)

start = datetime.date(2013, 6, 27)
end = start + datetime.timedelta(days=187)

data = client.read_key(MILES_SERIES_KEY, start, end, interval="1day", function="sum")
data_list = []
x_label_list = []
x_label_major_list = []

data_count=0
for datapoint in data.data:

	if data_count%15==0:
		x_label_major_list.append(datapoint.ts.strftime("%b %e, %Y"))
	
	x_label_list.append(datapoint.ts.strftime("%b %e, %Y"))
	data_list.append(datapoint.value)
	data_count = data_count + 1

chart = pygal.Bar(x_label_rotation=40,interpolate='cubic',show_minor_x_labels=False,disable_xml_declaration=True,explicit_size=True,style=BlueStyle)
开发者ID:drewdepriest,项目名称:DivvyDataChallenge,代码行数:31,代码来源:pygal-tempo-daily-miles.py

示例11: Client

"""
http://tempo-db.com/api/write-series/#bulk-write-multiple-series
"""
from __future__ import print_function

import datetime
from tempodb import Client

# Modify these with your credentials found at: http://tempo-db.com/manage/
API_KEY = 'your-api-key'
API_SECRET = 'your-api-secret'
SERIES_KEY = 'your-custom-key'

client = Client(API_KEY, API_SECRET)

ts = datetime.datetime.now()
data = [
    { 'key': 'custom-series-key1', 'v': 1.11 },
    { 'key': 'custom-series-key2', 'v': 2.22 },
    { 'key': 'custom-series-key3', 'v': 3.33 },
    { 'key': 'custom-series-key4', 'v': 4.44 },
]

print(client.write_bulk(ts, data))
开发者ID:ixmatus,项目名称:tempodb-python,代码行数:24,代码来源:tempodb-bulk-write-demo.py

示例12: Client

"""
http://tempo-db.com/api/write-series/#write-series-by-key
"""

import datetime
import random
from tempodb import Client, DataPoint

# Modify these with your credentials found at: http://tempo-db.com/manage/
API_KEY = '680d1adbbb0c42a398b5846c8e1517dd'
API_SECRET = 'f2db65d178634a36b4c25467f8bc2099'
SERIES_KEY = 'your-custom-key'

client = Client(API_KEY, API_SECRET)

date = datetime.datetime(2012, 1, 1)

for day in range(1, 10):
    # print out the current day we are sending data for
    print date

    data = []
    # 1440 minutes in one day
    for min in range (1, 1441):
        data.append(DataPoint(date, random.random() * 50.0))
        date = date + datetime.timedelta(minutes=1)

    client.write_key(SERIES_KEY, data)
开发者ID:daiyoko,项目名称:LotteryPrediction,代码行数:28,代码来源:tempodb-write-demo.py

示例13: Client

import serial
import math
import datetime
import random
from tempodb import Client, DataPoint

POTENTIAL_DIVIDER_RESISTOR = 10000
THERMISTOR_B_VALUE = 3977
THERMISTOR_REF_TEMP = 298.15
THERMISTOR_REF_RESISTANCE = 10000

client = Client('cc0c654d01774b128c1e0495de51784b', 'a280c43f6b27400998a4aba0b1eb4545')

def calculate_temp(value):
    voltage = float(value) / 1024 * 5
    resistance = POTENTIAL_DIVIDER_RESISTOR / (5 / voltage - 1)
    temp = 1 / (1/THERMISTOR_REF_TEMP + math.log(resistance / THERMISTOR_REF_RESISTANCE) / THERMISTOR_B_VALUE)
    print "Temperature is: %f K, (%f degC)" % (temp, temp-273.15)
    return temp-273.15

ser = serial.Serial('/dev/tty.usbserial-A800etDk', 9600)
temperature_array = []
while 1:
    r = ser.readline()
    split = r.split(",")
    if(len(split) == 3):
        # Deal with the temperature pin first
        value = split[0].strip()
        temp = calculate_temp(value)
        temperature_array.append(temp)
        if(len(temperature_array) >= 20):
开发者ID:Poopi,项目名称:conair,代码行数:31,代码来源:conair.py

示例14: Client

from tempodb import Client, DataPoint

client = Client('40349331c03d4d4e9c544f812af291a9', 'f6e1594584a74f28ae00a872cd179462')

for id in range(1,33):
    station='station_'+str(id).zfill(2)
    series = client.create_series(station)
开发者ID:batic,项目名称:bicike-lj,代码行数:7,代码来源:delete_series.py

示例15: __init__

 def __init__(self, **tempo_kwargs):
     self.client = Client(**tempo_kwargs)
开发者ID:BrianHicks,项目名称:probe,代码行数:2,代码来源:outputs.py


注:本文中的tempodb.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。