Torkel Ödegaard преди 8 години
родител
ревизия
1ecdf34938

+ 3 - 0
public/app/plugins/datasource/mysql/README.md

@@ -0,0 +1,3 @@
+# Grafana Fake Data Datasource -  Native Plugin
+
+This is the built in Fake Data Datasource that is used before any datasources are set up in your Grafana installation. It means you can create a graph without any data and still get an idea of what it would look like.

+ 43 - 0
public/app/plugins/datasource/mysql/datasource.ts

@@ -0,0 +1,43 @@
+///<reference path="../../../headers/common.d.ts" />
+
+import _ from 'lodash';
+
+export class MysqlDatasource {
+
+  /** @ngInject */
+  constructor(private instanceSettings, private backendSrv) {
+  }
+
+  query(options) {
+    console.log('test');
+    console.log(this.instanceSettings);
+    return this.backendSrv.post('/api/tsdb/query', {
+      from: options.range.from.valueOf().toString(),
+      to: options.range.to.valueOf().toString(),
+      queries: [
+        {
+          "refId": "A",
+          "scenarioId": "random_walk",
+          "intervalMs": options.intervalMs,
+          "maxDataPoints": options.maxDataPoints,
+        }
+      ]
+    }).then(res => {
+
+      var data = [];
+      if (res.results) {
+        _.forEach(res.results, queryRes => {
+          for (let series of queryRes.series) {
+            data.push({
+              target: series.name,
+              datapoints: series.points
+            });
+          }
+        });
+      }
+
+      return {data: data};
+    });
+  }
+}
+

+ 16 - 0
public/app/plugins/datasource/mysql/module.ts

@@ -0,0 +1,16 @@
+///<reference path="../../../headers/common.d.ts" />
+
+import angular from 'angular';
+import {MysqlDatasource} from './datasource';
+import {QueryCtrl} from 'app/plugins/sdk';
+
+class MysqlQueryCtrl extends QueryCtrl {
+  static templateUrl = 'partials/query.editor.html';
+}
+
+export {
+  MysqlDatasource,
+  MysqlDatasource as Datasource,
+  MysqlQueryCtrl as QueryCtrl,
+};
+

+ 20 - 0
public/app/plugins/datasource/mysql/partials/annotations.editor.html

@@ -0,0 +1,20 @@
+
+<div class="gf-form-group">
+	<h6>Filters</h6>
+	<div class="gf-form-inline">
+		<div class="gf-form">
+			<span class="gf-form-label width-7">Type</span>
+			<div class="gf-form-select-wrapper">
+				<select class="gf-form-input" ng-model="ctrl.annotation.type" ng-options="f.value as f.text for f in [{text: 'Alert', value: 'alert'}]">
+				</select>
+			</div>
+		</div>
+		<div class="gf-form">
+			<span class="gf-form-label width-7">Max limit</span>
+			<div class="gf-form-select-wrapper">
+				<select class="gf-form-input" ng-model="ctrl.annotation.limit" ng-options="f for f in [10,50,100,200,300,500,1000,2000]">
+				</select>
+			</div>
+		</div>
+	</div>
+</div>

+ 7 - 0
public/app/plugins/datasource/mysql/partials/query.editor.html

@@ -0,0 +1,7 @@
+<query-editor-row query-ctrl="ctrl" can-collapse="false">
+	<div class="gf-form-inline">
+		<div class="gf-form">
+			<label class="gf-form-label">Test metric (fake data source)</label>
+		</div>
+	</div>
+</query-editor-row>

+ 8 - 0
public/app/plugins/datasource/mysql/plugin.json

@@ -0,0 +1,8 @@
+{
+  "type": "datasource",
+  "name": "MySQL",
+  "id": "mysql",
+
+  "annotations": true,
+  "metrics": true
+}