Templating in Grafana with Elastic Search - grafana

I want to use the templating feature in Grafana with elastic search to create a set of 'dynamic' terms ("application")
To get the ist of terms from elasticsearch I'm useing:
{
"aggs" :
{
"applications" : {
"terms" : { "field" : "businessTransactions.application" }
}
}
}
When I use that query in the Templating Query variable settings as query Grafana tells me: "Template variables could not be initialized: Cannot read property 'then' of undefined"
I'm using grafana 3.1.0beta1
Maybe I'm completely off, but how would someone use a query to get different terms of a field as a template variable from elasticsearch?
Thanks!

First question: which version of Grafana are you using? Sorry just re-read and saw the answer, which is 3.1.0beta1.
The below works for me on 3.1.0 (not beta).
Second question: did you see this page: http://docs.grafana.org/datasources/elasticsearch/
Templating
The Elasticsearch datasource supports two types of queries
you can use to fill template variables with values.
Possible values for a field
{"find": "terms", "field": "#hostname"}
Fields filtered by type
{"find": "fields", "type": "string"}
Fields filtered by type, with filter {"find": "fields", "type": "string", "query": <lucene query>}
Multi format / All format

Related

What data source ID to use for Google Fit REST heart rate query?

I'm trying to retrieve aggregate daily heart rate summary data using the Google Fit REST API, but I'm struggling because either I'm missing something or the documentation seems to be very incomplete. I've successfully managed to retrieve aggregate daily step count by following one of the few available examples:
Request URL
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
Request body
{
"aggregateBy": [{
"dataTypeName": "com.google.step_count.delta",
"dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
}],
"bucketByTime": { "durationMillis": 86400000 },
"startTimeMillis": 1438705622000,
"endTimeMillis": 1439310422000
}
I can't find any example for reading heart rate, so I'm trying to modify this for heart rate. I found this list of data types where it has this data type: com.google.heart_rate.summary but there isn't any information on what the dataSourceId should be. I tried just omitting it but I get this error:
no default datasource found for: com.google.heart_rate.summary
Does anybody know what I need to use for dataSourceId, or have a link to any decent documentation on data sources?
For resting heart rate, I use this:
"derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm"
For heart rate or BPM, I use this:
"derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm"
For completeness, I have included the datasources that I am using below for various readings:
DATA_SOURCE = {
"steps": "derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas",
"dist": "derived:com.google.distance.delta:com.google.android.gms:from_steps<-merge_step_deltas",
"bpm": "derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm",
"rhr": "derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm",
"sleep" : "derived:com.google.sleep.segment:com.google.android.gms:sleep_from_activity<-raw:com.google.activity.segment:com.heytap.wearable.health:stream_sleep",
"cal" : "derived:com.google.calories.expended:com.google.android.gms:from_activities",
"move": "derived:com.google.active_minutes:com.google.android.gms:from_steps<-estimated_steps",
"points" : "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes",
"weight" : "derived:com.google.weight:com.google.android.gms:merge_weight"
}
Depending on the datasource, sometimes it will provide an array of points. You can then choose to take sum, mean, median, etc of all points in the array accordingly.
You can list the data sources available for a given data type, for example :
Method
GET
Request URL
https://www.googleapis.com/fitness/v1/users/me/dataSources?dataTypeName=com.google.heart_rate.summary
Depending on what you're trying to achieve, you'll probably find a source either for com.google.heart_rate.summary or com.google.heart_rate.bpm to meet your needs, including merged sources.

Parameterizing Resource Names in CloudFormation Template?

This answer here: Is there a way to parameterize cloud formation resource names? didn't really help as I am looking to set the physical name, not the logical one. I was hoping for something along the lines of setting a parameter in the parameters list like:
"ELBName": {
"Type": "String",
"Default": "xxx",
"Description": "The Production Number for this stack (e.g. xxx)"
}
and then
"LoadBalancerName": "prod" + {Ref: "ELBName"}
although that concatenation directly is not possible. Is there any way to do what I want? My end goal is to take a template I've created and use it to create many copies of itself, each with the same resources, but different names, possibly through a nested stack.
Use Fn::Join function to do this:
"LoadBalancerName":{
"Fn::Join":[
"",
[
"prod",
{
"Ref":"ELBName"
}
]
]
}
This will give the name as prod01 assuming ELBName parameter has been passed the value 01

How "keys" and "key" filters should be used in Couchbase to filter view results?

I have issue with key and keys filter parameter in Couchbase (Version: 3.0.0 Enterprise Edition) in the web console. Whatever value I set in those parameters, no record is returned.
Documents look like:
{
"folder": "F3",
"ccy": "USD",
"pnl": 789700,
"maturity": "4424-10-16 00:00 AM CEST",
"source": "BackOffice1",
"npv": 341684,
"symbolic_id": 880888,
"bpv": 374000,
"cpty": "CPTY2"
}
Map function is:
function (doc, meta) {
emit([doc.source,doc.cpty], doc.npv);
}
Reduce is the built in function
_count
I assume that I should be able to get all documents with the key ["BackOffice1","CPTY2"] by setting the key parameter in the querystring ?key=["BackOffice1","CPTY2"]&reduce=true&group=true. But nothing is returned.
I may miss something in how we should use key and keys parameters.
For information, startkey and endkey work as expected.
Is there something wrong with my approach ?
You have to add
keys=["BackOffice1","CPTY2"]
as parameter .
I figured out what was the issue with the key parameter. In the Couchbase version 3.0.0, we need to add inclusive_end=true parameter to get results.
Looking at Couchbase bugs, it looks like it was not required in previous versions and that it will be reverted back in next version, refer to https://www.couchbase.com/issues/browse/MB-12378.
After reviewing samples in Couchbase documentation, my usage of keys parameter was not correct. To query view with array as a key, keys parameter should be formatted as follow:
keys=[["value1",value2"],["value3",value2"]].
If I apply this to the example I provided in my question, the query will look like:
?keys=[["BackOffice1","CPTY2"]] or key=["BackOffice1","CPTY2"]
Thanks

Entity cannot be found by elasticsearch

I have the following entity in ElasticSearch:
{
"id": 123,
"entity-id": 1019,
"entity-name": "aaa",
"status": "New",
"creation-date": "2014-08-06",
"author": "bubu"
}
I try to query for all entities with status=New, so the above entity should appear there.
I run this code:
qesponse.setQuery(QueryBuilders.termQuery("status", "New"));
return qResponse.setFrom(start).setSize(size).execute().actionGet().toString();
But it return no result.
If I use this code (general search, not of specific field) I get the above entity.
qResponse.setQuery(QueryBuilders.queryString("New");
return qResponse.setFrom(start).setSize(size).execute().actionGet().toString();
Why?
The problem is a mismatch between a Term Query and using the Standard Analyzer when you index. The Standard Analyzer, among other things, lowercases the field when it's indexed:
Standard Analyzer
An analyzer of type standard is built using the Standard Tokenizer
with the Standard Token Filter, Lower Case Token Filter, and Stop
Token Filter.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html
The Term query, however, matches without analysis:
Term Query
Matches documents that have fields that contain a term (not analyzed).
The term query maps to Lucene TermQuery.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
So in your case when you index the field status it becomes "new". But when you search with a Term Query it's looking for "New" - they don't match. They do match with a general search it works because the general search also uses the Standard Analyzer.
The default value of index for a string field is analyzed . So, when you write "status" = "New" , it will use standard_analyzer, and after analyzing it will write as "new" .
So, term Query doesn't seems to be working, If you wish to query like you specified ,write mapping for the field as "not_analyzed".
For more info. link

Birt mongodb param

I installed Birt 4.3 (latest) as Eclipse plugin.
JDBC as data source works perfectly for me. I define a param in query. I can define a param in data set via Report Design and link it to a report param.
But I have multiple issues with MongoDB
1) When I open "edit data set" dialog I cannot find the menu "Parameters" in left side. I only see
Data Source
Query
Output Columns
Computed Columns
Filters
properties Binding
Setting
Review Results
No Parameter any more. I can see it in JDBC not in MongoDB
Could anyone please how to define a parameter in data set while Data source is MongoDB? How to link the param to the param of report?
2) In MongoDB (Birt) how to define a parameter in the expression of "Run Database Command" or in query
In JDBC we can use "?" as a param holder like
select * where id=?
param will replace "?"
For MongoDB
{
runCommand : {
aggregate : COLLECTION_NAME,
.....
}
}
COLLECTION_NAME is vary. How can I represent it?
Any help will be appreciated.
Thanks
MongoDB expression syntax itself does not support parameters, thus the MongoDB ODA connector does not support data set parameters directly. You can use BIRT scripting to reference a BIRT report parameter and change the runtime value of the "Command expression" data set property.
You can identify the system connection when you make a MongoDB data set using Eclipse. This is in the MongoDB Collection area of the data set dialog.
Check http://www.eclipse.org/forums/index.php/t/628348/ for more information.
EXAMPLE
You can use script to set the query using a beforeOpen script in the dataset such as:
this.queryText ='{ "findQueryExpr" : "{ pop: { $gte: 20000 } }" , "operationType" : "FIND" , "collectionName" : "zipcode" , "selectedFields" : [ "_id" , "city", "pop"]}'
The fields and collection name need to match the pre-configured dataset.
Replace the 20000 with your parameter value. For example, using a parameter named "Population" which takes an integer, you can update your query at run-time with the following script:
this.queryText ='{ "findQueryExpr" : "{ pop: { $gte: '+params["Population"].value+' } }" , "operationType" : "FIND" , "collectionName" : "zipcode" , "selectedFields" : [ "_id" , "city", "pop"]}'