grafanaclient: github.com/adejoux/grafanaclient Index | Examples | Files

package grafanaclient

import "github.com/adejoux/grafanaclient"

Package grafanaclient provide a simple API to manage Grafana 2.0 DataSources and Dashboards in Go. It's using Grafana 2.0 REST API.

Index

Examples

Package Files

api.go

func NewGroupBy Uses

func NewGroupBy() []GroupBy

NewGroupBy initialize a GroupBy structure

type Annotation Uses

type Annotation struct {
    Enable bool          `json:"enable"`
    List   []interface{} `json:"list"`
}

A Annotation contains the current annotations of a dashboard

type Dashboard Uses

type Dashboard struct {
    Editable        bool          `json:"editable"`
    HideControls    bool          `json:"hideControls"`
    ID              int           `json:"id"`
    OriginalTitle   string        `json:"originalTitle"`
    Refresh         string        `json:"refresh"`
    Annotations     Annotation    `json:"annotations"`
    SchemaVersion   int           `json:"schemaVersion"`
    SharedCrosshair bool          `json:"sharedCrosshair"`
    Style           string        `json:"style"`
    Templating      Templating    `json:"templating,omitempty" toml:"templates"`
    Tags            []interface{} `json:"tags"`
    GTime           GTime         `json:"time" toml:"time"`
    Rows            []Row         `json:"rows" toml:"row"`
    Title           string        `json:"title"`
    Version         int           `json:"version"`
    Timezone        string        `json:"timezone"`
}

A Dashboard contains the Dashboard structure.

func ConvertTemplate Uses

func ConvertTemplate(file string) (dashboard Dashboard, err error)

ConvertTemplate converts a string to a dashboard structure

func (*Dashboard) AddRow Uses

func (db *Dashboard) AddRow(row Row)

AddRow add a row to an existing dashboard. It takes a Row struct in parameter.

func (*Dashboard) SetTimeFrame Uses

func (db *Dashboard) SetTimeFrame(from time.Time, to time.Time)

SetTimeFrame setup the dashboard timeframe.

type DashboardResult Uses

type DashboardResult struct {
    Meta  Meta      `json:"meta"`
    Model Dashboard `json:"model"`
}

A DashboardResult contains the response from Grafana when requesting a Dashboard. It contains the Dashboard itself and the meta data.

type DashboardUploader Uses

type DashboardUploader struct {
    Dashboard Dashboard `json:"dashboard"`
    Overwrite bool      `json:"overwrite"`
}

A DashboardUploader encapsulates a complete Dashboard

type DataSource Uses

type DataSource struct {
    ID                int    `json:"Id"`
    OrgID             int    `json:"orgId"`
    Name              string `json:"name"`
    Type              string `json:"type"`
    Access            string `json:"access"`
    URL               string `json:"url"`
    Password          string `json:"password"`
    User              string `json:"user"`
    Database          string `json:"database"`
    BasicAuth         bool   `json:"basicAuth"`
    BasicAuthUser     string `json:"basicAuthUser"`
    BasicAuthPassword string `json:"basicAuthPassword"`
    IsDefault         bool   `json:"isDefault"`
}

A DataSource contains the json structure of Grafana DataSource

type DataSourcePlugin Uses

type DataSourcePlugin struct {
    Annotations struct {
        Enable bool          `json:"enable"`
        List   []interface{} `json:"list"`
    }   `json:"annotations"`
    Module      string `json:"module"`
    Name        string `json:"name"`
    Partials    PluginPartial
    PluginType  string `json:"pluginType"`
    ServiceName string `json:"serviceName"`
    Type        string `json:"type"`
}

A DataSourcePlugin contains the json structure of Grafana DataSource plugin

type DataSourcePlugins Uses

type DataSourcePlugins map[string]DataSourcePlugin

A DataSourcePlugins contains a map of DataSourcePlugin

type GTime Uses

type GTime struct {
    From string `json:"from"`
    Now  bool   `json:"now"`
    To   string `json:"to"`
}

A GTime contains the Dadhboard informations on the time frame of the data.

func NewGTime Uses

func NewGTime() GTime

NewGTime create a default time window for Grafana

type GrafanaError Uses

type GrafanaError struct {
    Code        int
    Description string
}

GrafanaError is a error structure to handle error messages in this library

func (GrafanaError) Error Uses

func (h GrafanaError) Error() string

Error generate a text error message. If Code is zero, we know it's not a http error.

type GrafanaMessage Uses

type GrafanaMessage struct {
    Message string `json:"message"`
}

A GrafanaMessage contains the json error message received when http request failed

type GroupBy Uses

type GroupBy struct {
    Type     string   `json:"type"`
    Interval string   `json:"interval,omitempty"`
    Params   []string `json:"params"`
}

A GroupBy struct is used to setup the group by part of the query

type Legend Uses

type Legend struct {
    Show         bool `json:"show"`
    Values       bool `json:"values"`
    Min          bool `json:"min"`
    Max          bool `json:"max"`
    Current      bool `json:"current"`
    Total        bool `json:"total"`
    Avg          bool `json:"avg"`
    AlignAsTable bool `json:"alignAsTable"`
}

A Legend specify the legend options used by the Panel

func NewLegend Uses

func NewLegend() Legend

NewLegend create a new Grafana legend with default values

type Login Uses

type Login struct {
    User     string `json:"user"`
    Email    string `json:"email"`
    Password string `json:"password"`
}

A Login contains the json structure of Grafana authentication request

type Meta Uses

type Meta struct {
    Created    string `json:"created"`
    Expires    string `json:"expires"`
    IsHome     bool   `json:"isHome"`
    IsSnapshot bool   `json:"isSnapshot"`
    IsStarred  bool   `json:"isStarred"`
    Slug       string `json:"slug"`
}

A Meta contains a Dashboard metadata.

type Metric Uses

type Metric struct {
    Measurement string
    Fields      []string
    Hosts       []string
    Alias       []string
}

A Metric is only used in TOML templates to define the targets to create

type Panel Uses

type Panel struct {
    Content         string           `json:"content"`
    Editable        bool             `json:"editable"`
    Error           bool             `json:"error"`
    ID              int              `json:"id"`
    Mode            string           `json:"mode"`
    Span            int              `json:"span"`
    Style           struct{}         `json:"style"`
    Title           string           `json:"title"`
    Type            string           `json:"type"`
    Fill            int              `json:"fill"`
    Stack           bool             `json:"stack"`
    Targets         []Target         `json:"targets" toml:"target"`
    Metrics         []Metric         `json:"-" toml:"metric"`
    SeriesOverrides []SeriesOverride `json:"seriesOverrides,omitempty" toml:"override"`
    Tooltip         Tooltip          `json:"tooltip,omitempty"`
    PageSize        int              `json:"pageSize,omitempty" toml:"pageSize,omitempty"`
    Legend          Legend           `json:"legend,omitempty"`
    LeftYAxisLabel  string           `json:"leftYAxisLabel,omitempty"`
    RightYAxisLabel string           `json:"rightYAxisLabel,omitempty"`
    DataSource      string           `json:"datasource,omitempty"`
    NullPointMode   string           `json:"nullPointMode,omitempty"`
    ValueName       string           `json:"valueName,omitempty"`
    Lines           bool             `json:"lines,omitempty"`
    Linewidth       int              `json:"linewidth,omitempty"`
    Points          bool             `json:"points,omitempty"`
    Pointradius     int              `json:"pointradius,omitempty"`
    Bars            bool             `json:"bars,omitempty"`
    Percentage      bool             `json:"percentage,omitempty"`
    SteppedLine     bool             `json:"steppedLine,omitempty"`
    TimeFrom        interface{}      `json:"timeFrom,omitempty"`
    TimeShift       interface{}      `json:"timeShift,omitempty"`
}

A Panel is a component of a Row. It can be a chart, a text or a single stat panel

func NewPanel Uses

func NewPanel() Panel

NewPanel create a new Grafana panel with default values

func (*Panel) AddTarget Uses

func (panel *Panel) AddTarget(target Target)

AddTarget add a target to an existing panel. It takes a Panel struct in parameter.

type Plugin Uses

type Plugin struct {
    Name    string `json:"name"`
    Type    string `json:"type"`
    ID      string `json:"id"`
    Enabled bool   `json:"enabled"`
    Pinned  bool   `json:"pinned"`
    Info    struct {
        Author struct {
            Name string `json:"name"`
            URL  string `json:"url"`
        }   `json:"author"`
        Description string      `json:"description"`
        Links       interface{} `json:"links"`
        Logos       struct {
            Small string `json:"small"`
            Large string `json:"large"`
        }   `json:"logos"`
        Screenshots interface{} `json:"screenshots"`
        Version     string      `json:"version"`
        Updated     string      `json:"updated"`
    }   `json:"info"`
    LatestVersion string `json:"latestVersion"`
    HasUpdate     bool   `json:"hasUpdate"`
}

Plugin is a Grafana 3.0 structure for plugins

type PluginPartial Uses

type PluginPartial struct {
    Annotations string `json:"annotations"`
    Config      string `json:"config"`
}

A PluginPartial contains the json structure of Grafana DataSource Plugin Partial

type Plugins Uses

type Plugins []Plugin

Plugins is an array of Plugin

type Row Uses

type Row struct {
    Collapse bool    `json:"collapse"`
    Editable bool    `json:"editable"`
    Height   string  `json:"height"`
    Panels   []Panel `json:"panels" toml:"panel"`
    Title    string  `json:"title"`
}

A Row is a dashboard Row it can contains multiple panels

func NewRow Uses

func NewRow() Row

NewRow create a new Grafana row with default values

func (*Row) AddPanel Uses

func (row *Row) AddPanel(panel Panel)

AddPanel add a panel to an existing row. It takes a Row struct in parameter.

type Select Uses

type Select struct {
    Type   string   `json:"type"`
    Params []string `json:"params"`
}

A Select specify the criteria to perform selection

type Selects Uses

type Selects []Select

Selects array of Select struct

type SeriesOverride Uses

type SeriesOverride struct {
    Alias     string `json:"alias"`
    Stack     bool   `json:"stack"`
    Fill      int    `json:"fill"`
    Transform string `json:"transform"`
}

A SeriesOverride allows to setup specific override by serie

func NewSeriesOverride Uses

func NewSeriesOverride(alias string) SeriesOverride

NewSeriesOverride create a new Grafana series override using the specified alias

type Session Uses

type Session struct {
    User     string
    Password string
    // contains filtered or unexported fields
}

Session contains user credentials, url and a pointer to http client session.

func NewSession Uses

func NewSession(user string, password string, url string) *Session

NewSession creates a new http connection . It includes a cookie jar used to keep session cookies. The URL url specifies the host and request URI.

It returns a Session struct pointer.

func (*Session) CreateDataSource Uses

func (s *Session) CreateDataSource(ds DataSource) (err error)

CreateDataSource creates a Grafana DataSource. It take a DataSource struct in parameter. It returns a error if it cannot perform the creation.

Code:

myurl := "http://localhost:3000"

myds := grafanaclient.DataSource{Name: "testgf",
    Type:     "influxdb_08",
    Access:   "direct",
    URL:      "http://localhost:8086",
    User:     "root",
    Password: "root",
    Database: "test",
}

session := grafanaclient.NewSession("admin", "admin", myurl)
session.DoLogon()
session.CreateDataSource(myds)

func (*Session) DeleteDashboard Uses

func (s *Session) DeleteDashboard(name string) (err error)

DeleteDashboard delete a Grafana Dashboard. First, it try to retrieve it. And if successful, delete it using the slug attribute It returns a error if a problem occurs when deleting the dashboard.

func (*Session) DeleteDataSource Uses

func (s *Session) DeleteDataSource(ds DataSource) (err error)

DeleteDataSource deletes a Grafana DataSource. It take a existing DataSource struct in parameter. It returns a error if it cannot perform the deletion.

Code:

myurl := "http://localhost:3000"

session := grafanaclient.NewSession("admin", "admin", myurl)
session.DoLogon()
ds, _ := session.GetDataSource("testgf")
session.DeleteDataSource(ds)

func (*Session) DoLogon Uses

func (s *Session) DoLogon() (err error)

DoLogon uses a new http connection using the credentials stored in the Session struct. It returns a error if it cannot perform the login.

func (*Session) GetDashboard Uses

func (s *Session) GetDashboard(name string) (dashboard DashboardResult, err error)

GetDashboard get a existing Dashboard by name. It takes a name string in parameter. It return a bytes.Buffer pointer. It returns a error if a problem occurs when trying to retrieve the DataSource.

func (*Session) GetDataSource Uses

func (s *Session) GetDataSource(name string) (ds DataSource, err error)

GetDataSource get a existing DataSource by name. It return a DataSource struct. It returns a error if a problem occurs when trying to retrieve the DataSource.

func (*Session) GetDataSourceList Uses

func (s *Session) GetDataSourceList() (ds []DataSource, err error)

GetDataSourceList return a list of existing Grafana DataSources. It return a array of DataSource struct. It returns a error if it cannot get the DataSource list.

func (*Session) GetDataSourcePlugins Uses

func (s *Session) GetDataSourcePlugins() (plugins DataSourcePlugins, err error)

GetDataSourcePlugins return a list of existing Grafana DataSources. It return a array of DataSource struct. It returns a error if it cannot get the DataSource list.

func (*Session) GetPlugins Uses

func (s *Session) GetPlugins(pluginType string) (plugins Plugins, err error)

GetPlugins get the list of plugins by PluginType

func (*Session) UploadDashboard Uses

func (s *Session) UploadDashboard(dashboard Dashboard, overwrite bool) (err error)

UploadDashboard upload a new Dashboard. It takes a dashboard structure in parameter. It encapsulate it in a DashboardUploader structure. overwrite parameter define if it overwrite existing dashboard. It returns a error if a problem occurs when creating the dashboard.

func (*Session) UploadDashboardString Uses

func (s *Session) UploadDashboardString(dashboard string, overwrite bool) (err error)

UploadDashboardString upload a new Dashboard. It takes a string cotnaining the json structure in parameter. This string will be decoded against a Dashboard struct for validation. If valid, the dashboard structure will be sent to UploadDashboard. overwrite parameter define if it overwrite existing dashboard. It returns a error if a problem occurs when trying to create the dashboard.

type Tag Uses

type Tag struct {
    Condition string `json:"condition"`
    Key       string `json:"key"`
    Value     string `json:"value"`
}

A Tag allows to filter the values

type Target Uses

type Target struct {
    Alias       string    `json:"alias"`
    Hide        bool      `json:"hide"`
    Measurement string    `json:"measurement"`
    GroupBy     []GroupBy `json:"groupBy"`
    Select      []Selects `json:"select,omitempty"`
    Tags        []Tag     `json:"tags"`
    DsType      string    `json:"dsType,omitempty"`
    Transform   string    `json:"transform,omitempty" toml:"transform,omitempty"`
}

A Target specify the metrics used by the Panel

func NewTarget Uses

func NewTarget() Target

NewTarget create a new Grafana target with default values

func (*Target) FilterByTag Uses

func (target *Target) FilterByTag(name string, value string)

FilterByTag add a Tag to an existing target. It takes a name and value strings in parameter.

func (*Target) GroupByTag Uses

func (target *Target) GroupByTag(tag string)

GroupByTag add a group by selection to the Target It takes a string in parameter specifying the tag name

func (*Target) TagKeys Uses

func (target *Target) TagKeys() []string

TagKeys returns a array of keys

type Template Uses

type Template struct {
    AllFormat string `json:"allFormat"`
    Current   struct {
        Tags  []interface{} `json:"tags"`
        Text  string        `json:"text"`
        Value interface{}   `json:"value"`
    }   `json:"current,omitempty"`
    Datasource  string `json:"datasource"`
    IncludeAll  bool   `json:"includeAll"`
    Multi       bool   `json:"multi"`
    MultiFormat string `json:"multiFormat"`
    Name        string `json:"name"`
    Options     []struct {
        Selected bool   `json:"selected"`
        Text     string `json:"text"`
        Value    string `json:"value"`
    }   `json:"options,omitempty"`
    Query         string `json:"query"`
    Refresh       string `json:"refresh"`
    RefreshOnLoad bool   `json:"refresh_on_load"`
    Regex         string `json:"regex"`
    Type          string `json:"type"`
}

Template define a variable usable in Grafana

func NewTemplate Uses

func NewTemplate() Template

NewTemplate create a default template for Grafana

type Templates Uses

type Templates []Template

Templates is an Array of Template

type Templating Uses

type Templating struct {
    List Templates `json:"list" toml:"template"`
}

A Templating contains a List of Templates usable in Dashboard

type Tooltip Uses

type Tooltip struct {
    ValueType string `json:"value_type" toml:"value_type"`
}

A Tooltip allow to setup some graphic display options

Package grafanaclient imports 15 packages (graph). Updated 2017-10-13. Refresh now. Tools for package owners.