Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Disable graphs if GRAPHITE_SERVER is None
Browse files Browse the repository at this point in the history
This allows using the UI without a graphite server (and not having lots of
broken images and useless HTTP requests).

To use pdnscontrol without graphite, set `GRAPHITE_SERVER = None` in
pdnscontrol.conf.

Fixes #85.
  • Loading branch information
zeha committed Mar 29, 2015
1 parent 1ecc8b5 commit 52af333
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 14 deletions.
2 changes: 2 additions & 0 deletions instance/pdnscontrol.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# GRAPHITE_SERVER = 'http://127.0.0.1:8085/render/'
# GRAPHITE_TIMEOUT = 30
# IGNORE_SSL_ERRORS = False
# If you don't have/want Graphite:
# GRAPHITE_SERVER = None

# USE_X_SENDFILE = False
# SESSION_COOKIE_NAME = 'ControlSess'
Expand Down
5 changes: 5 additions & 0 deletions pdnscontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def inject_auth_data():
return dict(user=user, logged_in=logged_in, user_roles=roles)


@app.context_processor
def inject_config():
return {'GRAPHITE_SERVER': app.config['GRAPHITE_SERVER']}


@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
Expand Down
11 changes: 8 additions & 3 deletions pdnscontrol/static/js/controllers.server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use strict";

angular.module('ControlApp.controllers.server', []);
angular.module('ControlApp.controllers.server', ['graphite']);

angular.module('ControlApp.controllers.server').controller('ServerListCtrl', ['$scope', '$compile', '$filter', 'Restangular', function($scope, $compile, $filter, Restangular) {
angular.module('ControlApp.controllers.server').controller('ServerListCtrl', ['$scope', '$compile', '$filter', 'Restangular', 'GraphiteManager', function($scope, $compile, $filter, Restangular, GraphiteManager) {
$scope.haveGraphite = GraphiteManager.enabled;
// init server-list filter
$scope.filter = "";

Expand Down Expand Up @@ -247,14 +248,18 @@ angular.module('ControlApp.controllers.server').controller('ServerCreateCtrl', [
};
}]);

angular.module('ControlApp.controllers.server').controller('ServerDetailCtrl', ['$scope', '$compile', '$location', 'Restangular', 'server', function($scope, $compile, $location, Restangular, server) {
angular.module('ControlApp.controllers.server').controller('ServerDetailCtrl', ['$scope', '$compile', '$location', 'Restangular', 'server', 'GraphiteManager', function($scope, $compile, $location, Restangular, server, GraphiteManager) {
$scope.haveGraphite = GraphiteManager.enabled;
$scope.server = server;
(function() {
var fragments = $location.path().split('/').reverse();
if (fragments.length == 4) {
$scope.current_tab = fragments[0];
} else {
$scope.current_tab = ''; // overview tab
if (!GraphiteManager.enabled) {
$scope.current_tab = 'statistics';
}
}
})();

Expand Down
23 changes: 18 additions & 5 deletions pdnscontrol/static/js/graphite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
"use strict";

var GraphiteModule = angular.module('graphite', ['services.pageVisibility']);
GraphiteModule.directive('graphite', function($interval, pageVisibility) {

GraphiteModule.factory('GraphiteManager', [function() {
return {
enabled: (ServerData.Config.graphite_server != null),
url: ServerData.Config.graphite_server,
default_opts: ServerData.Config.graphite_default_opts,
};
}]);

GraphiteModule.directive('graphite', function($interval, pageVisibility, GraphiteManager) {
return {
restrict: 'E',
template: '<div class="graphite-graph"><div class="right graphite-times">' +
Expand All @@ -20,7 +29,7 @@ GraphiteModule.directive('graphite', function($interval, pageVisibility) {
attrs.$set('gSalt', Math.random()*10000000);

function updateUrl() {
var url = ServerData.Config.graphite_server + '?_cache=180&_salt=' + attrs.gSalt;
var url = GraphiteManager.url + '?_cache=180&_salt=' + attrs.gSalt;
if (attrs.gSource === undefined)
return;

Expand All @@ -33,7 +42,7 @@ GraphiteModule.directive('graphite', function($interval, pageVisibility) {
'from': attrs.gFrom,
'title': attrs.gTitle || '',
'vtitle': attrs.gVTitle || ''
}, ServerData.Config.graphite_default_opts);
}, GraphiteManager.default_opts);

// automatically choose width, if possible
var width = $(elm).width() || $(elm).parent().width();
Expand Down Expand Up @@ -152,9 +161,9 @@ GraphiteModule.directive('graph', function() {
};
});

GraphiteModule.directive('sparklegraph', function($http, $interval) {
GraphiteModule.directive('sparklegraph', function($http, $interval, GraphiteManager) {
function showGraph(server, metric, width, from, elm, doneCallback) {
$http.get(ServerData.Config.graphite_server, {
$http.get(GraphiteManager.url, {
params: {
format: 'json',
areaMode: 'first',
Expand All @@ -180,6 +189,10 @@ GraphiteModule.directive('sparklegraph', function($http, $interval) {
return {
restrict: 'E',
link: function(scope, elm, attrs) {
if (!GraphiteManager.enabled) {
return;
}

var server = attrs.server.replace(/\./gm,'-');
var metric = attrs.metric;
var width = attrs.width;
Expand Down
2 changes: 1 addition & 1 deletion pdnscontrol/templates/clientside/server/detail.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-include src="'/tpl/server/detail_header.html'"></ng-include>
<div class="row">
<div class="row" ng-if="haveGraphite">
<div class="small-12 columns">
<div ng-switch on="server.daemon_type">
<div ng-switch-when="Authoritative">
Expand Down
2 changes: 1 addition & 1 deletion pdnscontrol/templates/clientside/server/detail_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1 class="server-name">{{server.name}}
<div class="row">
<div class="small-12 columns">
<dl class="tabs">
<dd ng-class="{active: current_tab==''}"><a href="/server/{{ server._id }}">Graphs</a></dd>
<dd ng-class="{active: current_tab==''}" ng-show="haveGraphite"><a href="/server/{{ server._id }}">Graphs</a></dd>
<dd ng-class="{active: current_tab=='statistics'}"><a href="/server/{{ server._id }}/statistics">Statistics</a></dd>
<dd ng-class="{active: current_tab=='zones'}"><a href="/server/{{ server._id }}/zones">Zones</a></dd>
<dd ng-class="{active: current_tab=='config'}"><a href="/server/{{ server._id }}/config">Configuration</a></dd>
Expand Down
6 changes: 3 additions & 3 deletions pdnscontrol/templates/clientside/server/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Servers</h1>
<th ng-click="orderProp = 'listen_address'">Main IP</th>
<th ng-click="orderProp = 'version'">Version</th>
<th ng-click="orderProp = 'uptime'">Up for</th>
<th>Load</th>
<th ng-if="haveGraphite">Load</th>
</tr>
</thead>
<tbody>
Expand All @@ -37,7 +37,7 @@ <h1>Servers</h1>
<td>{{server.listen_address()}}</td>
<td>{{server.version}}</td>
<td><span class="app-tooltip" tooltip="{{server.stats.uptime | absolutize_time | full_timestamp}}">{{server.stats.uptime | absolutize_time | rel_timestamp}}</span></td>
<td width="60" ng-switch on="server.daemon_type">
<td width="60" ng-switch on="server.daemon_type" ng-if="haveGraphite">
<sparklegraph ng-switch-when="Authoritative" width="60px" from="-600s" server="{{server.name}}" metric="auth.udp-queries"></sparklegraph>
<sparklegraph ng-switch-when="Recursor" width="60px" from="-600s" server="{{server.name}}" metric="recursor.questions"></sparklegraph>
</td>
Expand Down Expand Up @@ -67,7 +67,7 @@ <h1>Servers</h1>
</div>
</div>

<div class="row">
<div class="row" ng-if="haveGraphite">
<div class="small-12 columns" ng-show="selected_servers().length>0">
<h3>Aggregate statistics</h3>

Expand Down
2 changes: 1 addition & 1 deletion pdnscontrol/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{# FIXME: move this into its own route and make it cacheable #}
ServerData.Config = {
url_root: "{[ request.url_root ]}",
graphite_server: "/graphite/render/",
graphite_server: {[ ("/graphite/render" if GRAPHITE_SERVER else None)|tojson|safe ]},
graphite_default_opts: {
bgcolor: "FFFFFF",
majorGridLineColor: "darkgray",
Expand Down

0 comments on commit 52af333

Please sign in to comment.