-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Systems data source template (#3)
Co-authored-by: Carson Moore <carson.moore@ni.com>
- Loading branch information
1 parent
f90ca3c
commit 6e3c79e
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Systemlink System data source | ||
|
||
This is a plugin for the Systems Management service. It allows you to: | ||
- Populate a | ||
[query variable](https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#add-a-query-variable) | ||
with a list of systems connected to the server | ||
- Visualize system connection status counts on a dashboard | ||
- Visualize system metadata on a dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
DataQueryRequest, | ||
DataQueryResponse, | ||
DataSourceApi, | ||
DataSourceInstanceSettings, | ||
MutableDataFrame, | ||
FieldType, | ||
} from '@grafana/data'; | ||
|
||
import { TestingStatus, getBackendSrv } from '@grafana/runtime'; | ||
|
||
import { SystemQuery } from './types'; | ||
|
||
export class SystemDataSource extends DataSourceApi<SystemQuery> { | ||
baseUrl: string; | ||
constructor(private instanceSettings: DataSourceInstanceSettings) { | ||
super(instanceSettings); | ||
// TODO: set base path of the service | ||
this.baseUrl = this.instanceSettings.url + '/nifoo/v2'; | ||
} | ||
|
||
async query(options: DataQueryRequest<SystemQuery>): Promise<DataQueryResponse> { | ||
const { range } = options; | ||
const from = range!.from.valueOf(); | ||
const to = range!.to.valueOf(); | ||
|
||
// Return a constant for each query. | ||
const data = options.targets.map((target) => { | ||
return new MutableDataFrame({ | ||
refId: target.refId, | ||
fields: [ | ||
{ name: 'Time', values: [from, to], type: FieldType.time }, | ||
{ name: 'Value', values: [target.constant, target.constant], type: FieldType.number }, | ||
], | ||
}); | ||
}); | ||
|
||
return { data }; | ||
} | ||
|
||
async testDatasource(): Promise<TestingStatus> { | ||
// TODO: Implement a health and authentication check | ||
await getBackendSrv().get(this.baseUrl + '/bar'); | ||
return { status: 'success', message: 'Data source connected and authentication successful!' }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { ChangeEvent } from 'react'; | ||
import { InlineField, Input } from '@grafana/ui'; | ||
import { QueryEditorProps } from '@grafana/data'; | ||
import { SystemDataSource } from '../SystemDataSource'; | ||
import { SystemQuery } from '../types'; | ||
|
||
type Props = QueryEditorProps<SystemDataSource, SystemQuery>; | ||
|
||
export function SystemQueryEditor({ query, onChange, onRunQuery }: Props) { | ||
const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, queryText: event.target.value }); | ||
}; | ||
|
||
const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, constant: parseFloat(event.target.value) }); | ||
// executes the query | ||
onRunQuery(); | ||
}; | ||
|
||
const { queryText, constant } = query; | ||
|
||
return ( | ||
<div className="gf-form"> | ||
<InlineField label="Constant"> | ||
<Input onChange={onConstantChange} value={constant} width={8} type="number" step="0.1" /> | ||
</InlineField> | ||
<InlineField label="Query Text" labelWidth={16} tooltip="Not used yet"> | ||
<Input onChange={onQueryTextChange} value={queryText || ''} /> | ||
</InlineField> | ||
</div> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DataSourcePlugin } from '@grafana/data'; | ||
import { SystemDataSource } from './SystemDataSource'; | ||
import { SystemQueryEditor } from './components/SystemQueryEditor'; | ||
import { HttpConfigEditor } from 'core/HttpConfigEditor'; | ||
|
||
export const plugin = new DataSourcePlugin(SystemDataSource) | ||
.setConfigEditor(HttpConfigEditor) | ||
.setQueryEditor(SystemQueryEditor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { DataQuery } from '@grafana/schema' | ||
|
||
export interface SystemQuery extends DataQuery { | ||
queryText?: string; | ||
constant: number; | ||
} |