Skip to content

Commit

Permalink
first push
Browse files Browse the repository at this point in the history
  • Loading branch information
masato25 committed Apr 22, 2016
1 parent 1f48da7 commit 9b8671d
Show file tree
Hide file tree
Showing 43 changed files with 4,298 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Openfaln Datasource - 3 party plugin

[Openfalcon](https://github.com/open-falcon() is a system monitor solution made by xiaomi.

![](./img/grafana_demo.png)

## How to install?
* Please download the latest version of Grafana on the [github](https://github.com/grafana/grafana). (currently the latest one is tag -> v3.0-beta5)
* Finish the all setup up. (more info please refer the README.md in Grafana project.)
```
cd $GOPATH/src/github.com/grafana/grafana
go run build.go setup (only needed once to install godep)
godep restore (will pull down all golang lib dependencies in your current GOPATH)
go run build.go build
```
```
npm install
npm install -g grunt-cli
grunt
```
* Checkout this plugin
```
cd $GRAFANA_PATH/public_gen/app/plugins/datasource
git clone https://github.com/masato25/grafana-openfalcon
```
* Start grafana-server
```
./bin/grafana-server
```
* if the installation is successed, You will see Openfalcon on the datasource list.
![](./img/openfalcon_datasource.png)
108 changes: 108 additions & 0 deletions add_openfalcon_func.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
define([
'angular',
'lodash',
'jquery',
'./gfunc',
],
function (angular, _, $, gfunc) {
'use strict';

angular
.module('grafana.directives')
.directive('openfalconAddFunc', function($compile) {
var inputTemplate = '<input type="text"'+
' class="tight-form-input input-medium tight-form-input"' +
' spellcheck="false" style="display:none"></input>';

var buttonTemplate = '<a class="tight-form-item tight-form-func dropdown-toggle"' +
' tabindex="1" gf-dropdown="functionMenu" data-toggle="dropdown">' +
'<i class="fa fa-plus"></i></a>';

return {
link: function($scope, elem) {
var categories = gfunc.getCategories();
var allFunctions = getAllFunctionNames(categories);
var ctrl = $scope.ctrl;

$scope.functionMenu = createFunctionDropDownMenu(categories);

var $input = $(inputTemplate);
var $button = $(buttonTemplate);
//$input.appendTo(elem);
//$button.appendTo(elem);

$input.attr('data-provide', 'typeahead');
$input.typeahead({
source: allFunctions,
minLength: 1,
items: 10,
updater: function (value) {
var funcDef = gfunc.getFuncDef(value);
if (!funcDef) {
// try find close match
value = value.toLowerCase();
funcDef = _.find(allFunctions, function(funcName) {
return funcName.toLowerCase().indexOf(value) === 0;
});

if (!funcDef) { return; }
}

$scope.$apply(function() {
ctrl.addFunction(funcDef);
});

$input.trigger('blur');
return '';
}
});

$button.click(function() {
$button.hide();
$input.show();
$input.focus();
});

$input.keyup(function() {
elem.toggleClass('open', $input.val() === '');
});

$input.blur(function() {
// clicking the function dropdown menu wont
// work if you remove class at once
setTimeout(function() {
$input.val('');
$input.hide();
$button.show();
elem.removeClass('open');
}, 200);
});

$compile(elem.contents())($scope);
}
};
});

function getAllFunctionNames(categories) {
return _.reduce(categories, function(list, category) {
_.each(category, function(func) {
list.push(func.name);
});
return list;
}, []);
}

function createFunctionDropDownMenu(categories) {
return _.map(categories, function(list, category) {
return {
text: category,
submenu: _.map(list, function(value) {
return {
text: value.name,
click: "ctrl.addFunction('" + value.name + "')",
};
})
};
});
}
});
176 changes: 176 additions & 0 deletions dashboards/carbon_metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"__inputs": [
{
"name": "DS_NAME",
"type": "datasource",
"pluginId": "openfalcon"
}
],

"revision": "1.0",
"title": "Openfalcon Carbon Metrics",
"tags": ["openfalcon", "carbon"],
"style": "dark",
"timezone": "browser",
"editable": true,
"hideControls": false,
"sharedCrosshair": false,
"rows": [
{
"collapsable": true,
"collapse": false,
"editable": true,
"height": "350px",
"notice": false,
"panels": [
{
"aliasColors": {},
"annotate": {
"enable": false
},
"bars": false,
"datasource": "${DS_NAME}",
"editable": true,
"fill": 0,
"grid": {
"leftLogBase": 1,
"leftMax": null,
"leftMin": null,
"max": null,
"min": 0,
"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,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"loadingEditor": false,
"nullPointMode": "null as zero",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"resolution": 100,
"scale": 1,
"seriesOverrides": [
{
"alias": "Points Per Update",
"yaxis": 2
},
{
"alias": "CPU",
"yaxis": 2
}
],
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [
{
"refId": "A",
"target": "alias(sumSeries(carbon.agents.*.updateOperations),\"Updates\") "
},
{
"refId": "B",
"target": "alias(sumSeries(carbon.agents.*.metricsReceived),'Metrics Received')"
},
{
"refId": "C",
"target": "alias(sumSeries(carbon.agents.*.committedPoints),'Committed Points')"
},
{
"refId": "D",
"target": "alias(sumSeries(carbon.agents.*.pointsPerUpdate),'Points Per Update')"
},
{
"refId": "E",
"target": "alias(averageSeries(carbon.agents.*.cpuUsage),'CPU')"
},
{
"refId": "F",
"target": "alias(sumSeries(carbon.agents.*.creates),'Creates')"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Openfalcon Carbon Metrics",
"tooltip": {
"query_as_alias": true,
"shared": false,
"value_type": "cumulative"
},
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"short",
"short"
],
"zerofill": true
}
],
"title": "Row1"
}
],
"time": {
"from": "now-3h",
"to": "now"
},
"timepicker": {
"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",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
],
"type": "timepicker"
},
"templating": {
"enable": false,
"list": []
},
"annotations": {
"enable": false,
"list": []
},
"refresh": false,
"schemaVersion": 8,
"version": 2,
"links": []
}
Loading

0 comments on commit 9b8671d

Please sign in to comment.