mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 09:12:56 +08:00
feat(websockets): inital work on websockets, #4355
This commit is contained in:
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/go-macaron/binding"
|
"github.com/go-macaron/binding"
|
||||||
"github.com/grafana/grafana/pkg/api/avatar"
|
"github.com/grafana/grafana/pkg/api/avatar"
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/live"
|
"github.com/grafana/grafana/pkg/api/live"
|
||||||
"github.com/grafana/grafana/pkg/middleware"
|
"github.com/grafana/grafana/pkg/middleware"
|
||||||
m "github.com/grafana/grafana/pkg/models"
|
m "github.com/grafana/grafana/pkg/models"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/live"
|
|
||||||
"github.com/grafana/grafana/pkg/middleware"
|
"github.com/grafana/grafana/pkg/middleware"
|
||||||
"github.com/grafana/grafana/pkg/services/search"
|
"github.com/grafana/grafana/pkg/services/search"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Search(c *middleware.Context) {
|
func Search(c *middleware.Context) {
|
||||||
@ -43,6 +43,4 @@ func Search(c *middleware.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, searchQuery.Result)
|
c.JSON(200, searchQuery.Result)
|
||||||
|
|
||||||
live.SendMessage(query)
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import {infoPopover} from './components/info_popover';
|
|||||||
import {colorPicker} from './components/colorpicker';
|
import {colorPicker} from './components/colorpicker';
|
||||||
import {navbarDirective} from './components/navbar/navbar';
|
import {navbarDirective} from './components/navbar/navbar';
|
||||||
import {arrayJoin} from './directives/array_join';
|
import {arrayJoin} from './directives/array_join';
|
||||||
|
import {liveSrv} from './live/live_srv';
|
||||||
import 'app/core/controllers/all';
|
import 'app/core/controllers/all';
|
||||||
import 'app/core/services/all';
|
import 'app/core/services/all';
|
||||||
import 'app/core/routes/routes';
|
import 'app/core/routes/routes';
|
||||||
@ -42,5 +43,6 @@ export {
|
|||||||
navbarDirective,
|
navbarDirective,
|
||||||
searchDirective,
|
searchDirective,
|
||||||
colorPicker,
|
colorPicker,
|
||||||
|
liveSrv,
|
||||||
infoPopover
|
infoPopover
|
||||||
};
|
};
|
||||||
|
31
public/app/core/live/live_srv.ts
Normal file
31
public/app/core/live/live_srv.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
///<reference path="../../headers/common.d.ts" />
|
||||||
|
|
||||||
|
import config from 'app/core/config';
|
||||||
|
import coreModule from 'app/core/core_module';
|
||||||
|
|
||||||
|
export class LiveSrv {
|
||||||
|
conn: any;
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.conn = new WebSocket("ws://localhost:3000/ws");
|
||||||
|
this.conn.onclose = function(evt) {
|
||||||
|
console.log("WebSocket closed");
|
||||||
|
};
|
||||||
|
this.conn.onmessage = function(evt) {
|
||||||
|
console.log("WebSocket message", evt.data);
|
||||||
|
};
|
||||||
|
this.conn.onopen = function(evt) {
|
||||||
|
console.log("Connection opened");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribe(name) {
|
||||||
|
if (!this.conn) {
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var instance = new LiveSrv();
|
||||||
|
export {instance as liveSrv};
|
@ -20,14 +20,6 @@ class AdminSettingsCtrl {
|
|||||||
class AdminHomeCtrl {
|
class AdminHomeCtrl {
|
||||||
/** @ngInject **/
|
/** @ngInject **/
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
var conn = new WebSocket("ws://localhost:3000/ws");
|
|
||||||
conn.onclose = function(evt) {
|
|
||||||
console.log("Connection closed");
|
|
||||||
};
|
|
||||||
conn.onmessage = function(evt) {
|
|
||||||
console.log("message", evt.data);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
public/app/plugins/datasource/stream/datasource.ts
Normal file
21
public/app/plugins/datasource/stream/datasource.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
///<reference path="../../../headers/common.d.ts" />
|
||||||
|
|
||||||
|
import {liveSrv} from 'app/core/core';
|
||||||
|
|
||||||
|
export class GrafanaStreamDS {
|
||||||
|
|
||||||
|
/** @ngInject */
|
||||||
|
constructor(private $q) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
query(options) {
|
||||||
|
if (options.targets.length === 0) {
|
||||||
|
return Promise.resolve({data: []});
|
||||||
|
}
|
||||||
|
|
||||||
|
var target = options.targets[0];
|
||||||
|
liveSrv.subscribe(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
15
public/app/plugins/datasource/stream/module.ts
Normal file
15
public/app/plugins/datasource/stream/module.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
///<reference path="../../../headers/common.d.ts" />
|
||||||
|
|
||||||
|
import angular from 'angular';
|
||||||
|
import {GrafanaStreamDS} from './datasource';
|
||||||
|
import {QueryCtrl} from 'app/plugins/sdk';
|
||||||
|
|
||||||
|
class GrafanaQueryCtrl extends QueryCtrl {
|
||||||
|
static templateUrl = 'partials/query.editor.html';
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
GrafanaStreamDS as Datasource,
|
||||||
|
GrafanaQueryCtrl as QueryCtrl,
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
<query-editor-row ctrl="ctrl">
|
||||||
|
<li class="tight-form-item">
|
||||||
|
Stream Expression
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<input type="text" class="tight-form-input input-large" ng-model="ctrl.target.channel">
|
||||||
|
</li>
|
||||||
|
</query-editor-row>
|
8
public/app/plugins/datasource/stream/plugin.json
Normal file
8
public/app/plugins/datasource/stream/plugin.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "datasource",
|
||||||
|
"name": "Grafana Stream DS",
|
||||||
|
"id": "grafana-stream-ds",
|
||||||
|
|
||||||
|
"builtIn": true,
|
||||||
|
"metrics": true
|
||||||
|
}
|
Reference in New Issue
Block a user