Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/grafana/v7.2/packages_api/runtime/datasourcesrv.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana/v7.2/packages_api/runtime/datasourcesrv/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
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.
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
export interface DataSourceSrv Import
import { DataSourceSrv } from '@grafana/runtime';Methods
| Method | Description |
|---|---|
| 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
get(name?: string | null, scopedVars?: ScopedVars): Promise<DataSourceApi>;Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | null | name of the datasource plugin you want to use. |
| scopedVars | ScopedVars | variables used to interpolate a templated passed as name. |
Returns:
Promise<DataSourceApi>
getAll method
Get all data sources
Signature
getAll(): DataSourceInstanceSettings[];Returns:
DataSourceInstanceSettings[]
getDataSourceSettingsByUid method
Returns metadata based on UID.
Signature
getDataSourceSettingsByUid(uid: string): DataSourceInstanceSettings | undefined;Parameters
| Parameter | Type | Description |
|---|---|---|
| uid | string |
Returns:
DataSourceInstanceSettings | undefined
getExternal method
Get all data sources except for internal ones that usually should not be listed like mixed data source.
Signature
getExternal(): DataSourceInstanceSettings[];Returns:
DataSourceInstanceSettings[]