Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Kapacitor

Kapacitor is an open source framework for processing, monitoring, and alerting on time series data.
This is a 'driver-level' module, not a a full-fleged ORM or ODM.
you run queries directly by calling methods on this class.

example

import { Kapacitor } from 'kapacitor';
const kapacitor = new Kapacitor({
 host: 'localhost'
})

kapacitor.getTasks().then(res => {
 console.log(JSON.stringify(res, null, 2));
})

Hierarchy

  • Kapacitor

Index

Constructors

constructor

  • Connect to a single Kapacitor instance by specifying a set of connection options.

    example
    
    import { Kapacitor } from 'kapacitor';
    
    // Connects to a local, default kapacitor instance.
    new Kapacitor()
    
    example
    
    import { Kapacitor } from 'kapacitor';
    
    // Connect to a single host with a DSN:
    new Kapacitor('http://user:password@host:9092/')
    
    example
    
    import { Kapacitor } from 'kapacitor';
    
    // Connect to a single host with a full set of config details
    const client = new Kapacitor({
      host: 'localhost',
      port: 9092
    })
    
    example
    
    import { Kapacitor } from 'kapacitor';
    
    // Use a pool of several host connections and balance queries across them:
    const client = new Kapacitor({
      hosts: [
        { host: 'kapa1.example.com' },
        { host: 'kapa2.example.com' },
      ]
    })
    

    Parameters

    Returns Kapacitor

Methods

createTask

  • Creates a new task.

    example
    
    kapacitor.createTask({
      id: 'test_kapa',
      type: 'stream',
      dbrps: [{ db: 'test', rp: 'autogen' }],
      script: 'stream\n    |from()\n        .measurement("tick")\n',
      vars: {
        var1: {
          value: 42,
          type: VarType.Float
        }
      }
    });
    

    Parameters

    Returns Promise<ITask>

createTemplate

  • Creates a new template.

    throws

    no template exists

    example
    
    kapacitor.createTemplate({
      id: 'test_template',
      type: 'stream',
      script: `
        // Which measurement to consume
        var measurement string
        // Optional where filter
        var where_filter = lambda: TRUE
        // Optional list of group by dimensions
        var groups = [*]
        // Which field to process
        var field string
        // Warning criteria, has access to 'mean' field
        var warn lambda
        // Critical criteria, has access to 'mean' field
        var crit lambda
        // How much data to window
        var window = 5m
        // The slack channel for alerts
        var slack_channel = '#alerts'
    
        stream
            |from()
                .measurement(measurement)
                .where(where_filter)
                .groupBy(groups)
            |window()
                .period(window)
                .every(window)
            |mean(field)
            |alert()
                .warn(warn)
                .crit(crit)
                .slack()
                .channel(slack_channel)
      `,
      vars: {
        var1: {
          value: 42,
          type: VarType.Float
        }
      }
    });
    

    Parameters

    Returns Promise<ITemplate>

getConfig

getTask

  • Return a task. returns the results in a friendly format, ITask.

    throws

    RequestError

    statusCode statusMessage message
    404 Not Found no task exists
    example
    
    kapacitor.getTask(taskId, {dotView: 'labels'}).then(results => {
      console.log(results)
    })
    

    Parameters

    Returns Promise<ITask>

    result

getTasks

  • Return a array of tasks. returns the results in a friendly format, ITasks.

    example
    
    kapacitor.getTasks({dotView: 'labels'}).then(results => {
      console.log(results)
    })
    

    Parameters

    Returns Promise<ITasks>

    result(s)

getTemplate

  • Return a template. returns the results in a friendly format, ITemplate.

    throws

    RequestError

    statusCode statusMessage message
    404 Not Found no template exists
    example
    
    kapacitor.getTemplate(tmplId, {scriptFormat: 'raw'}).then(results => {
      console.log(results)
    })
    

    Parameters

    Returns Promise<ITemplate>

    result(s)

getTemplates

ping

  • Pings all available hosts, collecting online status and version info.

    example
    
    kapacitor.ping(5000).then(hosts => {
      hosts.forEach(host => {
        if (host.online) {
          console.log(`${host.url.host} responded in ${host.rtt}ms running ${host.version})`)
        } else {
          console.log(`${host.url.host} is offline :(`)
        }
      })
    })
    

    Parameters

    • timeout: number

      Given in milliseconds

    Returns Promise<IPingStats[]>

removeTask

  • removeTask(taskId: string): Promise<void>
  • remove a task with the provided task id.

    example
    
    kapacitor.removeTask('test_kapa');
    

    Parameters

    • taskId: string

    Returns Promise<void>

removeTemplate

  • removeTemplate(templateId: string): Promise<void>
  • remove a template with the provided template id.

    example
    
    kapacitor.removeTemplate('test_template');
    

    Parameters

    • templateId: string

    Returns Promise<void>

updateConfig

  • updateConfig(action: ConfigUpdateAction, section: string, element?: string): Promise<void>
  • Update config.

    example
    
    kapacitor.updateConfig({
     set: {
       'disable-subscriptions' : !disableSubscriptions
     }
    }, 'influxdb', 'default');
    

    Parameters

    Returns Promise<void>

updateTask

  • Update a task with the provided task id.

    example
    
    kapacitor.updateTask({
      id: 'test_kapa',
      status: 'enabled'
    });
    

    Parameters

    Returns Promise<ITask>

updateTemplate

  • Update a template with the provided template id.

    example
    
    kapacitor.updateTemplate({
      id: 'test_template',
      vars: {
        var1: {
          value: 42,
          type: VarType.Float
        }
      }
    });
    

    Parameters

    Returns Promise<ITemplate>

Generated using TypeDoc