Browse Source

convert+integrate Dashing adapter

Helge Jung 9 years ago
parent
commit
06d1d35352
4 changed files with 14 additions and 5 deletions
  1. 1 1
      Readme.md
  2. 2 1
      ffstatus/__init__.py
  3. 9 3
      ffstatus/dashing.py
  4. 2 0
      status-daemon.py

+ 1 - 1
Readme.md

@@ -15,7 +15,7 @@ Die Daten werden aggregiert und können anschließend an mehrere Datensenken wei
 ## Installation
 
 ```
-sudo apt-get install python-daemon
+sudo apt-get install python-daemon python-requests
 sudo ln -s "`pwd`/contrib/init-script.sh" /etc/init.d/ffstatus
 echo "DAEMON_DIR=`pwd`" | sudo tee -a /etc/default/ffstatus
 sudo update-rc.d ffstatus defaults

+ 2 - 1
ffstatus/__init__.py

@@ -1,9 +1,10 @@
 from copy import deepcopy
 
 from .alfred import AlfredParser
+from .dashing import DashingClient
 from .graphite import GraphitePush
 
-__all__ = [ 'AlfredParser', 'GraphitePush', 'dict_merge' ]
+__all__ = [ 'AlfredParser', 'DashingClient', 'GraphitePush', 'dict_merge' ]
 
 def dict_merge(a, b):
     '''recursively merges dict's. not just simple a['key'] = b['key'], if

+ 9 - 3
dashing-interface.py → ffstatus/dashing.py

@@ -1,16 +1,18 @@
 #!/usr/bin/python
 
 import json
+import logging
 import requests
 
-class DashingAdapter:
+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 send(self, metric, current, previous=None, blubb=None, bla=None):
+	def send(self, metric, current, previous=None):
 		info = {
 			'auth_token': self.auth_token,
 			'current': int(current),
@@ -20,9 +22,13 @@ class DashingAdapter:
 
 		url = self.base_url + metric
 		r = requests.post(url, data=json.dumps(info))
+		self.logger.debug('Sent metric "{0}" = "{1}"'.format(metric, current))
 		return r
 
+	def push(self, data):
+		self.logger.warn('push() not implemented yet')
+
 if __name__ == "__main__":
-	d = DashingAdapter('http://dashing.krombel.de:3030/widgets/', 'bitnhmlj47hamrftxkiug')
+	d = DashingClient('http://dashing.krombel.de:3030/widgets/', 'bitnhmlj47hamrftxkiug')
 	d.send('testNumber', 42)
 

+ 2 - 0
status-daemon.py

@@ -22,6 +22,7 @@ logger.addHandler(fh)
 logger.info('Starting up')
 
 a = AlfredParser()
+d = DashingClient('dashing.krombel.de', 'TODO')
 g = GraphitePush('fdca:ffee:ff12:a254::da7a', 2003)
 data = { }
 
@@ -49,6 +50,7 @@ with daemon_context:
 
 			logger.debug('Step 2/3: Pushing update data ...')
 			graphitedata = g.push(newdata, ts=ts)
+			d.push(newdata)
 
 			logger.info('Sent ' + str(graphitedata.count('\n')+1) + ' lines to Graphite.')