Menu
Open source
Custom components
Custom components are a way to create new components from a pipeline of built-in and other custom components.
A custom component is composed of:
- Arguments: Settings that configure the custom component.
- Exports: Values that a custom component exposes to its consumers.
- Components: Built-in and custom components that are run as part of the custom component.
Creating custom components
You can create a new custom component using the declare
configuration block.
The label of the block determines the name of the custom component.
The following custom configuration blocks can be used inside a declare
block:
- argument: Create a new named argument, whose current value can be referenced using the expression
argument.NAME.value
. Argument values are determined by the user of a custom component. - export: Expose a new named value to custom component users.
Custom components are useful for reusing a common pipeline multiple times. To learn how to share custom components across multiple files, refer to Modules.
Example
This example creates a new custom component called add
, which exports the sum of two arguments:
alloy
declare "add" {
argument "a" { }
argument "b" { }
export "sum" {
value = argument.a.value + argument.b.value
}
}
add "example" {
a = 15
b = 17
}
// add.example.sum == 32
Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video
Getting started with Grafana dashboard design
In this webinar, you'll learn how to design stylish and easily accessible Grafana dashboards that tell a story.
Video
Building advanced Grafana dashboards
In this webinar, we’ll demo how to build and format Grafana dashboards.
Video
Intro to Alerting with Grafana
Master alerting with Grafana: Navigate the complexities, reduce false positives, and boost reliability for your systems.