grafana / scenes

Build Grafana dashboards directly in your Grafana app plugins.
https://grafana.com/developers/scenes
Apache License 2.0
133 stars 20 forks source link

How to custom Datasource for prometheuse #869

Closed Ducchrist closed 1 month ago

Ducchrist commented 1 month ago

How do i make in my constants.ts a custom datasource with a specific ip prometheus. type: Prometheus URL: http://x.x.x.x:9090 HTTPmethode: POST... do i use this custom code and how to use it since documentation dont talk much about it. https://github.com/grafana/scenes/blob/c32882c8b4d0f6fad2dde39e5ab8e5822a989372/docusaurus/docs/advanced-custom-datasource.md?plain=1#L2

class MyCustomDS extends RuntimeDataSource {
  query(request: DataQueryRequest<DataQuery>): Promise<DataQueryResponse> | Observable<DataQueryResponse> {
    return Promise.resolve({
      state: LoadingState.Done,
      data: [
        {
          fields: [{ name: 'Values', type: FieldType.number, values: [1, 2, 3], config: {} }],
          length: 3,
        },
      ],
    });
  }

  testDatasource(): Promise<TestDataSourceResponse> {
    return Promise.resolve({ status: 'success', message: 'OK' });
  }
}

// Important to specify a unique pluginId and uid for your data source that is unlikely to confict with any other scene app plugin.
sceneUtils.registerRuntimeDataSource({ dataSource: new MyCustomDS('my-custom-ds', 'my-custom-ds-uid') });