Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Commit f447b74

Browse files
committed
add better information to readme
1 parent 50d5180 commit f447b74

File tree

6 files changed

+59
-36
lines changed

6 files changed

+59
-36
lines changed

README.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,62 @@
1-
# Grafana Data Source Plugin Template
1+
# Nodegraph API Plugin for Grafana
22

33
[![Build](https://github.com/grafana/grafana-starter-datasource/workflows/CI/badge.svg)](https://github.com/grafana/grafana-starter-datasource/actions?query=workflow%3A%22CI%22)
44

5-
This template is a starting point for building Grafana Data Source Plugins
5+
This plugin provides a datasource to connect a REST API to [nodegraph](https://grafana.com/docs/grafana/latest/visualizations/node-graph/) panel of Grafana.
6+
7+
![](src/img/graph-example.png)
68

79
## What is Grafana Data Source Plugin?
810

911
Grafana supports a wide range of data sources, including Prometheus, MySQL, and even Datadog. There’s a good chance you can already visualize metrics from the systems you have set up. In some cases, though, you already have an in-house metrics solution that you’d like to add to your Grafana dashboards. Grafana Data Source Plugins enables integrating such solutions with Grafana.
1012

13+
14+
1115
## Getting started
1216

17+
1. Use Grafana 7.4 or higher
18+
19+
- Download and place the datasouce in grafana/plugins directory.
20+
21+
This plugin is not signed yet, Grafana will not allow loading it by default. you should enable it by adding:
22+
23+
for example, if you are using Grafana with containers, add:
24+
25+
```yaml
26+
-e "GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=hamedkarbasi93-nodegraphapi-datasource"
27+
```
28+
29+
2. You can now add the the data source. Just enter the url of your API app and push "Save & Test". You will get an error in case of connection failure.
30+
31+
> Note: The browser should have access to the application not the grafana server.
32+
33+
![](src/img/add-datasource.png)
34+
35+
3. In grafana dashboard, pick the Nodegraph panel and have the graph visualization.
36+
37+
## API Configuration
38+
39+
You REST API application should return data in the following format:
40+
41+
endpoint: `/api/fetchgraph`
42+
43+
content type: `application/json`
44+
45+
Data Format example:
46+
47+
```json
48+
{"edges":[{"id":"1","mainStat":"53/s","source":"1","target":"2"}],"nodes":[{"arc__failed":0.7,"arc__passed":0.3,"detail__zone":"load","id":"1","subTitle":"instance:#2","title":"Service1"},{"arc__failed":0.5,"arc__passed":0.5,"detail__zone":"transform","id":"2","subTitle":"instance:#3","title":"Service2"}]}
49+
```
50+
51+
For more detail of the variables please visit [here](https://grafana.com/docs/grafana/latest/visualizations/node-graph/#data-api).
52+
53+
## Compiling the data source by yourself
54+
1355
1. Install dependencies
1456

15-
```bash
16-
yarn install
17-
```
57+
```bash
58+
yarn install
59+
```
1860

1961
2. Build plugin in development mode or run in watch mode
2062

@@ -40,3 +82,14 @@ Grafana supports a wide range of data sources, including Prometheus, MySQL, and
4082
- [Grafana documentation](https://grafana.com/docs/)
4183
- [Grafana Tutorials](https://grafana.com/tutorials/) - Grafana Tutorials are step-by-step guides that help you make the most of Grafana
4284
- [Grafana UI Library](https://developers.grafana.com/ui) - UI components to help you build interfaces using Grafana Design System
85+
86+
87+
88+
## Contributing
89+
90+
Thank you for considering contributing! If you find an issue, or have a better way to do something, feel free to open an issue, or a PR.
91+
92+
## License
93+
94+
This repository is open-sourced software licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
95+

src/ConfigEditor.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ interface Props extends DataSourcePluginOptionsEditorProps<MyDataSourceOptions>
1010
interface State {}
1111

1212
export class ConfigEditor extends PureComponent<Props, State> {
13-
onPathChange = (event: ChangeEvent<HTMLInputElement>) => {
14-
const { onOptionsChange, options } = this.props;
15-
const jsonData = {
16-
...options.jsonData,
17-
path: event.target.value,
18-
};
19-
onOptionsChange({ ...options, jsonData });
20-
};
21-
2213
// Secure field (only sent to the backend)
2314
onAPIKeyChange = (event: ChangeEvent<HTMLInputElement>) => {
2415
const { onOptionsChange, options } = this.props;
@@ -60,16 +51,6 @@ export class ConfigEditor extends PureComponent<Props, State> {
6051

6152
return (
6253
<div className="gf-form-group">
63-
<div className="gf-form">
64-
<FormField
65-
label="Path"
66-
labelWidth={6}
67-
inputWidth={20}
68-
onChange={this.onPathChange}
69-
value={jsonData.path || ''}
70-
placeholder="json field returned to frontend"
71-
/>
72-
</div>
7354
<div className="gf-form">
7455
<FormField
7556
label="URL"

src/QueryEditor.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ export class QueryEditor extends PureComponent<Props> {
2323
onRunQuery();
2424
};
2525

26-
onFrequencyChange = (event: ChangeEvent<HTMLInputElement>) => {
27-
const { onChange, query, onRunQuery } = this.props;
28-
onChange({ ...query, frequency: parseFloat(event.target.value) });
29-
// executes the query
30-
onRunQuery();
31-
};
32-
3326
render() {
3427
const query = defaults(this.props.query, defaultQuery);
35-
const { queryText, constant, frequency } = query;
28+
const { queryText, constant } = query;
3629
return (
3730
<div className="gf-form">
3831
<FormField
@@ -50,7 +43,6 @@ export class QueryEditor extends PureComponent<Props> {
5043
label="Query Text"
5144
tooltip="Not used yet"
5245
/>
53-
<FormField width={4} value={frequency} onChange={this.onFrequencyChange} label="Frequency" type="number" />
5446
</div>
5547
);
5648
}

src/img/add-datasource.png

20.8 KB
Loading

src/img/graph-example.png

41.3 KB
Loading

src/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ import { DataQuery, DataSourceJsonData } from '@grafana/data';
33
export interface MyQuery extends DataQuery {
44
queryText?: string;
55
constant: number;
6-
frequency: number;
76
}
87

98
export const defaultQuery: Partial<MyQuery> = {
109
constant: 6.5,
11-
frequency: 1.0,
1210
};
1311

1412
/**
1513
* These are options configured for each DataSource instance
1614
*/
1715
export interface MyDataSourceOptions extends DataSourceJsonData {
18-
path?: string;
1916
baseUrl?: string;
2017
}
2118

0 commit comments

Comments
 (0)