瀏覽代碼

Merge pull request #3008 from mtanda/prometheus_link

Revert prometheus graph view link
Torkel Ödegaard 10 年之前
父節點
當前提交
89eedd59a8

+ 1 - 0
public/app/plugins/datasource/prometheus/datasource.js

@@ -21,6 +21,7 @@ function (angular, _, moment, dateMath) {
       this.name = datasource.name;
       this.supportMetrics = true;
       this.url = datasource.url;
+      this.directUrl = datasource.directUrl;
       this.basicAuth = datasource.basicAuth;
       this.lastErrors = {};
     }

+ 5 - 0
public/app/plugins/datasource/prometheus/partials/query.editor.html

@@ -110,6 +110,11 @@
              ng-change="refreshMetricData()">
       </select>
     </li>
+    <li class="tight-form-item">
+      <a href="{{linkToPrometheus()}}" target="_blank" bs-tooltip="'Link to Graph in Prometheus'">
+        <i class="fa fa-share-square-o"></i>
+      </a>
+    </li>
   </ul>
 
   <div class="clearfix"></div>

+ 15 - 0
public/app/plugins/datasource/prometheus/query_ctrl.js

@@ -44,6 +44,21 @@ function (angular, _) {
         .then(callback);
     };
 
+    $scope.linkToPrometheus = function() {
+      var range = Math.ceil(($scope.range.to.valueOf() - $scope.range.from.valueOf()) / 1000);
+      var endTime = $scope.range.to.utc().format('YYYY-MM-DD HH:MM');
+      var expr = {
+        expr: $scope.target.expr,
+        range_input: range + 's',
+        end_input: endTime,
+        step_input: '',
+        stacked: $scope.panel.stack,
+        tab: 0
+      };
+      var hash = encodeURIComponent(JSON.stringify([expr]));
+      return $scope.datasource.directUrl + '/graph#' + hash;
+    };
+
     $scope.init();
   });