Legacy data source plugins

    To interact with the rest of grafana the plugins module file can export 4 different components.

    • Datasource (Required)
    • QueryCtrl (Required)
    • AnnotationsQueryCtrl

    Plugin json

    There are two data source specific settings for the plugin.json

    These settings indicate what kind of data the plugin can deliver. At least one of them has to be true.

    The javascript object that communicates with the database and transforms data to times series.

    1. testDatasource(); // used by data source configuration page to make sure the connection is working
    2. annotationQuery(options); // used by dashboards to get annotations
    3. metricFindQuery(options); // used by query editor to get metric suggestions.

    When a user clicks on the Save & Test button when adding a new data source, the details are first saved to the database and then the testDatasource function that is defined in your data source plugin will be called. It is recommended that this function makes a query to the data source that will also test that the authentication details are correct. This is so the data source is correctly configured when the user tries to write a query in a new dashboard.

    Request object passed to datasource.query function:

    There are two different kinds of results for data sources: time series and table. Time series is the most common format and is supported by all data sources and panels. Table format is only supported by the InfluxDB data source and table panel. But we might see more of this in the future.

    Time series response from datasource.query. An array of:

    1. [
    2. {
    3. "target": "upper_75",
    4. "datapoints": [
    5. [622, 1450754160000],
    6. [365, 1450754220000]
    7. },
    8. {
    9. "datapoints": [
    10. [861, 1450754160000],
    11. [767, 1450754220000]
    12. ]
    13. }
    14. ]

    Table response from datasource.query. An array of:

    1. {
    2. "rangeRaw": { "from": "now-3h", "to": "now" },
    3. "annotation": {
    4. "datasource": "generic datasource",
    5. "enable": true,
    6. "name": "annotation name"
    7. },
    8. }

    Expected result from datasource.annotationQuery:

    QueryCtrl

    A JavaScript class that will be instantiated and treated as an Angular controller when the user edits metrics in a panel. This class has to inherit from the app/plugins/sdk.QueryCtrl class.

    Requires a static template or templateUrl variable which will be rendered as the view for this controller.

    A JavaScript class that will be instantiated and treated as an Angular controller when a user tries to edit or create a new data source of this type.

    Requires a static template or variable which will be rendered as the view for this controller.

    AnnotationsQueryCtrl

    Requires a static template or templateUrl variable which will be rendered as the view for this controller. The fields that are bound to this controller are then sent to the Database objects annotationQuery function.