Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use #1

Open
jpdurot opened this issue Aug 7, 2017 · 3 comments
Open

How to use #1

jpdurot opened this issue Aug 7, 2017 · 3 comments

Comments

@jpdurot
Copy link

jpdurot commented Aug 7, 2017

Hi !

A post processing plugin looks very promising, especially with Javascript engine.
Could you please provide some examples of how to use this plugin and how to develop scripts ?

Thanks in advance, and good job !

@brianhks
Copy link
Member

brianhks commented Aug 10, 2017

So you first add the plugin to your query like this:
"plugins": [ { "name": "kairos_script", "script": "/home/bhawkins/work/consolidate.js" } ]

Right now the plugin pulls the script from the kairos file system only - easiest way to get it going. In the future I would like to read the script C* or let you specify it in the query (maybe two dangerous).

Here is a sample script I was testing with - very rough

`print("Howdy");
//These are the results from Kairos
// least squares line through my data
var leastResults = queryResults.queries[0].results;
// std dev for the data
var devResults = queryResults.queries[1].results;

//The call to getQueryResults is what will be returned - i'm adding a query result to the object
var newResponse = ks.getQueryResults().addQuery();
var newResult = newResponse.addResult("projected");

//I'm adding a result for plus and minus one standard deviation
//That is projected out one week
var sdPlus = newResponse.addResult("+SD");
var sdMinus = newResponse.addResult("-SD");

for (i = 0; i < leastResults.size(); i++)
{
//Get the least squares line
var v1 = leastResults[i].values[0];
var v2 = leastResults[i].values[1];

//Calculate the slope of the line
var rise = v2.value - v1.value;
var run = v2.time - v1.time;
var slope = rise/run;

//Project data out one week
var offset = (1000*60*60*24*7); //one week in milliseconds
var projectedTime = v2.time + offset;
var projectedValue = slope * offset + v2.value;

//Add results to new response
newResult.addValue(projectedTime, projectedValue);
sdPlus.addValue(projectedTime, projectedValue + devResults[i].values[0].value);
sdMinus.addValue(projectedTime, projectedValue - devResults[i].values[0].value);

}`

So my thinking is that help functions can be added to the KairosScript object (ks) that would do things to time series that people generally want.

I'm open to other ideas.

@brianhks
Copy link
Member

Not sure what is happening with that post, formatting of the script is wacked.

@jpdurot
Copy link
Author

jpdurot commented Aug 25, 2017

Nice sample thanks !
Actually, I'm looking for support for expressions, like the ones in OpenTSDB, in a basic way, the goal being to display a transformed data in Grafana, and also make computation on multiple metrics. We intensively use Grafana for displaying data, so expression editor should also be part of Kairos data source plugin for Grafana. I think the scripting language is a good start as a backend, unlike OpenTSDB which defines its own grammar which can be more complex.
I see two points:

  • the expression wrote by the user must be checked carefully, and very limited, so that it can't harm the system it runs on, loops indefinitely, ...
  • Helper methods will have to be implemented to align data for multiple metrics on the same timestamp before performing computation depending on multiple metrics

Is support of expression on KairosDB roadmap ?

JP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants