123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- 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):
- status = storage.status
- # {akt,max}{Knoten,Client}count
- self.send('aktKnoten', status['nodes_active'])
- self.send('aktClient', 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)
|