|
|
@ -29,7 +29,6 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
seriesList: any = []; |
|
|
|
seriesList: any = []; |
|
|
|
dataList: any = []; |
|
|
|
dataList: any = []; |
|
|
|
|
|
|
|
|
|
|
|
_backendUrl: string = undefined; |
|
|
|
|
|
|
|
// annotations: any = [];
|
|
|
|
// annotations: any = [];
|
|
|
|
|
|
|
|
|
|
|
|
private _datasourceRequest: DatasourceRequest; |
|
|
|
private _datasourceRequest: DatasourceRequest; |
|
|
@ -51,10 +50,15 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
_panelInfo: PanelInfo; |
|
|
|
_panelInfo: PanelInfo; |
|
|
|
|
|
|
|
|
|
|
|
private _analyticUnitTypes: any; |
|
|
|
private _analyticUnitTypes: any; |
|
|
|
|
|
|
|
private _hasticDatasources: any[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private $graphElem: any; |
|
|
|
|
|
|
|
private $legendElem: any; |
|
|
|
|
|
|
|
|
|
|
|
panelDefaults = { |
|
|
|
panelDefaults = { |
|
|
|
// datasource name, null = default datasource
|
|
|
|
// datasource name, null = default datasource
|
|
|
|
datasource: null, |
|
|
|
datasource: null, |
|
|
|
|
|
|
|
hasticDatasource: null, |
|
|
|
// sets client side (flot) or native graphite png renderer (png)
|
|
|
|
// sets client side (flot) or native graphite png renderer (png)
|
|
|
|
renderer: 'flot', |
|
|
|
renderer: 'flot', |
|
|
|
yaxes: [ |
|
|
|
yaxes: [ |
|
|
@ -180,21 +184,17 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
this.rebindKeys(); |
|
|
|
this.rebindKeys(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getBackendURL(): Promise<string> { |
|
|
|
getBackendURL(): string { |
|
|
|
if(this._backendUrl !== undefined) { |
|
|
|
const datasourceId = this.panel.hasticDatasource; |
|
|
|
return this._backendUrl; |
|
|
|
if(datasourceId !== undefined && datasourceId !== null) { |
|
|
|
|
|
|
|
const datasource = _.find(this._hasticDatasources, { id: datasourceId }); |
|
|
|
|
|
|
|
if(datasource.access === 'proxy') { |
|
|
|
|
|
|
|
return `/api/datasources/proxy/${datasource.id}`; |
|
|
|
} |
|
|
|
} |
|
|
|
var data = await this.backendSrv.get('api/plugins/corpglory-hastic-app/settings'); |
|
|
|
return datasource.url; |
|
|
|
if(data.jsonData === undefined || data.jsonData === null) { |
|
|
|
|
|
|
|
return undefined; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
let val = data.jsonData.hasticServerUrl; |
|
|
|
|
|
|
|
if(val === undefined || val === null) { |
|
|
|
|
|
|
|
return undefined; |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
} |
|
|
|
val = val.replace(/\/+$/, ""); |
|
|
|
|
|
|
|
return val; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async updateAnalyticUnitTypes() { |
|
|
|
async updateAnalyticUnitTypes() { |
|
|
|
const analyticUnitTypes = await this.analyticService.getAnalyticUnitTypes(); |
|
|
|
const analyticUnitTypes = await this.analyticService.getAnalyticUnitTypes(); |
|
|
@ -210,26 +210,11 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
return _.keys(this._analyticUnitTypes); |
|
|
|
return _.keys(this._analyticUnitTypes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _checkBackendUrlOk(backendURL: string): boolean { |
|
|
|
|
|
|
|
if(backendURL === null || backendURL === undefined || backendURL === '') { |
|
|
|
|
|
|
|
appEvents.emit( |
|
|
|
|
|
|
|
'alert-warning', |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
`hasticServerUrl is missing`, |
|
|
|
|
|
|
|
`Please set it in config. More info: https://github.com/hastic/hastic-grafana-app/wiki/Getting-started` |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async runBackendConnectivityCheck() { |
|
|
|
async runBackendConnectivityCheck() { |
|
|
|
let backendURL = await this.getBackendURL(); |
|
|
|
const backendURL = this.getBackendURL(); |
|
|
|
if(!this._checkBackendUrlOk(backendURL)) { |
|
|
|
|
|
|
|
return; |
|
|
|
try { |
|
|
|
} |
|
|
|
const connected = await this.analyticService.isBackendOk(); |
|
|
|
let connected = await this.analyticService.isBackendOk(); |
|
|
|
|
|
|
|
if(connected) { |
|
|
|
if(connected) { |
|
|
|
this.updateAnalyticUnitTypes(); |
|
|
|
this.updateAnalyticUnitTypes(); |
|
|
|
appEvents.emit( |
|
|
|
appEvents.emit( |
|
|
@ -241,22 +226,18 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch(err) { |
|
|
|
async link(scope, elem, attrs, ctrl) { |
|
|
|
console.error(err); |
|
|
|
|
|
|
|
} |
|
|
|
this.processor = new DataProcessor(this.panel); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let backendURL = await this.getBackendURL(); |
|
|
|
|
|
|
|
if(!this._checkBackendUrlOk(backendURL)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.analyticService = new AnalyticService(backendURL, this.$http); |
|
|
|
async link(scope, elem, attrs, ctrl) { |
|
|
|
|
|
|
|
this._datasources = {}; |
|
|
|
this.runBackendConnectivityCheck(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.analyticsController = new AnalyticController(this.panel, this.analyticService, this.events); |
|
|
|
this.$graphElem = $(elem[0]).find('#graphPanel'); |
|
|
|
|
|
|
|
this.$legendElem = $(elem[0]).find('#graphLegend'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.onHasticDatasourceChange(); |
|
|
|
|
|
|
|
|
|
|
|
this.events.on('render', this.onRender.bind(this)); |
|
|
|
this.events.on('render', this.onRender.bind(this)); |
|
|
|
this.events.on('data-received', this.onDataReceived.bind(this)); |
|
|
|
this.events.on('data-received', this.onDataReceived.bind(this)); |
|
|
@ -281,8 +262,6 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
this.$scope.$digest(); |
|
|
|
this.$scope.$digest(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this._datasources = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appEvents.on('ds-request-response', data => { |
|
|
|
appEvents.on('ds-request-response', data => { |
|
|
|
let requestConfig = data.config; |
|
|
|
let requestConfig = data.config; |
|
|
|
|
|
|
|
|
|
|
@ -294,19 +273,6 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
type: undefined |
|
|
|
type: undefined |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.analyticsController.fetchAnalyticUnitsStatuses(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $graphElem = $(elem[0]).find('#graphPanel'); |
|
|
|
|
|
|
|
var $legendElem = $(elem[0]).find('#graphLegend'); |
|
|
|
|
|
|
|
this._graphRenderer = new GraphRenderer( |
|
|
|
|
|
|
|
$graphElem, this.timeSrv, this.contextSrv, this.$scope |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
this._graphLegend = new GraphLegend($legendElem, this.popoverSrv, this.$scope); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._updatePanelInfo(); |
|
|
|
|
|
|
|
this.analyticsController.updateServerInfo(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onInitEditMode() { |
|
|
|
onInitEditMode() { |
|
|
@ -329,6 +295,27 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
actions.push({ text: 'Toggle legend', click: 'ctrl.toggleLegend()' }); |
|
|
|
actions.push({ text: 'Toggle legend', click: 'ctrl.toggleLegend()' }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async onHasticDatasourceChange() { |
|
|
|
|
|
|
|
this.processor = new DataProcessor(this.panel); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this._fetchHasticDatasources(); |
|
|
|
|
|
|
|
const backendURL = this.getBackendURL(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.analyticService = new AnalyticService(backendURL, this.$http); |
|
|
|
|
|
|
|
this.runBackendConnectivityCheck(); |
|
|
|
|
|
|
|
this.analyticsController = new AnalyticController(this.panel, this.analyticService, this.events); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.analyticsController.fetchAnalyticUnitsStatuses(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._graphRenderer = new GraphRenderer( |
|
|
|
|
|
|
|
this.$graphElem, this.timeSrv, this.contextSrv, this.$scope |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
this._graphLegend = new GraphLegend(this.$legendElem, this.popoverSrv, this.$scope); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._updatePanelInfo(); |
|
|
|
|
|
|
|
this.analyticsController.updateServerInfo(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
issueQueries(datasource) { |
|
|
|
issueQueries(datasource) { |
|
|
|
// this.annotationsPromise = this.annotationsSrv.getAnnotations({
|
|
|
|
// this.annotationsPromise = this.annotationsSrv.getAnnotations({
|
|
|
|
// dashboard: this.dashboard,
|
|
|
|
// dashboard: this.dashboard,
|
|
|
@ -385,15 +372,17 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.analyticsController !== undefined) { |
|
|
|
var loadTasks = [ |
|
|
|
var loadTasks = [ |
|
|
|
// this.annotationsPromise,
|
|
|
|
// this.annotationsPromise,
|
|
|
|
this.analyticsController.fetchAnalyticUnitsSegments(+this.range.from, +this.range.to) |
|
|
|
this.analyticsController.fetchAnalyticUnitsSegments(+this.range.from, +this.range.to) |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
var results = await Promise.all(loadTasks); |
|
|
|
await Promise.all(loadTasks); |
|
|
|
this.loading = false; |
|
|
|
this.loading = false; |
|
|
|
// this.annotations = results[0].annotations;
|
|
|
|
// this.annotations = results[0].annotations;
|
|
|
|
this.render(this.seriesList); |
|
|
|
this.render(this.seriesList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -657,7 +646,7 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
|
|
|
|
|
|
|
|
private async _updatePanelInfo() { |
|
|
|
private async _updatePanelInfo() { |
|
|
|
const datasource = await this._getDatasourceByName(this.panel.datasource); |
|
|
|
const datasource = await this._getDatasourceByName(this.panel.datasource); |
|
|
|
const backendUrl = await this.getBackendURL(); |
|
|
|
const backendUrl = this.getBackendURL(); |
|
|
|
|
|
|
|
|
|
|
|
let grafanaVersion = 'unknown'; |
|
|
|
let grafanaVersion = 'unknown'; |
|
|
|
if(_.has(window, 'grafanaBootData.settings.buildInfo.version')) { |
|
|
|
if(_.has(window, 'grafanaBootData.settings.buildInfo.version')) { |
|
|
@ -691,6 +680,16 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async _fetchHasticDatasources() { |
|
|
|
|
|
|
|
this._hasticDatasources = await this.backendSrv.get('/api/datasources'); |
|
|
|
|
|
|
|
this._hasticDatasources = this._hasticDatasources.filter(ds => ds.type === 'corpglory-hastic-datasource'); |
|
|
|
|
|
|
|
this.$scope.$digest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get hasticDatasources() { |
|
|
|
|
|
|
|
return this._hasticDatasources; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get panelInfo() { |
|
|
|
get panelInfo() { |
|
|
|
return this._panelInfo; |
|
|
|
return this._panelInfo; |
|
|
|
} |
|
|
|
} |
|
|
|