How to show only the pod name when hovering Grafana chart from Kubernetes "container_memory_usage_bytes" metric? - kubernetes

I created this chart using Grafana and the query
rate(container_memory_usage_bytes{ image!="", container_name!="POD"}[5m]) /1024 / 1024.
When highlighting the data points I receive all the details about the pod that is too much information.
How can I show only the pod field?

Found the answer: go to Options / Legend and include the field to be used as legend :) In this case: {{pod}}
Thanks Fabio Vieira

Related

Prometheus & Grafana: templating and "bool" modifier

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"}

How do I write a Prometheus query that returns the value of a label?

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

Google Annotation chart: Could it be possible to reverse the Y-axis?

I am working with the project that need Google Annotation Chart to show my data. And I have a problem like below.
My problem:
I would like to show the reverse value on the Y-axis.
What I mean is: the bigger the value is down and vice versa (the smaller the value is up)
I try to test all the option at the support docs but it still did not work
https://developers.google.com/chart/interactive/docs/gallery/annotationchart
Option:
...
vAxis: {direction: -1} // This works on line chart but not annotation chart
...
or somethings like
...
max: -200000, // this won't work and it's just keep the value not minus
min: 200000
...
This is my test code that forked from the docs page
https://jsfiddle.net/lecaoquochung/dsmgL9wj/2/
Could anyone help me to answer my problem? (Could it be possible to reverse the Y-axis now and later?)
Thank you very much
Problem solved. I have updated the testcode chart
Solution: add the chart to the option (get support from Googler)
chart : {vAxis: {direction: -1}},
Memo: Wonder that something updated in the API or just syntax (Because there is no description for chart option on graph docs pages)
Hope this help for anyone meet the same problem.

ZK Charts, clearing the chart

I am using ZK charts in my project. I am having line type charts. And using addSeries on my chats. But when I want refresh charts as in when user if fetching new Data, I am not sure how to clear the graph. Please help.
For example, if you are using series to add points on the chart (in my example I am using Float values) you can empty data displayed by setting an empty list to the series, like this:
chart.getSeries().setData(new ArrayList<Float>());
this one worked for me,
just write this line before populating your chart
chart.getSeries().setData(0);
To do that just call the method
chart.invalidate();

PNG area chart with Google Charts API?

I want to make an area chart with Google's Chart API, but it needs to be the PNG format one so I can build a PDF. Is that possible? The Chart Wizard does not seem to support area charts. Also, I want to do it in perl and the URI::GoogleChart module.
I spent a lot of time on this and discovered that I can do this:
See the example visually or the code below:
http://chart.apis.google.com/chart
?chxl=1:|week1|week2
&chxp=1,20,90
&chxr=0,0,120
&chxs=0,676767,11.5,0.5,l,676767|1,676767,9.5,0,_,676767
&chxt=y,x
&chs=300x278
&cht=lxy
&chco=FF9900,FF0000
&chds=6.667,100,0,110,0,100,0,118.333
&chd=t:-1|110,80|-1|43,32
&chdl=Total+Num|Special+Num
&chdlp=t
&chg=1,-1,1,0
&chls=2|2
&chma=8,0,0,7|54,2
&chtt=%23+Total+and+%23+Red+Items
&chts=000000,11.5
&chm=b,FF9900,0,1,0|B,FF0000,1,9,0
Where the last line b,color,startLine,endLine,0 means fill down to endLine and B,color,startLine,arbitraryNumber,0 means fill down to the bottom of the chart.
The solution came from Google's docs with some experimentation.