Pi Zero Easy IoT

安価で簡単に IoT を始めよう! - Raspberry Pi Zero によるプログラミングレス IoT 環境データ収集

machinist.js

Library for sending some data to Machinist, this module exports class Machinist.

Machinist class (extends Record class)

Usage example

  let machinist = require('file path to this machinist.js');

  let machinist = new Machinist({
    agent: "agent_something",
    apiKey: "xxxxxxxxxx",
    batchQuantity: 1,
    format: (datas)=>{
      let metrics = [];
      datas.forEach((data)=>{
        let timestamp = Math.floor(data.timestamp / 1000);
        metrics.push({
          name: "a",
          namespace: "namespace_somethig",
          data_point: {value: data.a, timestamp: timestamp}});
        metrics.push({
          name: "b",
          namespace: "namespace_somethig",
          data_point: {value: data.b, timestamp: timestamp}});});
      return {
        agent: "agent_something",
        metrics: metrics
        };
    }
  });

machinist.write({a: 1, b: 2, timestamp: new Date.getTime()});

Constructor & Method

format function in constructor argument

Like above sample, argument of format function, datas is an array (this is internal stocks of which from write method argument), and format function return object of agent and metrics.

  format: (datas)=>{
    let metrics = [];
    datas.forEach((data)=>{
      let timestamp = Math.floor(data.timestamp / 1000);
      metrics.push({
        name: "a",
        namespace: "namespace_somethig",
        data_point: {value: data.a, timestamp: timestamp}});
      metrics.push({
        name: "b",
        namespace: "namespace_somethig",
        data_point: {value: data.b, timestamp: timestamp}});});
    return {
      agent: "agent_something",
      metrics: metrics
    };
  }