Using Events from Other Streams

Octave.js consists of a library of methods, available within Cloud Actions, that facilitate accessing the Octave API.

You can the methods outlined here (https://api.octave.dev/#cloud-javascript-library) to gather data inside of a cloud action.

Performing a Simple Query

You can run a simple query to find events using the Octave.Event.* methods such as find etc.

The following steps illustrate this process:

  1. Create a Cloud Action as described in Cloud Actions above.
  2. Add code in the Action Runner to invoke the Octave.Event.find method. For example, the following code finds events from stream s5b7c2258c4eaa25486be2ed1:

Request:

var events = Octave.Event.find('s5b7c2258c4eaa25486be2ed1')

Response:

[
   {
      elems:{
         x:1
      },
      creationDate:1534865286261,
      ...
   },
   {
      elems:{
         x:1
      },
      ...
   }
]

Querying with a Filter

You can pass in the (optional) options object to the Octave.Event.* methods to run the query with a filter.

For additional information about the fields of the options object, see Analyzing Events.

The following steps illustrate this process:

  1. Create Cloud Action as described in Cloud Actions.
  2. Add code in the Action Runner to invoke the Octave.Event.find method. For example, the following code finds the most recent event where x is greater than 1:

Request:

var event = Octave.Event.findOne('s5b7c2258c4eaa25486be2ed1', {
  filter: 'x > 1',
  sort: 'creationDate',
})

Response:

{
   elems:{
      x:1
   },
   creationDate:1534865286261,
   ...
}

Analyzing Events Using Aggregation

Events can be analyzed using the aggregate method and passing in the (optional) options object to define the aggregation. For example, the following code filters events that have a CPU temperature above 50 degrees. It then groups the results by the month in which they were created, and outputs information about the temperature values:

var myAggregationResults = Octave.Event.aggregate(myStreamId, {
  filter: 'EXISTS cpu_temp',
  rules: { x: 'cpu_temp > 50' },
  groupBy: ['$month'],
  output: [
    '$avg:cpu_temp',
    '$min:cpu_temp',
    '$max:cpu_temp',
    '$avg:x',
    '$count',
  ],
  sorts: ['$avg:x:desc', '$avg:cpu_temp:asc'],
})