Documentation ¶
Overview ¶
Package dashboards provides a programmatic API for interacting with New Relic dashboards.
Package dashboards provides a programmatic API for interacting with New Relic Insights dashboards. It can be used to create, read, update and delete dashboards. Refer to the Insights dashboard documentation for more information on working with these resources:
https://docs.newrelic.com/docs/insights/insights-api/manage-dashboards/insights-dashboard-api
Authentication ¶
You will need a valid Admin's API key to communicate with the backend New Relic API that provides this functionality. See the API key documentation below for more information on how to locate these keys:
https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys
Example (Dashboard) ¶
// Initialize the client configuration. An Admin API key is required to // communicate with the backend API. cfg := config.New() cfg.AdminAPIKey = os.Getenv("NEW_RELIC_ADMIN_API_KEY") // Initialize the client. client := New(cfg) // Search the dashboards for the current account by title. listParams := &ListDashboardsParams{ Title: "Example dashboard", } dashboards, err := client.ListDashboards(listParams) if err != nil { log.Fatal("error listing dashboards:", err) } // Get dashboard by ID. This example assumes that at least one dashboard // has been returned by the list endpoint, but in practice it is possible // that an empty slice is returned. dashboard, err := client.GetDashboard(dashboards[0].ID) if err != nil { log.Fatal("error getting dashboard:", err) } // Create a new dashboard. applicationName := "Example application" dashboard = &Dashboard{ Title: "Example dashboard", Icon: DashboardIconTypes.BarChart, } requestsPerMinute := DashboardWidget{ Visualization: VisualizationTypes.Billboard, Data: []DashboardWidgetData{ { NRQL: fmt.Sprintf("FROM Transaction SELECT rate(count(*), 1 minute) WHERE appName = '%s'", applicationName), }, }, Presentation: DashboardWidgetPresentation{ Title: "Requests per minute", }, Layout: DashboardWidgetLayout{ Row: 1, Column: 1, }, } errorRate := DashboardWidget{ Visualization: VisualizationTypes.Gauge, Data: []DashboardWidgetData{ { NRQL: fmt.Sprintf("FROM Transaction SELECT percentage(count(*), WHERE error IS true) WHERE appName = '%s'", applicationName), }, }, Presentation: DashboardWidgetPresentation{ Title: "Error rate", Threshold: &DashboardWidgetThreshold{ Red: 2.5, }, }, Layout: DashboardWidgetLayout{ Row: 1, Column: 2, }, } notes := DashboardWidget{ Visualization: VisualizationTypes.Markdown, Data: []DashboardWidgetData{ { Source: "### Helpful Links\n\n* [New Relic One](https://one.newrelic.com)\n* [Developer Portal](https://developer.newrelic.com)", }, }, Presentation: DashboardWidgetPresentation{ Title: "Dashboard note", }, Layout: DashboardWidgetLayout{ Row: 1, Column: 3, }, } dashboard.Widgets = []DashboardWidget{ requestsPerMinute, errorRate, notes, } created, err := client.CreateDashboard(*dashboard) if err != nil { log.Fatal("error creating dashboard:", err) } // Add a widget to an existing dashboard. topApdex := DashboardWidget{ Visualization: VisualizationTypes.FacetTable, Data: []DashboardWidgetData{ { NRQL: fmt.Sprintf("FROM Transaction SELECT rate(count(*), 1 minute) FACET name WHERE appName = '%s'", applicationName), }, }, Presentation: DashboardWidgetPresentation{ Title: "Requests per minute, by transaction", }, Layout: DashboardWidgetLayout{ Row: 1, Column: 2, Width: 3, }, } created.Widgets = append(created.Widgets, topApdex) updated, err := client.UpdateDashboard(*created) if err != nil { log.Fatal("error updating dashboard:", err) } // Delete a dashaboard. _, err = client.DeleteDashboard(updated.ID) if err != nil { log.Fatal("error deleting dashboard:", err) }
Output:
Index ¶
- Variables
- type Dashboard
- type DashboardFilter
- type DashboardIconType
- type DashboardMetadata
- type DashboardWidget
- type DashboardWidgetData
- type DashboardWidgetDataCompareWith
- type DashboardWidgetDataCompareWithPresentation
- type DashboardWidgetDataMetric
- type DashboardWidgetLayout
- type DashboardWidgetPresentation
- type DashboardWidgetThreshold
- type Dashboards
- func (d *Dashboards) CreateDashboard(dashboard Dashboard) (*Dashboard, error)
- func (d *Dashboards) DeleteDashboard(dashboardID int) (*Dashboard, error)
- func (d *Dashboards) GetDashboard(dashboardID int) (*Dashboard, error)
- func (d *Dashboards) ListDashboards(params *ListDashboardsParams) ([]*Dashboard, error)
- func (d *Dashboards) UpdateDashboard(dashboard Dashboard) (*Dashboard, error)
- type EditableType
- type ListDashboardsParams
- type VisibilityType
- type VisualizationType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DashboardIconTypes specifies the possible options for dashboard icons. DashboardIconTypes = struct { Adjust DashboardIconType Archive DashboardIconType BarChart DashboardIconType Bell DashboardIconType Bolt DashboardIconType Bug DashboardIconType Bullhorn DashboardIconType Bullseye DashboardIconType Clock DashboardIconType Cloud DashboardIconType Cog DashboardIconType Comments DashboardIconType Crosshairs DashboardIconType Dashboard DashboardIconType Envelope DashboardIconType Fire DashboardIconType Flag DashboardIconType Flask DashboardIconType Globe DashboardIconType Heart DashboardIconType Leaf DashboardIconType Legal DashboardIconType LifeRing DashboardIconType LineChart DashboardIconType Magic DashboardIconType Mobile DashboardIconType Money DashboardIconType None DashboardIconType PaperPlane DashboardIconType PieChart DashboardIconType PuzzlePiece DashboardIconType Road DashboardIconType Rocket DashboardIconType ShoppingCart DashboardIconType Sitemap DashboardIconType Sliders DashboardIconType Tablet DashboardIconType ThumbsDown DashboardIconType ThumbsUp DashboardIconType Trophy DashboardIconType USD DashboardIconType User DashboardIconType Users DashboardIconType }{ Adjust: "adjust", Archive: "archive", BarChart: "bar-chart", Bell: "bell", Bolt: "bolt", Bug: "bug", Bullhorn: "bullhorn", Bullseye: "bullseye", Clock: "clock-o", Cloud: "cloud", Cog: "cog", Comments: "comments-o", Crosshairs: "crosshairs", Dashboard: "dashboard", Envelope: "envelope", Fire: "fire", Flag: "flag", Flask: "flask", Globe: "globe", Heart: "heart", Leaf: "leaf", Legal: "legal", LifeRing: "life-ring", LineChart: "line-chart", Magic: "magic", Mobile: "mobile", Money: "money", None: "none", PaperPlane: "paper-plane", PieChart: "pie-chart", PuzzlePiece: "puzzle-piece", Road: "road", Rocket: "rocket", ShoppingCart: "shopping-cart", Sitemap: "sitemap", Sliders: "sliders", Tablet: "tablet", ThumbsDown: "thumbs-down", ThumbsUp: "thumbs-up", Trophy: "trophy", USD: "usd", User: "user", Users: "users", } )
var ( // EditableTypes specifies the possible options for who can edit a dashboard. EditableTypes = struct { Owner EditableType All EditableType ReadOnly EditableType }{ Owner: "editable_by_owner", All: "editable_by_all", ReadOnly: "read_only", } )
var ( // VisibilityTypes specifies the possible options for a dashboard's visibility. VisibilityTypes = struct { Owner VisibilityType All VisibilityType }{ Owner: "owner", All: "all", } )
var ( // VisualizationTypes specifies the possible options for dashboard widget types. VisualizationTypes = struct { ApplicationBreakdown VisualizationType AttributeSheet VisualizationType Billboard VisualizationType BillboardComparison VisualizationType ComparisonLineChart VisualizationType EventFeed VisualizationType EventTable VisualizationType FacetBarChart VisualizationType FacetPieChart VisualizationType FacetTable VisualizationType FacetedAreaChart VisualizationType FacetedLineChart VisualizationType Funnel VisualizationType Gauge VisualizationType Heatmap VisualizationType Histogram VisualizationType LineChart VisualizationType Markdown VisualizationType MetricLineChart VisualizationType RawJSON VisualizationType SingleEvent VisualizationType UniquesList VisualizationType }{ ApplicationBreakdown: "application_breakdown", AttributeSheet: "attribute_sheet", Billboard: "billboard", BillboardComparison: "billboard_comparison", ComparisonLineChart: "comparison_line_chart", EventFeed: "event_feed", EventTable: "event_table", FacetBarChart: "facet_bar_chart", FacetPieChart: "facet_pie_chart", FacetTable: "facet_table", FacetedAreaChart: "faceted_area_chart", FacetedLineChart: "faceted_line_chart", Funnel: "funnel", Gauge: "gauge", Heatmap: "heatmap", Histogram: "histogram", LineChart: "line_chart", Markdown: "markdown", MetricLineChart: "metric_line_chart", RawJSON: "raw_json", SingleEvent: "single_event", UniquesList: "uniques_list", } )
Functions ¶
This section is empty.
Types ¶
type Dashboard ¶
type Dashboard struct { ID int `json:"id"` Title string `json:"title,omitempty"` Icon DashboardIconType `json:"icon,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` Visibility VisibilityType `json:"visibility,omitempty"` Editable EditableType `json:"editable,omitempty"` UIURL string `json:"ui_url,omitempty"` APIURL string `json:"api_url,omitempty"` OwnerEmail string `json:"owner_email,omitempty"` Metadata DashboardMetadata `json:"metadata"` Filter DashboardFilter `json:"filter,omitempty"` Widgets []DashboardWidget `json:"widgets,omitempty"` }
Dashboard represents information about a New Relic dashboard.
type DashboardFilter ¶
type DashboardFilter struct { EventTypes []string `json:"event_types,omitempty"` Attributes []string `json:"attributes,omitempty"` }
DashboardFilter represents the filter in a dashboard.
type DashboardIconType ¶ added in v0.17.0
type DashboardIconType string
DashboardIconType represents an option for the dashboard's icon field.
type DashboardMetadata ¶
type DashboardMetadata struct {
Version int `json:"version"`
}
DashboardMetadata represents metadata about the dashboard (like version)
type DashboardWidget ¶
type DashboardWidget struct { Visualization VisualizationType `json:"visualization,omitempty"` ID int `json:"widget_id,omitempty"` AccountID int `json:"account_id,omitempty"` Data []DashboardWidgetData `json:"data,omitempty"` Presentation DashboardWidgetPresentation `json:"presentation,omitempty"` Layout DashboardWidgetLayout `json:"layout,omitempty"` }
DashboardWidget represents a widget in a dashboard.
type DashboardWidgetData ¶
type DashboardWidgetData struct { NRQL string `json:"nrql,omitempty"` Source string `json:"source,omitempty"` Duration int `json:"duration,omitempty"` EndTime int `json:"end_time,omitempty"` EntityIds []int `json:"entity_ids,omitempty"` CompareWith []DashboardWidgetDataCompareWith `json:"compare_with,omitempty"` Metrics []DashboardWidgetDataMetric `json:"metrics,omitempty"` RawMetricName string `json:"raw_metric_name,omitempty"` Facet string `json:"facet,omitempty"` OrderBy string `json:"order_by,omitempty"` Limit int `json:"limit,omitempty"` }
DashboardWidgetData represents the data backing a dashboard widget.
type DashboardWidgetDataCompareWith ¶
type DashboardWidgetDataCompareWith struct { OffsetDuration string `json:"offset_duration,omitempty"` Presentation DashboardWidgetDataCompareWithPresentation `json:"presentation,omitempty"` }
DashboardWidgetDataCompareWith represents the compare with configuration of the widget.
type DashboardWidgetDataCompareWithPresentation ¶
type DashboardWidgetDataCompareWithPresentation struct { Name string `json:"name,omitempty"` Color string `json:"color,omitempty"` }
DashboardWidgetDataCompareWithPresentation represents the compare with presentation configuration of the widget.
type DashboardWidgetDataMetric ¶
type DashboardWidgetDataMetric struct { Name string `json:"name,omitempty"` Units string `json:"units,omitempty"` Scope string `json:"scope,omitempty"` Values []string `json:"values,omitempty"` }
DashboardWidgetDataMetric represents the metrics data of the widget.
type DashboardWidgetLayout ¶
type DashboardWidgetLayout struct { Width int `json:"width"` Height int `json:"height"` Row int `json:"row"` Column int `json:"column"` }
DashboardWidgetLayout represents the layout of a widget in a dashboard.
type DashboardWidgetPresentation ¶
type DashboardWidgetPresentation struct { Title string `json:"title,omitempty"` Notes string `json:"notes,omitempty"` DrilldownDashboardID int `json:"drilldown_dashboard_id,omitempty"` Threshold *DashboardWidgetThreshold `json:"threshold,omitempty"` }
DashboardWidgetPresentation represents the visual presentation of a dashboard widget.
type DashboardWidgetThreshold ¶
type DashboardWidgetThreshold struct { Red float64 `json:"red,omitempty"` Yellow float64 `json:"yellow,omitempty"` }
DashboardWidgetThreshold represents the threshold configuration of a dashboard widget.
type Dashboards ¶
type Dashboards struct {
// contains filtered or unexported fields
}
Dashboards is used to communicate with the New Relic Dashboards product.
func New ¶
func New(config config.Config) Dashboards
New is used to create a new Dashboards client instance.
func (*Dashboards) CreateDashboard ¶
func (d *Dashboards) CreateDashboard(dashboard Dashboard) (*Dashboard, error)
CreateDashboard is used to create a New Relic dashboard.
func (*Dashboards) DeleteDashboard ¶
func (d *Dashboards) DeleteDashboard(dashboardID int) (*Dashboard, error)
DeleteDashboard is used to delete a New Relic dashboard.
func (*Dashboards) GetDashboard ¶
func (d *Dashboards) GetDashboard(dashboardID int) (*Dashboard, error)
GetDashboard is used to retrieve a single New Relic dashboard.
func (*Dashboards) ListDashboards ¶
func (d *Dashboards) ListDashboards(params *ListDashboardsParams) ([]*Dashboard, error)
ListDashboards is used to retrieve New Relic dashboards.
func (*Dashboards) UpdateDashboard ¶
func (d *Dashboards) UpdateDashboard(dashboard Dashboard) (*Dashboard, error)
UpdateDashboard is used to update a New Relic dashboard.
type EditableType ¶
type EditableType string
EditableType represents an option for the dashboard's editable field.
type ListDashboardsParams ¶
type ListDashboardsParams struct { Category string `url:"filter[category],omitempty"` CreatedAfter *time.Time `url:"filter[created_after],omitempty"` CreatedBefore *time.Time `url:"filter[created_before],omitempty"` Page int `url:"page,omitempty"` PerPage int `url:"per_page,omitempty"` Sort string `url:"sort,omitempty"` Title string `url:"filter[title],omitempty"` UpdatedAfter *time.Time `url:"filter[updated_after],omitempty"` UpdatedBefore *time.Time `url:"filter[updated_before],omitempty"` }
ListDashboardsParams represents a set of filters to be used when querying New Relic dashboards.
type VisibilityType ¶
type VisibilityType string
VisibilityType represents an option for the dashboard's visibility field.
type VisualizationType ¶ added in v0.17.0
type VisualizationType string
VisualizationType represents an option for adashboard widget's type.