When I select NRT Instance say sp1nrt, sp1cap I want to load the bucket with label bucket_name=sp1. How to extract the same from the from the variable probably by regex.
Try this :
bucket_size(
size_type=“used”,
bucket_name=~“${nrtInstance:regex/^(sp[0-9]+).*/$1/}”
)
or
create a second variable and keep your panel query clean:
- Dashboard → Settings → Variables → Add variable
- Name:
nrtPrefix
- Type: Query
- Datasource: Prometheus
- Query type: Label values
- Label:
bucket_name
- Regex:
/^(sp[0-9]+)/
- Save
Now in your panel just do:
promql
bucket_size(size_type="used", bucket_name="$nrtPrefix")
Either of these will ensure that when you pick sp1nrt or sp1cap in $nrtInstance
, Grafana only ever sends sp1 to your bucket_name
filter.