Add Grafana configuration to docker file and add graph

Change-Id: I687c1c24fed49a98f83015cab73879a3323432fb
This commit is contained in:
Vincent Fournier 2015-06-01 22:38:21 -04:00
parent bc2a419f53
commit 45aae4bf8a
9 changed files with 76 additions and 20 deletions

View File

@ -7,7 +7,7 @@ ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get update && apt-get install -yq git apache2 npm nodejs-legacy ruby
RUN apt-get update && apt-get install -yq git apache2 npm nodejs-legacy ruby curl
RUN npm install -g grunt-cli bower
RUN gem install sass
RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd
@ -17,6 +17,7 @@ ADD container/000-default.conf etc/apache2/sites-enabled/000-default.conf
ADD container/ports.conf etc/apache2/ports.conf
RUN a2enmod proxy
RUN a2enmod proxy_http
RUN a2enmod headers
# configure script
ADD container/configure.sh /configure.sh
@ -35,6 +36,12 @@ ENV BANSHO_PROD true
ENV BANSHO_SURVEIL_URL http://surveil:8080/
ENV BANSHO_AUTH_URL http://surveil:8080/v2/auth/
ENV INFLUXDB_HOST influxdb
ENV INFLUXDB_PORT 8086
ENV INFLUXDB_NAME db
ENV INFLUXDB_USER root
ENV INFLUXDB_PASS root
CMD ./configure.sh && \
cd /opt/bansho && \
bash -c "if [ $BANSHO_PROD = true ] ; then grunt production ; fi" && \

View File

@ -9,17 +9,17 @@ rebuild:
sudo docker build --no-cache -t bansho .
interactive:
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil -v $(shell pwd)/app:/opt/bansho/dist -e BANSHO_ENV=false -i -t --name bansho bansho bash
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil --link surveil_grafana_1:grafana -v $(shell pwd)/app:/opt/bansho/dist -e BANSHO_ENV=false -i -t --name bansho bansho bash
daemon:
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil -v $(shell pwd)/app:/opt/bansho/dist -e BANSHO_PROD=false -d -t --name bansho bansho
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil --link surveil_grafana_1:grafana -v $(shell pwd)/app:/opt/bansho/dist -e BANSHO_PROD=false -d -t --name bansho bansho
grunt development
production:
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil -d -t --name bansho bansho
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil --link surveil_grafana_1:grafana -d -t --name bansho bansho
staging:
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil -v $(shell pwd)/dist:/opt/bansho/dist -e BANSHO_PROD=false -d -t --name bansho bansho
sudo docker run -p 8888:8888 --link surveil_surveil_1:surveil --link surveil_grafana_1:grafana -v $(shell pwd)/dist:/opt/bansho/dist -e BANSHO_PROD=false -d -t --name bansho bansho
grunt staging
kill:

View File

@ -18,7 +18,8 @@ angular.module('bansho', [
'bansho.view.host',
'bansho.view.service',
'bansho.view.drupalDashboard',
'bansho.view.drupal'
'bansho.view.drupal',
'bansho.grafana'
])
.config(['$routeProvider', function ($routeProvider) {

View File

@ -0,0 +1,23 @@
'use strict';
angular.module('bansho.grafana', [])
.service('iframeUrl', function () {
var createIFrameUrl = function (templateName, host_name, service_description, metric) {
return '/grafana/dashboard-solo/db/' + templateName + '?' +
'panelId=' + '1' +
'&fullscreen&from=' + 'now-6h' +
'&to=' + 'now' +
'&var-metric1=' + metric +
'&var-host_name=' + host_name +
'&var-service_description=' + service_description;
};
var getIFrameUrl = function (metric, host_name, service_description) {
return createIFrameUrl('templatehostnameservicedescriptiononemetric',
host_name, service_description, metric);
};
return {
getIFrameUrl: getIFrameUrl
};
});

View File

@ -1,5 +1,6 @@
<div class="subcomponent__live subcomponent__small">
<h2>Load</h2>
<iframe src="{{iframeUrl}}" width="450" height="200" frameborder="0"></iframe>
<table class="data-table">
<tbody>
<tr>

View File

@ -1,12 +1,12 @@
'use strict';
angular.module('bansho.host.load', [])
.directive('banshoHostLoad', function () {
.directive('banshoHostLoad', ['iframeUrl', function (iframeUrl) {
return {
restrict: 'E',
compile: function (scope, element, attrs) {
scope.host = attrs.host;
},
controller: ['$scope', function ($scope, element, attrs) {
$scope.iframeUrl = iframeUrl.getIFrameUrl("metric_load1", $scope.host.config.host_name, "load");
}],
templateUrl: 'components/host/host_load/host_load.html'
};
});
}]);

View File

@ -69,6 +69,7 @@
<script src="components/table/cell_status_host_address/cell_status_host_address.js"></script>
<script src="components/table/cell_status_host_status/cell_status_host_status.js"></script>
<script src="components/table/state_icon/state_icon.js"></script>
<script src="components/grafana/grafana.js"></script>
<script src="components/host/host.js"></script>
<script src="components/host/host_cpu/host_cpu.js"></script>

View File

@ -15,6 +15,8 @@
ProxyPass /surveil/ http://surveil:8080/
ProxyPassReverse /surveil/ http://surveil:8080/
ProxyPass /adagios/ http://demo.kaji-project.org/
ProxyPassReverse /adagios/ http://demo.kaji-project.org/
RequestHeader set GRAFANA-USER "admin"
ProxyPass /grafana/ http://grafana:80/
ProxyPassReverse /grafana/ http://grafana:80/
</VirtualHost>

View File

@ -2,6 +2,7 @@
CONFIG_FILE="/etc/apache2/sites-enabled/000-default.conf"
function configure_proxy {
echo "=> Configuring apache ProxyPass ..."
# Surveil URLS
@ -11,3 +12,23 @@ sed -i "s|ProxyPassReverse /surveil/ .*|ProxyPassReverse /surveil/ ${BANSHO_SURV
# Bansho auth URL
sed -i "s|ProxyPass /surveil/v2/auth/.*|ProxyPass /surveil/v2/auth/ ${BANSHO_AUTH_URL}|g" ${CONFIG_FILE}
sed -i "s|ProxyPassReverse /surveil/v2/auth/.*|ProxyPass /surveil/v2/auth/ ${BANSHO_AUTH_URL}|g" ${CONFIG_FILE}
}
function configure_grafana {
echo "=> Configuring InfluxDB datasources."
curl 'http://localhost:8888/grafana/api/datasources' -X PUT -H 'Content-Type: application/json;charset=utf-8' --data '{"name":"influxdb","type":"influxdb","url":"http://'${INFLUXDB_HOST}':'${INFLUXDB_PORT}'","access":"proxy","isDefault":true,"database":"'${INFLUXDB_NAME}'","user":"'${INFLUXDB_USER}'","password":"'${INFLUXDB_PASS}'"}'
# Save dashboard
curl 'http://localhost:8888/grafana/api/dashboards/db/' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' -H 'Connection: keep-alive' -H 'DNT: 1' --data-binary $'{"dashboard":{"id":null,"title":"templateHostNameServiceDescriptionOneMetric","originalTitle":"templateHostNameServiceDescriptionOneMetric","tags":[],"style":"dark","timezone":"browser","editable":true,"hideControls":false,"rows":[{"collapse":false,"editable":true,"height":"250px","panels":[{"aliasColors":{},"bars":false,"datasource":null,"editable":true,"error":false,"fill":1,"grid":{"leftLogBase":1,"leftMax":null,"leftMin":null,"rightLogBase":1,"rightMax":null,"rightMin":null,"threshold1":null,"threshold1Color":"rgba(216, 200, 27, 0.27)","threshold2":null,"threshold2Color":"rgba(234, 112, 112, 0.22)"},"id":1,"interval":"20s","legend":{"avg":false,"current":false,"max":false,"min":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":2,"links":[],"nullPointMode":"connected","percentage":false,"pointradius":5,"points":false,"renderer":"flot","seriesOverrides":[],"span":12,"stack":false,"steppedLine":false,"targets":[{"function":"mean","groupByTags":[],"measurement":"$metric1","query":"SELECT mean(value) FROM \\"$metric1\\" WHERE host_name=\'$host_name\' AND service_description=\'$service_description\' AND $timeFilter GROUP BY time($interval) ORDER BY asc","tags":[{"key":"host_name","value":"$host_name"},{"condition":"AND","key":"service_description","value":"$service_description"}]}],"timeFrom":null,"timeShift":null,"title":"","tooltip":{"shared":true,"value_type":"cumulative"},"type":"graph","x-axis":true,"y-axis":true,"y_formats":["short","short"]}],"title":"Row"}],"nav":[{"collapse":false,"enable":true,"notice":false,"now":true,"refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],"status":"Stable","time_options":["5m"],"type":"timepicker"}],"time":{"from":"now-6h","to":"now"},"templating":{"list":[{"allFormat":"glob","datasource":null,"includeAll":false,"multi":false,"multiFormat":"glob","name":"metric1","query":"SHOW measurements","refresh_on_load":false,"type":"query"},{"allFormat":"glob","datasource":null,"includeAll":false,"multi":false,"multiFormat":"glob","name":"host_name","query":"SHOW tag values With key in (host_name) ","refresh_on_load":false,"type":"query"},{"allFormat":"glob","datasource":null,"includeAll":false,"multi":false,"multiFormat":"glob","name":"service_description","query":"SHOW tag values With key in (service_description) ","refresh_on_load":false,"type":"query"}]},"annotations":{"list":[]},"schemaVersion":6,"version":0,"links":[]},"overwrite":true}' --compressed
}
configure_proxy
if [ -f "/.grafana_setup" ]; then
echo "=> Data sources had been created before, skipping ..."
else
(sleep 60 && configure_grafana && touch "/.grafana_setup")&
fi