sql: wip mysql stuff

This commit is contained in:
Torkel Ödegaard
2017-03-29 20:43:20 +02:00
parent 6965064ea9
commit 1ecdf34938
6 changed files with 97 additions and 0 deletions

View File

@@ -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.

View File

@@ -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};
});
}
}

View File

@@ -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,
};

View File

@@ -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>

View File

@@ -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>

View File

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