index.js
function ravenwall(options) {
  if (options instanceof statware) return options

  options = options || {}

  // set defaults
  options.sysstats = !(options.sysstats === false)
  options.procstats = !(options.procstats === false)
  options.memstats = !(options.memstats === false)
  options.push = !(options.push === false)
  options.pushApi = options.pushApi || "https://push.ravenwall.com"
  options.pushSeconds = options.pushSeconds || 10
  options.logHandle = options.logHandle || console.log
  options.logSeconds = options.logSeconds || 60
  options.initial = options.initial || {}
  options.initial.ravenwall_agent = "nodejs_" + VERSION
  if (options.id) id = options.id

  function startPusher(id) {
    if (!options.apiToken) throw new Error("Push API Requires an API token.")
    var pusherSettings = {
      url: options.pushApi + "/" + id,
      headers: {
        "Ravenwall-API-Token": options.apiToken,
      },
      timeout: (options.pushSeconds * 900) | 0
    }

    stats.pusher(pusherSettings, options.pushSeconds)
    stats.push()
  }

  // Create series/api client
  if (!options.noUpsert) {
    var client = api(options.apiToken, options.apiUrl)
      .upsertSeries({id: options.id, tags: options.tags}, function (err, res, body) {
        if (err) {
          console.log("Unable to upsert series to Ravenwall!", err)
          return
        }
        if (res.statusCode != 201) {
          console.log("Unable to upsert series to Ravenwall: server replied %s", res.statusCode)
          return
        }
        var results = JSON.parse(body)
        if (!options.id && options.push && !options.push) {
          // This is a new series, so the pusher wasn't set up yet. Set it up now.
          id = results.id
          startPusher(results.id)
        }
      })
  }

  var stats = statware(options.initial)
  if (options.sysstats) stats.registerHelper(statware.sysstats)
  if (options.procstats) stats.registerHelper(statware.procstats)
  if (options.memstats) stats.registerHelper(statware.memstats)

  // Don't immediately start a pusher if no id specified (instead it will start after upsert)
  if (options.push && options.id) {
    startPusher(options.id)
  }

  if (options.page) {
    stats.page(options.pagePort)
  }

  if (options.log) {
    stats.logger(options.logHandle, options.logSeconds)
    stats.log()
  }

  return stats
}
function ravenwall(options) {
  if (options instanceof statware) return options

  options = options || {}

  // set defaults
  options.sysstats = !(options.sysstats === false)
  options.procstats = !(options.procstats === false)
  options.memstats = !(options.memstats === false)
  options.push = !(options.push === false)
  options.pushApi = options.pushApi || "https://push.ravenwall.com"
  options.pushSeconds = options.pushSeconds || 10
  options.logHandle = options.logHandle || console.log
  options.logSeconds = options.logSeconds || 60
  options.initial = options.initial || {}
  options.initial.ravenwall_agent = "nodejs_" + VERSION
  if (options.id) id = options.id

  function startPusher(id) {
    if (!options.apiToken) throw new Error("Push API Requires an API token.")
    var pusherSettings = {
      url: options.pushApi + "/" + id,
      headers: {
        "Ravenwall-API-Token": options.apiToken,
      },
      timeout: (options.pushSeconds * 900) | 0
    }

    stats.pusher(pusherSettings, options.pushSeconds)
    stats.push()
  }

  // Create series/api client
  if (!options.noUpsert) {
    var client = api(options.apiToken, options.apiUrl)
      .upsertSeries({id: options.id, tags: options.tags}, function (err, res, body) {
        if (err) {
          console.log("Unable to upsert series to Ravenwall!", err)
          return
        }
        if (res.statusCode != 201) {
          console.log("Unable to upsert series to Ravenwall: server replied %s", res.statusCode)
          return
        }
        var results = JSON.parse(body)
        if (!options.id && options.push && !options.push) {
          // This is a new series, so the pusher wasn't set up yet. Set it up now.
          id = results.id
          startPusher(results.id)
        }
      })
  }

  var stats = statware(options.initial)
  if (options.sysstats) stats.registerHelper(statware.sysstats)
  if (options.procstats) stats.registerHelper(statware.procstats)
  if (options.memstats) stats.registerHelper(statware.memstats)

  // Don't immediately start a pusher if no id specified (instead it will start after upsert)
  if (options.push && options.id) {
    startPusher(options.id)
  }

  if (options.page) {
    stats.page(options.pagePort)
  }

  if (options.log) {
    stats.logger(options.logHandle, options.logSeconds)
    stats.log()
  }

  return stats
}
function ravenwall ( options ) { if ( options instanceof statware ) return options options = options || { } // set defaults options . sysstats = ! ( options . sysstats === false ) options . procstats = ! ( options . procstats === false ) options . memstats = ! ( options . memstats === false ) options . push = ! ( options . push === false ) options . pushApi = options . pushApi || "https://push.ravenwall.com" options . pushSeconds = options . pushSeconds || 10 options . logHandle = options . logHandle || console . log options . logSeconds = options . logSeconds || 60 options . initial = options . initial || { } options . initial . ravenwall_agent = "nodejs_" + VERSION if ( options . id ) id = options . id function startPusher ( id ) { if ( ! options . apiToken ) throw new Error ( "Push API Requires an API token." ) var pusherSettings = { url : options . pushApi + "/" + id , headers : { "Ravenwall-API-Token" : options . apiToken , } , timeout : ( options . pushSeconds * 900 ) | 0 } stats . pusher ( pusherSettings , options . pushSeconds ) stats . push ( ) } // Create series/api client if ( ! options . noUpsert ) { var client = api ( options . apiToken , options . apiUrl ) . upsertSeries ( { id : options . id , tags : options . tags } , function ( err , res , body ) { if ( err ) { console . log ( "Unable to upsert series to Ravenwall!" , err ) return } if ( res . statusCode != 201 ) { console . log ( "Unable to upsert series to Ravenwall: server replied %s" , res . statusCode ) return } var results = JSON . parse ( body ) if ( ! options . id && options . push && ! options . push ) { // This is a new series, so the pusher wasn't set up yet. Set it up now. id = results . id startPusher ( results . id ) } } ) } var stats = statware ( options . initial ) if ( options . sysstats ) stats . registerHelper ( statware . sysstats ) if ( options . procstats ) stats . registerHelper ( statware . procstats ) if ( options . memstats ) stats . registerHelper ( statware . memstats ) // Don't immediately start a pusher if no id specified (instead it will start after upsert) if ( options . push && options . id ) { startPusher ( options . id ) } if ( options . page ) { stats . page ( options . pagePort ) } if ( options . log ) { stats . logger ( options . logHandle , options . logSeconds ) stats . log ( ) } return stats }
The Ravenwall Agent.

@param {Object} options The options to create the agent with.
options.apiToken {string} set your Ravenwall API key. Can also use the RAVENWALL_API_TOKEN environment variable.
options.id {string} set a series id. This defines where your data will be stored. If not specified, a uuid will be generated.
options.tags {Array} tags to add/apply to the series. Add-only. Must match: /[a-zA-Z0-9:_-]+/
options.initial {Object} [{}] a default stats object. Useful for initializing values that may be set later for data continuity.
options.sysstats {Bool} [true] whether to apply a default set of system-related stats.
options.procstats {Bool} [true] whether to apply a default set of process-related stats.
options.memstats {Bool} [true] whether to apply a default set of memory-related stats.
options.push {Bool} [true] whether to create as a stats-pushing agent that will send data to Ravenwall.
options.pushApi {string} [https://push.ravenwall.com] The ravenwall push api endpoint.
options.pushSeconds {Int} [10] the frequency it will automatically push data. Setting this too low can get you throttled. Suggested minimum is ~10 seconds. Set to <= 0 to disable recurring push.
options.page {Bool} [false] whether to create a status page that will report the stats that can be scraped.
options.pagePort {Int} [7667] port to run the status page on (if enabled)
options.log {Bool} [false] whether to create a recurring stat logger
options.logHandle {Function} [console.log] a handle to log to
options.logSeconds {Int} [60] the frequency to log the stats to the log handle.
@return {Statware}
The Ravenwall Agent .