How Do I Construct The Following Query in Grafana? - elasticsearch

I'd like to create a query variable in Grafana that will bring back a series a distinct Host Names that will be used to filter out results in my dashboard.
I am using ElasticSearch as the datasource and here is a sample of the fields in the log record(showing only the host:hostname for brevity):
"host": {
"hostname": "ip-xx-xx-xx-xx",
"architecture": "x86_64",
}
The term "host.hostname" is what I am trying to retrieve.
In the table view of ElasticSearch the field is displayed as follows:
Here is what I'm trying to do:
I want to write a Lucene query for a Grafana query variable.
For the time-range that the user selects I'd like the query to return all available hosts in the current ElasticSearch stream.
I'd like to return only unique entries. If the stream contains 3 unique hosts I'd like to return only 3.
This query variable will be used in the dashboard to filter out specific hosts (one, multiple or all) and then I'd like my panel queries to display results only for the hosts that the user has selected.
Here is the query I currently have, not surprisingly, it doesn't work:
{"find": "terms", "field": "host.hostname", "query": "ip-*"}
Here is what the Variable Edit screen looks like (Datasource name scrubbed):
Here is what the panel editor looks like. Not that ip addresses are shown in legend. That's fine. In this case I'm trying to display the "actual free" memory. Note that no data is displayed (another newbie issue).
I'm brand new to ElasticSearch with Grafana so my attempt I'm sure looks lame to more experienced folks. Any help would be greatly appreciated.
I am using the 7.5.0-beta Docker image.

Related

Grafana Variables Query using ElasticSearch - Filter doesn't work

I am currently using Grafana v9.1.7 and ElasticSearch 8.4.2
What I'm trying to achieve is to create a dashboard that can filter the data by country. I have a keyword field named honeypot_country (it's a string that mapped into keyword in elastic). When this filter is selected, it should only provide set of data filtered by that country
I already tried to create a variable query to filter these data. But it doesn't filter as I want to. So, I hope anyone can help me with this issue. Thanks

How to visualize NULL values in kibana?

Doc stored in ES index is like this:
{
"product_id": "something_unique",
"price": 25
}
The price section can also be null at times. (This is just as assumed db structure, as I don't want to list all the actual attributes which are being used in elasticsearch).
Now when I try to visualize this in Kibana I get results like this:
The visualized data is only for 3 entries whereas we have data for 11 products in the ES system. The other 8 entries have price as null. I want to showcase this info in kibana graph so that the admin can take proper action for this.
So, is there any way I can show the details of docs which have price as null ?
I am new to Elasticsearch and couldn't find solution to this anywhere else therefore posting it here. Please don't come up with comments like "null values are not supposed to be visualized , I have implemented the /_xpack/sql api but its not very handy".
I am using Elasticsearch 6.5

Grafana - Show metric by field value

I'm currently trying to create a graph on Grafana to monitor the status of my servers, however, I can't seem to find a way to use the value of a field as the value to be displayed on the graph. (Datasource is ElasticSearch)
The following "document" is going to be sent to GrayLog (which saves to Elastic) every 1 minute for an array of regions.
{
"region_key": "some_key",
"region_name": "Some Name",
"region_count": 1610
}
By using the following settings, I can get Grafana to display the count of messages it received for each region, however, I want to display the number on the region_count field instead.
Result:
How can I accomplish this? is this even possible using Elastic as the datasource?
1) Make sure that your document includes a timestamp in ElasticSearch.
2) In the Query box, provide the Lucene query which narrows down the documents to only those related to this metric
3) In the Metric line, press "Count" and change that to one which takes a specific field: for example, "Average"
4) Next to the "Average" box will appear "select field", which is a dropdown of the available fields. If you see unexpected fieldnames here, it's probably because your Lucene query isn't specific enough. (Kibana can be useful for getting this query right)

Is there a way to define a dynamic query in Kibana dashboard?

A somewhat similar question has been asked here but there's no answer for that yet. That question relates to an older version of Kibana so I hope you can help me.
I'm trying to setup some predefined queries in the Kibana dashboard. I'm using Kibana 5.1. The purpose of those queries is filtering some logs based on multiple different parameters.
Let's see a query I'd like to execute:
{
"index": "${index_name}",
"query": {
"query_string": {
"query": "message:(+\"${LOG_LEVEL}\")",
"analyze_wildcard": true
}
}
}
I know I can query directly in the dashboard something like "message:(+"ERROR")" and manually change the ERROR to WARN for example, but I don't want that - imagine that this query might be more complex and contain multiple fields.
Note that the data stored in the message is not structured - think of the message as a whole log line. This means I don't have fields like LOG_LEVEL which I could filter directly.
Is there any way I can set the index_name and LOG_LEVEL dynamically from the Kibana Discover dashboard?
You should go to discover, open one document and click over this button in any of the fields. After this, a filter will appear under the search bar and you can edit it and put any custom query. If you want add more filters with more custom queries you can repeat the same action with a different document or field or you can do to Settings (or Management), Saved Objects, go to the Search you saved and to the JSON representation and copy and paste the elements inside the filter array field as many times you want.
And remember that in order to apply one of the filters, you probably should disable the enabled ones (otherwise it will filter by all the enabled filters in your dashboard).

How to retrieve unique count of a field using Kibana + Elastic Search

Is it possible to query for a distinct/unique count of a field using Kibana? I am using elastic search as my backend to Kibana.
If so, what is the syntax of the query? Heres a link to the Kibana interface I would like to make my query: http://demo.kibana.org/#/dashboard
I am parsing nginx access logs with logstash and storing the data into elastic search. Then, I use Kibana to run queries and visualize my data in charts. Specifically, I want to know the count of unique IP addresses for a specific time frame using Kibana.
For Kibana 4 go to this answer
This is easy to do with a terms panel:
If you want to select the count of distinct IP that are in your logs, you should specify in the field clientip, you should put a big enough number in length (otherwise, it will join different IP under the same group) and specify in the style table. After adding the panel, you will have a table with IP, and the count of that IP:
Now Kibana 4 allows you to use aggregations. Apart from building a panel like the one that was explained in this answer for Kibana 3, now we can see the number of unique IPs in different periods, that was (IMO) what the OP wanted at the first place.
To build a dashboard like this you should go to Visualize -> Select your Index -> Select a Vertical Bar chart and then in the visualize panel:
In the Y axis we want the unique count of IPs (select the field where you stored the IP) and in the X axis we want a date histogram with our timefield.
After pressing the Apply button, we should have a graph that shows the unique count of IP distributed on time. We can change the time interval on the X axis to see the unique IPs hourly/daily...
Just take into account that the unique counts are approximate. For more information check also this answer.
Be aware with Unique count you are using 'cardinality' metric, which does not always guarantee exact unique count. :-)
the cardinality metric is an approximate algorithm. It is based on the
HyperLogLog++ (HLL) algorithm. HLL works by hashing your input and
using the bits from the hash to make probabilistic estimations on the
cardinality.
Depending on amount of data I can get differences of 700+ entries missing in a 300k dataset via Unique Count in Elastic which are otherwise really unique.
Read more here: https://www.elastic.co/guide/en/elasticsearch/guide/current/cardinality.html
Create "topN" query on "clientip" and then histogram with count on "clientip" and set "topN" query as source. Then you will see count of different ips per time.
Unique counts of field values are achieved by using facets. See ES documentation for the full story, but the gist is that you will create a query and then ask ES to prepare facets on the results for counting values found in fields. It's up to you to customize the fields used and even describe how you want the values returned. The most basic of facet types is just to group by terms, which would be like an IP address above. You can get pretty complex with these, even requiring a query within your facet!
{
"query": {
"match_all": {}
},
"facets": {
"terms": {
"field": "ip_address"
}
}
}
Using Aggs u can easily do that.
Writing down query for now.
GET index/_search
{
"size":0,
"aggs": {
"source": {
"terms": {
"field": "field",
"size": 100000
}
}
}
}
This would return the different values of field with there doc counts.
For Kibana 7.x, Unique Count is available in most visualizations.
For example, in Lens:
In aggregation based visualizations:
And even in TSVB (supporting normal fields as well as Runtime Fields, Scripted Fields are not supported):

Resources