Skip to main content

dashboards.go

dashboards.go - Overview

  1. Overview The file defines the data structures (structs) used to represent Grafana dashboards, panels, layouts, variables, query data, and widgets. These structures are used for handling dashboard configurations and data retrieval.

  2. Detailed Documentation

Datasource

  • Purpose: Represents a data source used in Grafana.
    • Parameters:
      • Type (string): The type of the data source.
      • UID (string): The unique identifier of the data source.
    • Returns: None

Panels

  • Purpose: Represents a panel in a Grafana dashboard.
    • Parameters:
      • Datasource (interface{}): The data source for the panel.
      • Description (string): The description of the panel (optional).
      • FieldConfig (struct): Configuration for the panel's fields (optional).
        • Defaults (struct): Default field configuration.
          • Color (struct): Color settings.
            • Mode (string): Color mode.
          • Max (float64): Maximum value.
          • Min (float64): Minimum value.
          • Thresholds (struct): Threshold settings.
            • Mode (string): Threshold mode.
            • Steps ([]struct): Threshold steps.
              • Color (string): Color for the step.
              • Value (interface{}): Value for the step.
          • Unit (string): Unit of measurement.
        • Overrides ([]interface{}): Field configuration overrides.
      • GridPos (struct): Grid position of the panel.
        • H (int): Height.
        • W (int): Width.
        • X (int): X coordinate.
        • Y (int): Y coordinate.
      • ID (int): Panel ID.
      • Links ([]interface{}): Panel links (optional).
      • Options (struct): Panel-specific options (optional).
        • Orientation (string): Orientation of the panel.
        • ReduceOptions (struct): Options for data reduction.
          • Calcs ([]string): Calculations to perform.
          • Fields (string): Fields to use for reduction.
          • Values (bool): Whether to show values.
        • ShowThresholdLabels (bool): Whether to show threshold labels.
        • ShowThresholdMarkers (bool): Whether to show threshold markers.
      • PluginVersion (string): Plugin version (optional).
      • Targets ([]struct): Data targets for the panel.
        • Datasource (interface{}): Data source for the target.
        • EditorMode (string): Editor mode.
        • Expr (string): Expression for the target.
        • Hide (bool): Whether to hide the target.
        • IntervalFactor (int): Interval factor.
        • LegendFormat (string): Legend format.
        • Range (bool): Whether to use range.
        • RefID (string): Reference ID.
        • Step (int): Step value.
      • Title (string): Panel title.
      • Type (string): Panel type.
      • HideTimeOverride (bool): Hide time override.
      • MaxDataPoints (int): Maximum data points.
      • Collapsed (bool): Panel collapsed or not.
      • Panels ([]Panels): Nested Panels

GrafanaJSON

  • Purpose: Represents the structure of a Grafana JSON dashboard.
    • Parameters:
      • Inputs ([]struct): Inputs for the dashboard.
        • Name (string): Name of the input.
        • Label (string): Label for the input.
        • Description (string): Description of the input.
        • Type (string): Type of the input.
        • PluginID (string): Plugin ID.
        • PluginName (string): Plugin Name.
      • Requires ([]struct): Dependencies for the dashboard.
        • Type (string): Type of dependency.
        • ID (string): ID of dependency.
        • Name (string): Name of dependency.
        • Version (string): Version of dependency.
      • Annotations (struct): Annotations for the dashboard.
        • List ([]struct): List of annotations.
          • HashKey (string): Hash key.
          • BuiltIn (int): Built-in flag.
          • Datasource (interface{}): Data source.
          • Enable (bool): Enable flag.
          • Hide (bool): Hide flag.
          • IconColor (string): Icon color.
          • Name (string): Name.
          • Target (struct): Target settings.
            • Limit (int): Limit.
            • MatchAny (bool): Match any flag.
            • Tags ([]interface{}): Tags.
            • Type (string): Type.
          • Type (string): Type.
      • Editable (bool): Whether the dashboard is editable.
      • FiscalYearStartMonth (int): Fiscal year start month.
      • GnetID (int): Gnet ID.
      • GraphTooltip (int): Graph tooltip setting.
      • ID (interface{}): Dashboard ID.
      • Links ([]struct): Dashboard links.
        • Icon (string): Icon.
        • Tags ([]interface{}): Tags.
        • TargetBlank (bool): Whether to open in a new tab.
        • Title (string): Title.
        • Type (string): Type.
        • URL (string): URL.
      • LiveNow (bool): Live now flag.
      • Panels ([]Panels): Panels in the dashboard.
      • SchemaVersion (int): Schema version.
      • Style (string): Style.
      • Tags ([]string): Tags for the dashboard.
      • Templating (struct): Templating settings.
        • List ([]struct): List of template variables.
          • Current (struct): Current value of the variable.
            • Selected (bool): Whether the value is selected.
            • Text (interface{}): Text representation of the value.
            • Value (interface{}): Value of the variable.
          • Hide (int): Hide setting.
          • IncludeAll (bool): Include all option.
          • Label (string): Label (optional).
          • Multi (bool): Multi-select option.
          • Name (string): Name.
          • Options ([]interface{}): Available options.
          • Query (interface{}): Query for the variable.
          • Refresh (int): Refresh interval (optional).
          • Regex (string): Regex filter (optional).
          • SkipURLSync (bool): Skip URL sync.
          • Type (string): Type of variable.
          • Datasource (interface{}): Variable data source.
          • Definition (string): Variable definition.
          • Sort (int): Variable sort order.
          • TagValuesQuery (string): Variable tag values query.
          • TagsQuery (string): Variable tags query.
          • UseTags (bool): Use tags.
      • Time (struct): Time range settings.
        • From (string): Start time.
        • To (string): End time.
      • Timepicker (struct): Timepicker settings.
        • RefreshIntervals ([]string): Refresh intervals.
        • TimeOptions ([]string): Time options.
      • Timezone (string): Timezone.
      • Title (string): Dashboard title.
      • UID (string): Dashboard UID.
      • Version (int): Dashboard version.
      • WeekStart (string): Week start day.

Layout

  • Purpose: Represents the layout of a panel in a dashboard.
    • Parameters:
      • H (int): Height.
      • I (string): Identifier.
      • Moved (bool): Whether the panel has been moved.
      • Static (bool): Whether the panel is static.
      • W (int): Width.
      • X (int): X coordinate.
      • Y (int): Y coordinate.
    • Returns: None

Variable

  • Purpose: Represents a dashboard variable.
    • Parameters:
      • AllSelected (bool): Whether all values are selected.
      • CustomValue (string): Custom value.
      • Description (string): Description.
      • ModificationUUID (string): Modification UUID.
      • MultiSelect (bool): Whether multi-select is enabled.
      • QueryValue (string): Query value.
      • SelectedValue (string): Selected value.
      • ShowALLOption (bool): Whether to show the "All" option.
      • Sort (string): Sort order.
      • TextboxValue (string): Textbox value.
      • Type (string): Variable type.
    • Returns: None

Data

  • Purpose: Represents generic query data.
    • Parameters:
      • Legend (string): Legend for the data.
      • Query (string): Query string.
      • QueryData ([]interface{}): Array of query results.
    • Returns: None

QueryDataDashboard

  • Purpose: Represents the query data for a dashboard.
    • Parameters:
      • Data (Data): The data related to the query.
      • Error (bool): Indicates if there was an error during the query.
      • ErrorMessage (string): The error message, if any.
      • Loading (bool): Indicates if the data is still loading.
    • Returns: None

ClickHouseQueryDashboard

  • Purpose: Represents a ClickHouse query for a dashboard.
    • Parameters:
      • Legend (string): The legend for the query.
      • Name (string): The name of the query.
      • Query (string): The raw ClickHouse query.
      • Disabled (bool): Indicates if the query is disabled.
    • Returns: None

QueryBuilder

  • Purpose: Represents a query builder component.
    • Parameters:
      • AggregateOperator (interface{}): Aggregate operator used in the query.
      • Disabled (bool): Indicates if the query is disabled.
      • GroupBy ([]string): Group by fields.
      • Legend (string): Legend for the query.
      • MetricName (string): Name of the metric.
      • Name (string): Name of the query.
      • TagFilters (TagFilters): Tag filters. // Assuming TagFilters is defined elsewhere
      • ReduceTo (interface{}): Reduce to value.
    • Returns: None

MetricsBuilder

  • Purpose: Represents a metrics builder configuration.
    • Parameters:
      • Formulas ([]string): Formulas to apply.
      • QueryBuilder ([]QueryBuilder): Query builders.
    • Returns: None

PromQueryDashboard

  • Purpose: Represents a Prometheus query for a dashboard.
    • Parameters:
      • Query (string): The Prometheus query.
      • Disabled (bool): Indicates if the query is disabled.
      • Name (string): The name of the query.
      • Legend (string): The legend for the query.
    • Returns: None

Query

  • Purpose: Represents a query configuration with different types.
    • Parameters:
      • ClickHouse ([]ClickHouseQueryDashboard): ClickHouse queries.
      • PromQL ([]PromQueryDashboard): Prometheus queries.
      • MetricsBuilder (MetricsBuilder): Metrics builder configuration.
      • QueryType (int): Type of the query.
    • Returns: None

Widget

  • Purpose: Represents a dashboard widget.
    • Parameters:
      • Description (string): Description of the widget.
      • ID (string): ID of the widget.
      • IsStacked (bool): Indicates if the widget is stacked.
      • NullZeroValues (string): Handling of null/zero values.
      • Opacity (string): Opacity of the widget.
      • PanelTypes (string): Panel types.
      • Query (Query): The query configuration for the widget.
      • QueryData (QueryDataDashboard): Query data for the widget.
      • TimePreferance (string): Time preference.
      • Title (string): Title of the widget.
      • YAxisUnit (string): Unit for the Y-axis.
      • QueryType (int): Type of query used by the widget.
    • Returns: None

DashboardData

  • Purpose: Represents the complete data for a dashboard.
    • Parameters:
      • Description (string): Description of the dashboard.
      • Tags ([]string): Tags for the dashboard.
      • Layout ([]Layout): Layout of the panels.
      • Title (string): Title of the dashboard.
      • Widgets ([]Widget): Widgets in the dashboard.
      • Variables (map[string]Variable): Variables used in the dashboard.
    • Returns: None
  1. Code Examples None

  2. Clarity and Accuracy The documentation is based on the provided code and aims for accuracy.

  3. Markdown & MDX Perfection The markdown is formatted to be compatible with Docusaurus.

  4. Edge Cases To Avoid Breaking MDX

  • Angle brackets < and > are escaped using &lt; and &gt; where necessary.
  • Curly braces { and } are properly handled within code blocks.
  1. Getting Started Relevance Include in Getting Started: NO