I created a new Graph in Grafana that takes data from OpenTSDB.
The Alias field has the following value: Label $metric $tag_host.
when it is interpreted, it looks like this:
Label $metric myhost1
...
Label $metric myhostn
but I want to look like this:
Label xyz myhost1
...
Label xyz myhostn
where xyz is the value of the Metric field.
So, for a key (E.g.: host) in Tags, I can use $tag_<key> (E.g.: $tag_host) in Alias.
I want to achieve the same behavior for the hard-coded Metric value (E.g.: xyz), such that if someone wants to change the Metric value in the future from xyz to abc, the Alias should be updated automatically.
I tried to use:
$metric
$Metric
$tag_metric
but they didn't work.
Is it possible to use the Metric value in Alias without hard-coding in Alias (the hard-coding from Metric is enough)?
My solution: I included second tag (first one was id - $tag_id) into GROUP BY (tag(sql)) and then I used $tag_sql ($tag_key) variable to define alias for current series of data thus:
Highlighted fields are tags.
This might be a XY Problem.
If what you're trying to do is just to show the value in the Label, you don't need to create an alias. Just go to Legend and tick the appropriate option(s) (Min, Max, Avg, etc.). This will add a new column(s) near the Label with the appropriate value.
I'm using Grafana 4.4.3.
Related
In iText's DITO template designer product, I have one field which has a fairly complex calculation. In another field, I want to use the result of that calculation.
The tooltip says "Identifier used for referencing fields in calculation expressions". So I assumed if I named it blah I can use it in a calculation in another field like this: sum({{blah}},42) (e.g. add 42 to the value of blah). But if I do that I get the error
Unable to resolve reference: "{{blah}}" in node with tag: <span> and text:
The iText DITO documentation does not elaborate on this feature at all. I'm evaluating iText DITO and there does not seem to be any way to get support while evaluating the product.
Suppose I have a field with a very complex calculation. In order to reuse the calculation result, I can do the following:
Give a name to this field (in the image below I've chosen name "total")
Insert a calculation to another field (where I want to reuse "total")
Add "total" as the calculation's body:
That's it, now the total value is reused:
I think the documentation you are looking for is at https://kb.itextpdf.com/home/ditokb/latest/manuals/itext-dito-editor/calculations
You have to give the rich text element a name in the properties to be able to reference it on other rich text element and/or calculations.
See image example at https://kb.itextpdf.com/home/ditokb/files/latest/68620314/68620309/1/1660291029000/image2020-5-27_17-56-41.png
all.
I'm new to Grafana and I want to get only tag values what I want.
For example,
As you can see,"23" is a value of tags, I just want to get template variable by "23".
But now I get so many template variables so that every time I have to seek it for long time.
I'd like to get some tags like "23" rather than seek it from all tags.
Thank you very much for your support.
Unfortunately you cannot use "IN" when filtering TAGs youll need to do something like this (i.e only show 23 and 24)
Your query should be
SHOW TAG VALUES WITH KEY "measurementPoint" where ("measurementPoint" = '23') or ("measurementPoint" = '24')
Ofcourse if you know its only going to be 23 or something else you could just use static variables or have i misunderstood your question ?
I have a data set that looks like this:
I want to use a parameter to select a value from Group and then compute Ratio which is Value divided by Value when Group == parameter. The image above is the desired output when the parameter equals D.
I thought that this would do the trick:
[Value]/{EXCLUDE [GROUP]: MAX(VALUE)}
But I just get nulls.
Thanks for your help!
LOD expressions dont work that way and they will always show as null values in the datasource page. Here is the Documentation. (Bullet point 2)
For your case, create the parameter as shown below. (You can use 'Paste from clipboard' as by default only values can be assigned by field and not 'Display As'.)
Now your calculation simply becomes
[Value]/[Selected_Group]
I am building Grafana (4.1.1) graphs with a Prometheus (1.1.2) backend, and am trying to use Templates to select/deselect certain sub-sets of metrics on a dashboard. I have a template variable called "$POP" which describes my city locations, and a template variable called "$Resolver" which describes the type of resolver I am using ("unbound" or "pdns" are the possible string results.)
I have these two metrics like this that work quite well currently selecting on the various values in $POP:
irate(dnsdist_recursor_main_servers_unbound_drops{env="prod",loc=~"$POP"}[1m]) > 0
irate(dnsdist_recursor_main_servers_pdns_drops{env="prod",loc=~"$POP"}[1m]) > 0
Putting aside for the moment that instead of labels the selection criteria are embedded in the metric name (I know it's not ideal but this is just an example of larger problem sets so please do not suggest how I can use labels) I would like the following results:
When (~"$Resolver" == "unbound") I would like to show the first metric (dnsdist_recursor_main_servers_unbound_drops) and when (~"$Resolver" == "pdns") I would like to show the second one (dnsdist_recursor_main_servers_pdns_drops) and when both are selected I'd like to show both metric set data. Basically, I hope to have an on/off visibility trigger for a metric that is keyed to my $Resolver template value.
How do I create a boolean such that the metric is shown or not shown based on the setting of the string value in the templated setting of $Resolver? The trick here is that the selection criteria is in the metric name, not a label, which is really stumping me. I tried "bool" modifiers but was never able to get anything to work on string equality tests. I'm sure it's just a syntax issue but examples are thin on the ground.
What you can take advantage of here is that there's no uniqueness restriction on label selectors, so you can do {resolver="$resolver",resolver="unbound"}
I'm making a Grafana dashboard and want a panel that reports the latest version of our app. The version is reported as a label in the app_version (say) metric like so:
app_version_updated{instance="eu99",version="1.5.0-abcdefg"}
I've tried a number of Prometheus queries to extract the version label as a string from the latest member of this time series, to no effect.
For example, the query
count(app_version_updated) by (version)
returns a {version="1.5.0-abcdefg"} element with a value of 1. When put in a Grafana dashboard in a single value panel, this doesn't display the version string but instead the count value (1).
How can I construct a Prometheus query that returns the version string?
My answer tries to elaborate on Carl's answer. I assume that the GUI layout may have changed a little since 2016, so it took me while to find the "name" option.
Assuming you have a metric as follows:
# HELP db2_prometheus_adapter_info Information on the state of the DB2-Prometheus-Adapter
# TYPE db2_prometheus_adapter_info gauge
db2_prometheus_adapter_info{app_state="UP") 1.0
and you would like to show the value of the label app_state.
Follow these steps:
Create a "SingleStat" visualization.
Go to the "Queries" tab:
Enter the name (here db2_prometheus_adapter_info) of the metric.
Enter the label name as the legend using the {{[LABEL]}} notation (here {{app_state}}).
Activate the "instant" option.
Go to the "Visualization" tab:
Choose the value "Name" under "Value - Stat".
Note on the "Instant" setting: This setting switches from a range query to a simplified query only returning the most recent value of the metric (also see What does the "instant" checkbox in grafana graphs based on prometheus do?). If not activated, the panel will show an error as soon as there is more than one distinct value for the label in the history of the metric. For a "normal" metric you would remedy this by choosing "current" in the "Value - Stat" option. But doing so here prevents your label value to be shown.
We recently added support for displaying the serie name as a value in the single stat panel (https://github.com/grafana/grafana/issues/4740). So you have to run our nightly build until we release 4.0.
Just make sure the query returns one serie and you can use the "name" value in the dropdown under Options -> big value.Then you can format the string using the legend formater. Ex {{job}} would return "node" as a serie name.
I hope this answers your question.
While most of #marcus-rickert's answer is still valid in Grafana 7, there is some change.
The 'Stat' 'Name' field seems to be gone, instead in the 'Field' panel, you can set the 'Display name' to the label you want to show.
This worked for me.
label_values(my_metric{type= "xxx", another_label="xxx"},target_label)
With Stat visualization in Grafana 8+, you can set the legend to the intended label name and then change the Stat Styles -> Text Mode to Name
Prometheus doesn't have any functions that return strings, what you're looking for is for a Grafana singlestat to be able to display a label value - which it unfortunately doesn't support yet.
https://github.com/grafana/grafana/issues/5094 tracks this.
Another update on very latest kube-prometheus-stack using grafana 8.0.3. I still faced this issue, for me in a Bar gauge I still had this issue in scenarios where it only returned 1 value, but with 2+ values the Legend field works OK.
My solution:
Go to Edit Panel, find Display Name, type
${__field.labels.insertYourLegendValueHere}
I wanted to get all the various values of a label from Prometheus to put into a variable in Grafana. I used this simple query to populate my varialbe Drop-Down list:
label_values(myLabelName)
This returned the expected "value01", "value02" etc