Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display system status counts #6

Merged
merged 27 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
14b44b8
Initial commit
mure Jun 29, 2023
c0fdbb3
Templating
mure Jul 5, 2023
f609f89
Remove tag
mure Jul 5, 2023
b124b23
Add Data Frames data source
mure Jul 6, 2023
bce2267
Downloaded plugin template
ggracechoi Jul 17, 2023
2813cd8
solved merge conflicts
ggracechoi Jul 18, 2023
c94f08a
Add systems data source from template
mure Jul 18, 2023
4f11242
Edited README with a brief overview of plugin
ggracechoi Jul 19, 2023
2bc3048
Merge branch 'users/grchoi/systems-datasource' of https://github.com/…
ggracechoi Jul 19, 2023
130e98d
Updated proper README
ggracechoi Jul 19, 2023
4a8d748
remove workflows
mure Jul 19, 2023
0b4c173
testDataSource method completed
ggracechoi Jul 20, 2023
1501c2e
Merge remote-tracking branch 'origin/main' into users/grchoi/systems-…
ggracechoi Jul 20, 2023
6cced05
Merge branch 'users/grchoi/systems-datasource' of https://github.com/…
ggracechoi Jul 20, 2023
453cabf
Updated type.ts
ggracechoi Jul 21, 2023
d9d1478
Updated SystemQueryEditor.tsx
ggracechoi Jul 21, 2023
4a02579
Before W2
ggracechoi Jul 21, 2023
b45c22e
W2 done
ggracechoi Jul 24, 2023
e310e35
Deleted old code
ggracechoi Jul 24, 2023
512798b
Merge remote-tracking branch 'origin/main' into users/grchoi/systems-…
ggracechoi Jul 24, 2023
7421def
Update src/datasources/system/components/SystemQueryEditor.tsx
ggracechoi Jul 24, 2023
bc6eeb9
Update src/datasources/system/types.ts
ggracechoi Jul 24, 2023
5fb1b99
added getDefaultQuery
ggracechoi Jul 25, 2023
4bd162e
added utils.ts
ggracechoi Jul 25, 2023
0ef8ac7
Merge branch 'users/grchoi/systems-datasource' of https://github.com/…
ggracechoi Jul 25, 2023
8e50a42
added utils.test.ts
ggracechoi Jul 25, 2023
53e748e
ran lint
ggracechoi Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/datasources/system/SystemDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import { TestingStatus, getBackendSrv } from '@grafana/runtime';

import { SystemQuery } from './types';
import { QueryType, SystemQuery, SystemSummary } from './types';

export class SystemDataSource extends DataSourceApi<SystemQuery> {
baseUrl: string;
Expand All @@ -24,15 +24,26 @@ export class SystemDataSource extends DataSourceApi<SystemQuery> {
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 },
],
});
});
const data = await Promise.all(options.targets.map(async (target) => {
if (target.queryClass === QueryType.Summary) {
var summaryResponse = await getBackendSrv().get<SystemSummary>(this.baseUrl + '/get-systems-summary');
return new MutableDataFrame({
refId: target.refId,
fields: [
{ name: 'Connected Count', values: [summaryResponse.connectedCount], type: FieldType.number },
ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
{ name: 'Disconnected Count', values: [summaryResponse.disconnectedCount], type: FieldType.number },
],
});
} else {
return new MutableDataFrame({
refId: target.refId,
fields: [
{ name: 'Time', values: [from, to], type: FieldType.time },
{ name: 'Value', values: [1, 2], type: FieldType.number },
ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
],
});
}
}));

return { data };
}
Expand Down
36 changes: 17 additions & 19 deletions src/datasources/system/components/SystemQueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import React, { ChangeEvent } from 'react';
import { InlineField, Input } from '@grafana/ui';
import React from 'react';
import { InlineField, InlineFieldRow, RadioButtonGroup } from '@grafana/ui';
import { QueryEditorProps } from '@grafana/data';
import { SystemDataSource } from '../SystemDataSource';
import { SystemQuery } from '../types';
import { QueryType, SystemQuery } from '../types';

type Props = QueryEditorProps<SystemDataSource, SystemQuery>;

const QUERY_TYPES = [
{label: "Metadata", value: QueryType.Metadata},
{label: "Summary", value: QueryType.Summary}
]

ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
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
const onQueryTypeChange = (value: QueryType) => {
onChange({ ...query, queryClass: value })
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>
<InlineFieldRow >
<InlineField label="Query Type">
ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
<RadioButtonGroup options={QUERY_TYPES} onChange={onQueryTypeChange} value={query.queryClass} />
ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
</InlineField>
ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
</InlineFieldRow>
</div>
);
}
13 changes: 11 additions & 2 deletions src/datasources/system/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { DataQuery } from '@grafana/schema'

export enum QueryType {
Metadata = "Metadata",
cameronwaterman marked this conversation as resolved.
Show resolved Hide resolved
Summary = "Summary"
}

export interface SystemQuery extends DataQuery {
queryText?: string;
constant: number;
queryClass: QueryType
ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
}

ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
export interface SystemSummary {
connectedCount: number,
disconnectedCount: number
ggracechoi marked this conversation as resolved.
Show resolved Hide resolved
}
Loading