Menu

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Enterprise Open source

DataSourceSrv interface

This is the entry point for communicating with a datasource that is added as a plugin (both external and internal). Via this service you will get access to the DataSourceApi that have a rich API for communicating with the datasource.

Signature

typescript
export interface DataSourceSrv 

Import

typescript
import { DataSourceSrv } from '@grafana/runtime';

Methods

MethodDescription
get(name, scopedVars)
getAll()Get all data sources
getDataSourceSettingsByUid(uid)Returns metadata based on UID.
getExternal()Get all data sources except for internal ones that usually should not be listed like mixed data source.

get method

Signature

typescript
get(name?: string | null, scopedVars?: ScopedVars): Promise<DataSourceApi>;

Parameters

ParameterTypeDescription
namestring | nullname of the datasource plugin you want to use.
scopedVarsScopedVarsvariables used to interpolate a templated passed as name.

Returns:

Promise<DataSourceApi>

getAll method

Get all data sources

Signature

typescript
getAll(): DataSourceInstanceSettings[];

Returns:

DataSourceInstanceSettings[]

getDataSourceSettingsByUid method

Returns metadata based on UID.

Signature

typescript
getDataSourceSettingsByUid(uid: string): DataSourceInstanceSettings | undefined;

Parameters

ParameterTypeDescription
uidstring

Returns:

DataSourceInstanceSettings | undefined

getExternal method

Get all data sources except for internal ones that usually should not be listed like mixed data source.

Signature

typescript
getExternal(): DataSourceInstanceSettings[];

Returns:

DataSourceInstanceSettings[]