Permalink
Browse files

Plain Text and JSON accepted from collectd based on the content-type …

…header
  • Loading branch information...
rgaiser committed Nov 1, 2010
1 parent 61f5bff commit f46b698625b9847fa334ab5a458e406ae6aabfea
Showing with 41 additions and 12 deletions.
  1. +28 −6 README.collectd
  2. +13 −6 restmq/collectd.py
View
@@ -1,4 +1,4 @@
-Collectd REST Endpoint
+collectd REST Endpoint
======================
Now RestMQ has a collectd rest endpoint to receive and queue messages from collectd and collectd_web
@@ -9,29 +9,51 @@ This is an specialization of RestMQ, that shows how flexible and easy the intern
The collectd entrypoint does a vaery simple and basic validation of the data send by the collectd daemon.
-* Collectd Configuration:
+* collectd Configuration:
** Data collection:
+ RestMQ collectd entrypoint will decide which format to parse based on the 'Content-type' sent by the client.
+
+ * Plain Text
+
Use the write_http(http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_write_http) bundled with collectd to pass
- data to the RestMQ server using the Plain Text Protocol (http://collectd.org/wiki/index.php/Plain_text_protocol), I found the JSON
- generated by Collectd a little bit confusing, so the collectd endpoint has a parser for the Plain Text Protocol and creates a
- more friendly JSON with the data to insert in the RestMQ Queue:
+ data to the RestMQ server using the Plain Text Protocol (http://collectd.org/wiki/index.php/Plain_text_protocol), RestMQ will
+ generated a JSON with the data to be inserted on the RestMQ Queue:
collectd.conf:
...
<Plugin write_http>
<URL "http://<collectd_restmq_server>/collectd/data">
Format Command
# User "collectd"
- # Password "yerpass"
+ # Password "weCh3ik0"
</URL>
</Plugin>
Example JSON inserted in the RestMQ:
[{"host": "collectd_restmq_server", "type_instance": "df-boot", "plugin_instance": "df", "value": "1288548767:116497408.000000:391246848.000000", "interval": "10"}]
+ * JSON Generated by collectd
+
+ Use the write_http(http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_write_http) bundled with collectd to pass
+ data to the RestMQ server using the the JSON generated by collectd, the collectd endpoint just insert the data in the RestMQ Queue:
+
+ collectd.conf:
+ ...
+ <Plugin write_http>
+ <URL "http://<collectd_restmq_server>/collectd/data">
+ Format JSON
+ # User "collectd"
+ # Password "yerpass"
+ </URL>
+ </Plugin>
+
+ Example JSON inserted in the RestMQ:
+
+ [{"values":[1.16497e+08,3.91247e+08],"time":1288625884,"interval":10,"host":"collectd_restmq_server","plugin":"df","plugin_instance":"","type":"df","type_instance":"boot"}]
+
** Event collection:
Since the write_http is not yet used for events, you need to create a simple script using CURL to send events to the RestMQ server
View
@@ -21,13 +21,20 @@ def post(self, queue):
if value is None:
raise cyclone.web.HTTPError(400)
if queue == 'data':
+ content_type = self.request.headers.get('Content-Type')
queue = 'collectd_data'
- try:
- value = value.splitlines()
- value = self.collectd_plaintext_parser(value)
- value = simplejson.dumps(value)
- except Exception, e:
- log.msg("ERROR: %s" % e)
+ if content_type == 'text/plain':
+ try:
+ value = value.splitlines()
+ value = self.collectd_plaintext_parser(value)
+ value = simplejson.dumps(value)
+ except Exception, e:
+ log.msg("ERROR: %s" % e)
+ raise cyclone.web.HTTPError(503)
+ elif content_type == 'application/json':
+ pass
+ else:
+ log.msg("ERROR: Content-Type not expected %s" % content_type)
raise cyclone.web.HTTPError(503)
elif queue == 'event':
queue = 'collectd_event'

0 comments on commit f46b698

Please sign in to comment.