#!/usr/bin/python # -*- coding: utf-8 -*- from .basestorage import BaseStorage import json import logging import requests class DashingClient: base_url = None def __init__(self, base_url, auth_token): self.base_url = base_url self.auth_token = auth_token self.logger = logging.getLogger('dashing') def __str__(self): return 'Dashing at \'{0}\''.format(self.base_url) def send(self, metric, current, previous=None): info = { 'auth_token': self.auth_token, 'current': int(current), } if previous is not None: info['previous'] = previous url = self.base_url + metric resp = requests.post(url, data=json.dumps(info)).read() self.logger.debug('Sent metric "{0}" = "{1}"'.format(metric, current)) return resp def push(self, storage): if not isinstance(storage, BaseStorage): self.logger.error('Mimimi, storage is not a BaseStorage.') return status = storage.status # {akt,max}{Knoten,Client}count self.send('aktKnotencount', status['nodes_active']) self.send('aktClientcount', status['clients_unique']) # aktTraffic (mit Historie ?!) # evtl. Liste der letzten Knoten, die dazukamen if __name__ == "__main__": client = DashingClient( 'http://dashing.krombel.de:3030/widgets/', 'bitnhmlj47hamrftxkiug') client.send('testNumber', 42)