Commit b5a1b3a4 by Torkel Odegaard

worked on metric key indexing and metric key search

parent 45ce00c1
......@@ -10,7 +10,6 @@ function (angular, _, config) {
module.controller('MetricKeysCtrl', function($scope, $http, $q) {
var elasticSearchUrlForMetricIndex = config.elasticsearch + '/' + config.grafana_index + '/';
var loadingDefered;
$scope.init = function () {
$scope.metricPath = "prod.apps.api.boobarella.*";
......@@ -103,7 +102,7 @@ function (angular, _, config) {
function receiveMetric(result) {
var data = result.data;
if (!data || data.length == 0) {
if (!data || data.length === 0) {
console.log('no data');
return;
}
......@@ -123,31 +122,24 @@ function (angular, _, config) {
function saveMetricKey(metricId) {
// Create request with id as title. Rethink this.
var request = ejs.Document(config.grafana_index, 'metricKey', metricId).source({
var request = $scope.ejs.Document(config.grafana_index, 'metricKey', metricId).source({
metricPath: metricId
});
return request.doIndex(
// Success
function(result) {
function() {
$scope.infoText = "Indexing " + metricId;
$scope.metricCounter = $scope.metricCounter + 1;
},
function(error) {
function() {
$scope.errorText = "failed to save metric " + metricId;
}
);
}
function metricLoadError(data, status, headers, config)
{
$scope.errorText = "failed to get metric";
}
function loadMetricsRecursive(metricPath)
{
return $http({ method: 'GET', url: config.graphiteUrl + '/metrics/find/?query=' + metricPath} )
.then(receiveMetric);
return $http.get(config.graphiteUrl + '/metrics/find/?query=' + metricPath).then(receiveMetric);
}
});
......
......@@ -14,18 +14,38 @@ function (angular, _, config, $) {
$scope.init = function() {
$scope.elasticsearch = $scope.elasticsearch || {};
$scope.giveSearchFocus = 0;
$scope.search_results = {
dashboards: [],
metrics: [],
graphs: []
};
$scope.selectedIndex = null;
};
$scope.keyDown = function (evt) {
if (evt.keyCode === 40) {
$scope.selectedIndex = ($scope.selectedIndex || 0) + 1;
}
};
$scope.elasticsearch_dashboards = function(queryStr) {
dashboard.elasticsearch_list(queryStr + '*', 50).then(function(results) {
if(_.isUndefined(results.hits)) {
$scope.search_results = { dashboards: [] };
return;
}
$scope.search_results = { dashboards: results.hits.hits };
});
};
$scope.elasticsearch_dblist = function(queryStr) {
var words = queryStr.split(" ");
queryStr = queryStr.toLowerCase();
if (queryStr.indexOf('d:') === 0) {
$scope.elasticsearch_dashboards(queryStr.substring(2, queryStr.length));
return;
}
var words = queryStr.split(' ');
var query = $scope.ejs.BoolQuery();
var terms = _.map(words, function(word) {
return $scope.ejs.MatchQuery("metricPath_ng", word).boost(1.2);
return $scope.ejs.MatchQuery('metricPath_ng', word).boost(1.2);
});
var ngramQuery = $scope.ejs.BoolQuery();
......@@ -39,11 +59,10 @@ function (angular, _, config, $) {
results.then(function(results) {
if (results && results.hits && results.hits.hits.length > 0) {
$scope.search_results.metrics = results.hits.hits;
console.log("hits", $scope.search_results.metrics);
$scope.search_results = { metrics: results.hits.hits };
}
else {
$scope.search_results.metrics = [];
$scope.search_results = { metric: [] };
}
});
};
......@@ -52,8 +71,26 @@ function (angular, _, config, $) {
$scope.giveSearchFocus = $scope.giveSearchFocus + 1;
};
$scope.addMetricToCurrentDashboard = function (metricId) {
dashboard.current.rows.push({
title: '',
height: '250px',
editable: true,
panels: [
{
type: 'graphite',
title: 'test',
span: 12,
targets: [ { target: metricId } ]
}
]
});
};
});
module.directive('xngFocus', function() {
return function(scope, element, attrs) {
$(element).click(function(e) {
......
......@@ -10,6 +10,47 @@
<li ng-repeat="pulldown in dashboard.current.nav" ng-controller="PulldownCtrl" ng-show="pulldown.enable"><kibana-simple-panel type="pulldown.type" ng-cloak></kibana-simple-panel></li>
<li class="dropdown"ng-show="showDropdown('save')">
<a href="#" bs-tooltip="'Save'" data-placement="bottom" class="dropdown-toggle" data-toggle="dropdown">
<i class='icon-save'></i>
</a>
<ul class="dropdown-menu" style="padding:10px">
<li ng-show="dashboard.current.loader.save_elasticsearch">
<form class="input-prepend nomargin">
<button style="margin-top:-1px" class="btn" ng-click="elasticsearch_save('dashboard')"><i class="icon-save"></i></button>
<input class='input-medium' ng-model="dashboard.current.title" type="text" ng-model="elasticsearch.title"/>
</form>
</li>
<li class="dropdown-submenu noarrow" ng-show="dashboard.current.loader.save_local || dashboard.current.loader.save_gist || dashboard.current.loader.save_default">
<a tabindex="-1" class="small" style="padding:0"><i class="icon-caret-left"></i> Advanced</a>
<ul class="dropdown-menu">
<li ng-show="dashboard.current.loader.save_default">
<a class="link" ng-click="set_default()">Save as Home</a>
</li>
<li ng-show="dashboard.current.loader.save_default">
<a class="link" ng-click="purge_default()">Reset Home</a>
</li>
<li ng-show="dashboard.current.loader.save_local">
<a class="link" ng-click="dashboard.to_file()">Export schema</a>
</li>
<li ng-show="dashboard.current.loader.save_gist" style="margin:10px">
<h6>Gist</h6>
<form class="input-append">
<input class='input-medium' placeholder='Title' type="text" ng-model="gist.title"/>
<button class="btn" ng-click="save_gist()"><i class="icon-github-alt"></i></button>
</form><br>
<small ng-show="gist.last">Last gist: <a target="_blank" href="{{gist.last}}">{{gist.last}}</a></small>
</li>
</ul>
</li>
</ul>
</li>
<li><a bs-tooltip="'Goto saved default'" data-placement="bottom" href='#/dashboard'><i class='icon-home'></i></a></li>
<li ng-show="showDropdown('share')"><a bs-tooltip="'Share'" data-placement="bottom" ng-click="elasticsearch_save('temp',dashboard.current.loader.save_temp_ttl)" bs-modal="'app/partials/dashLoaderShare.html'"><i class='icon-share'></i></a></li>
......
......@@ -19,19 +19,27 @@
<ul class="dropdown-menu grafana-search">
<li>
<div class="grafana-search-panel">
<input type="text" placeholder="search dashboards, metrics, or graphs" xng-focus="giveSearchFocus" ng-model="elasticsearch.query" ng-change="elasticsearch_dblist(elasticsearch.query)" />
<input type="text" placeholder="search dashboards, metrics, or graphs" xng-focus="giveSearchFocus" ng-keydown="keyDown($event)" ng-model="elasticsearch.query" ng-change="elasticsearch_dblist(elasticsearch.query)" />
<h6 ng-hide="search_results.metrics.length">No dashboards matching your query found</h6>
<h6 ng-hide="search_results.dashboards.length || search_results.metrics.length">No dashboards or metrics matching your query found</h6>
<table class="table table-condensed table-striped">
<tr bindonce ng-repeat="row in search_results.metrics">
<td><span class="label label-info">metric</span> {{row._id}}</td>
<tr bindonce ng-repeat="row in search_results.metrics" class="grafana-search-metric-result">
<td><span class="label label-info">metric</span></td>
<td class="grafana-search-metric-name">
{{row._id}}
</td>
<td style="width:100%;">
<div class="grafana-search-metric-actions">
<a ng-click="addMetricToCurrentDashboard(row._id)"><i class="icon-plus-sign"></i> Add to dashboard</a>
</div>
</td>
</tr>
<!--
<tr bindonce ng-repeat="row in search_results | orderBy:['_id']">
<tr bindonce ng-repeat="row in search_results.dashboards | orderBy:['_id']">
<td><a ng-click="elasticsearch_delete(row._id)"><i class="icon-remove"></i></a></td>
<td><a href="#/dashboard/elasticsearch/{{row._id}}" bo-text="row._id"></a></td>
<td style="width:100%"><a href="#/dashboard/elasticsearch/{{row._id}}" bo-text="row._id"></a></td>
<td><a><i class="icon-share" ng-click="share = dashboard.share_link(row._id,'elasticsearch',row._id)" bs-modal="'app/panels/dashcontrol/share.html'"></i></a></td>
</tr> -->
</tr>
</table>
</div>
</li>
......
......@@ -21,7 +21,7 @@ function (Settings) {
* elasticsearch installed on. You probably want to set it to the FQDN of your
* elasticsearch host
*/
elasticsearch: "http://se0-elasticstash-01:9200",
elasticsearch: "http://"+window.location.hostname+":9200",
/** @scratch /configuration/config.js/5
* ==== default_route
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -22,4 +22,22 @@
width: 770px;
margin-left: -385px;
top: 100px !important;
}
.grafana-search-metric-actions {
visibility: hidden;
padding-left: 20px;
}
.grafana-search-metric-name {
white-space: nowrap;
}
.grafana-search-metric-result:hover {
.grafana-search-metric-actions {
visibility: visible;
}
.grafana-search-metric-name {
color: @blue;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment