Package: django-collectd-rest
django-collectd-restdjango-collectd-rest is a simpleDjangoapplication to demonstrate RRD plots generated bycollectdor any otherrrddata. The application is built on top ofdjango-rest-frameworkand provides REST API to access the plots.There are two major things in django-collectd-rest,graphsare grouped intogroups. Both the graphs and the groups are accessible through REST API. Using mutable access (POST, PUT, DELETE), you can configure you hierarchy, create new graphs or alter existing ones. You also can grab meta-info or ready PNG images by means of GET requests. Genuinerrdtoolis currently used to render the plots.Newly introducedgranularityobject is a kind of policy hinting image freshness lifetime, or its time resolution. Currently, it is used to correctly setmax-agein responseCache-Controlheader. The default granularity hasmax-age=0.InstallationThe following prerequisites are required to operate django-collectd-rest:django-rest-framework- powerful and flexible toolkit that makes it easy to build Web APIs.rrd- high performance data logging and graphing system for time series data.To use django-collectd-rest in your django project, include the following code into yoursettings.py:INSTALLED_APPS=(#...'rest_framework','collectd_rest',)Into yoururls.pyyou have to add the following:urlpatterns=patterns('',#...url(r'^collectd_rest/',include('collectd_rest.urls')),)ConfigurationThe whole configuration is stored into the project database, there is not separate dedicated configfile. New graphs and groups are added by creating new objects. The latter can be done in different ways.Using django database console:fromcollectd_restimportmodelsgroup=models.GraphGroup(title="The Group",name="group1")group.save()graph=models.Graph(title="The Graph",name="graph1",priority=0,command="DEF:cpuuser=/path/to/rrd/cpu-0/cpu-idle.rrd:value:AVERAGE LINE2:cpuuser#000000:legend",group=group)graph.save()TheGraphGroupmodel has two parameters: human-readabletitleand lookup fieldnameto access the group by url likehttp://example.com/collectd_rest/group/{name}/.
TheGraphmodel has way more fields, includingpriorityto sort the graphs inside one group, mandatory parentgroup, andcommandto generate rrd plot.The other ways to configure the application are Django fixtures, Django admin interface,django-rest-frameworkweb browsable interface, and REST API itself. You can also modify the graphs hierarchy dynamically by means of custom REST client.Authentication and permissionsYou may utilise all possible options provided bydjango-rest-framework. SeeTutorialfor reference.CachingYou may utilise all caching mechanisms provided byDjangoframework. SeeDjango's cache framework.UsingTo demonstrate how the framework can be used, let's look at the following JavaScript code (jQueryis used here). The following code renders the group namesmygroupinto correspondingdivelement, and themyothergroupinto the other one.<html><head><scripttype="text/javascript"src="http://yastatic.net/jquery/2.1.1/jquery.js"></script><script>functionrenderGraph(graph){varname=graph['name'];vartitle=graph['title'];varurl=graph['url'];varcode="<div id=\""+name+"\" class=\"django-collectd-rest-graph\">\n";code+="<div>"+title+"</div>\n";code+="<img src="+url+" />\n";code+="</div>\n";returncode;};functionrenderGroup(group){varname=group['name'];vartitle=group['title'];vargraphs=group['graphs'];varcode="<div>"+title+"</div><ul>\n";graphs.forEach(function(g){code+="<li>"+renderGraph(g)+"</li>\n";});code+="</ul>\n";returncode;}$(document).ready(function(){$.get("http://example.com/collectd_rest/groups/",function(data){data.forEach(function(entry){varname=entry['name'];varcode=renderGroup(entry);$(".django-collectd-rest-group#"+name).html(code);});});});</script></head><body><divid="test"></div><divclass="django-collectd-rest-group"id="mygroup"></div><divclass="django-collectd-rest-group"id="myothergroup"></div></body></html>FeedbackIf you have any questions, issues, or pull-requests, you are welcome to use GitHub infrastructure for them.LicenseCopyright (c) 2014, Matwey V. KornilovAll rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.