Grafonnet Documentation

repository·main·Indexed 19 days ago

https://github.com/grafana/grafonnet

A Jsonnet library used for generating Grafana dashboards, automatically generated from OpenAPI documents. It includes the grafonnet.alerting package for defining alerting components such as contact points, mute timings, notification policies, notification templates, and rule groups.

Tokens
173.7K
Snippets
731
Records
1.2K
Agent score
63%

What's inside Grafonnet

  1. Explore Grafonnet panel subpackages

    main

    The grafonnet.panel package is the entry point for defining various Grafana panel types using Grafonnet. It is organized into subpackages, where each subpackage corresponds to a specific panel type (e.g., timeSeries, gauge, table). To create a specific panel, you should import the relevant subpackage from grafonnet.panel.

    // Available panel subpackages include:
    // grafonnet.panel.timeSeries
    // grafonnet.panel.gauge
    // grafonnet.panel.table
    // grafonnet.panel.barChart
    // ... and many others
  2. Use the grafonnet table panel

    main
    The grafonnet.panel.table package provides the API for constructing Grafana Table panels using Jsonnet. It is organized into several subpackages that allow for fine-grained configuration of sorting, linking, transformations, field mapping, overrides, and threshold steps.
  3. Explore the grafonnet.apps subpackages

    main

    The grafonnet.apps package provides high-level abstractions for managing Grafana application-level entities. It is organized into several subpackages, each targeting a specific type of Grafana object:

    • dashboard: Tools for creating and configuring Grafana dashboards.
    • folder: Tools for managing dashboard folders.
    • playlist: Tools for managing dashboard playlists.
    • preferences: Tools for managing Grafana user or system preferences.
  4. Configure Azure Monitor queries

    main
    The grafonnet.query.azureMonitor package provides functions to construct queries for Azure Monitor. You can use high-level functions like withAzureMonitor, withAzureLogAnalytics, withAzureResourceGraph, and withAzureTraces to create specific query types. These functions typically accept a value (the base object to be transformed) and return a modified version of that object.
  5. Use the grafonnet.alerting package

    main
    The grafonnet.alerting package provides a structured way to define Grafana alerting components using Jsonnet. It is organized into several subpackages that allow you to compose a complete alerting pipeline, including rules, notification policies, and contact points.
  6. Explore librarypanel subpackages

    main

    The librarypanel package provides tools for configuring Library Panels in Grafonnet. It includes subpackages for managing field configurations, links, transformations, and thresholds.

    Key subpackages include:

    • model.fieldConfig.defaults.actions: Configuration for field actions.
    • model.fieldConfig.defaults.links: Configuration for field-level links.
    • model.fieldConfig.defaults.thresholds.steps: Configuration for threshold steps.
    • model.fieldConfig.overrides: Configuration for field overrides.
    • model.links: General link configurations.
    • model.transformations: Data transformation configurations.
  7. Explore the grafonnet.apps.dashboard.v2 API subpackages

    main
    The grafonnet.apps.dashboard.v2 package provides a structured API for defining Grafana dashboards using the v2 specification. The API is organized into subpackages that correspond to different parts of the dashboard specification, such as layout, variables, links, and time settings. Use these subpackages to compose a complete dashboard object.
  8. Understand the different value mapping types

    main

    Grafana supports four primary mapping types used across different mapping objects:

    • value: Maps specific text/numeric values to a color or different display text (e.g., mapping 10 to Perfection!).
    • range: Maps numerical ranges to display text and color (e.g., mapping 0-10 to Low).
    • regex: Maps regular expressions to replacement text and color (e.g., truncating a domain name).
    • special: Maps special values like Null, NaN, or booleans (true/false) to display text and color (e.g., mapping null to N/A).
  9. Configure Dashboard-to-Dashboard Links

    main

    When using withType('dashboards') to link to other dashboards within Grafana, you can control how they are presented and filtered:

    • Dropdown Display: Use withAsDropdown(value) to show links in a dropdown menu (default true) or side-by-side (default false).
    • Filtering by Tags: Use withTags(value) to provide an array of tags. This limits the displayed dashboards to those matching the provided tags. If the array is empty, all dashboards are shown.
    • Template Variables: Use withIncludeVars(value) (default true) to include current template variable values as query parameters in the link.
    • Time Range: Use withKeepTime(value) (default true) to include the current dashboard time range in the link.
    /* Example of a dashboard link type with filtering and variable preservation */
    link.withType('dashboards')
      .withTags(['production', 'alerts'])
      .withAsDropdown(true)
      .withIncludeVars(true)
      .withKeepTime(true)
  10. How overrides work in Grafonnet

    main

    Overrides allow you to customize visualization settings for specific fields or series. You accomplish this by creating an override rule that targets a specific set of fields (using selectors like name, type, or regex) and then defining the options to be applied to those targets.

    There are five primary ways to target fields for an override:

    1. byName: Targets fields by their specific name.
    2. byQuery: Targets fields by their byFrameRefID.
    3. byRegexp: Targets fields using a regular expression.
    4. byType: Targets fields based on their data type (e.g., 'number').
    5. byValue: Targets fields based on their specific value.
    override.byType.new('number')
    + override.byType.withPropertiesFromOptions(
      panel.standardOptions.withDecimals(2)
      + panel.standardOptions.withUnit('s')
    )
  11. Configure conditional rendering for tabs

    main

    Use withConditionalRendering(value) on the spec object to control when tabs are displayed.

    Within conditionalRendering, you can use:

    • withKind(): Set the kind of conditional rendering.
    • withSpec(value): Provide the specific configuration for the conditional rendering.

    The spec for conditional rendering includes:

    • withCondition(value): Define the condition.
    • withItems(value): Define the items to be rendered.
    • withVisibility(value): Set the visibility settings.