How to use librato-node - 10 common examples

To help you get started, we’ve selected a few librato-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ello / webapp / src / server / iso.js View on Github external
res.redirect(location)
            break
          case 'render':
            console.log(`[${requestId}][render] Rendering ISO response (took ${new Date() - startTime}ms)`)
            librato.measure('webapp.server.render.success', 1)
            res.send(body)
            saveResponseToCache(cacheKey, body, postIds, postTokens, streamKind, streamId)
            break
          case 'error':
            console.log(`[${requestId}][render] Rendering error response (took ${new Date() - startTime}ms)`)
            librato.measure('webapp.server.render.error', 1)
            res.status(500).end()
            break
          case '404':
            console.log(`[${requestId}][render] Rendering 404 response (took ${new Date() - startTime}ms)`)
            librato.measure('webapp.server.render.404', 1)
            res.status(404).end()
            break
          default:
            console.log(`[${requestId}][render] Received unrecognized response (took ${new Date() - startTime}ms)`)
            console.log(JSON.stringify(result))
            librato.measure('webapp.server.render.error', 1)
            // Fall through
            res.status(500).end()
        }
        clearTimeout(renderTimeout)
      }
      const jobFailedCallback = (errorMessage) => {
github ello / webapp / src / server / iso.js View on Github external
saveResponseToCache(cacheKey, body, postIds, postTokens, streamKind, streamId)
            break
          case 'error':
            console.log(`[${requestId}][render] Rendering error response (took ${new Date() - startTime}ms)`)
            librato.measure('webapp.server.render.error', 1)
            res.status(500).end()
            break
          case '404':
            console.log(`[${requestId}][render] Rendering 404 response (took ${new Date() - startTime}ms)`)
            librato.measure('webapp.server.render.404', 1)
            res.status(404).end()
            break
          default:
            console.log(`[${requestId}][render] Received unrecognized response (took ${new Date() - startTime}ms)`)
            console.log(JSON.stringify(result))
            librato.measure('webapp.server.render.error', 1)
            // Fall through
            res.status(500).end()
        }
        clearTimeout(renderTimeout)
      }
      const jobFailedCallback = (errorMessage) => {
github ello / webapp / src / server / entrypoint-queue.js View on Github external
import { updateStrings as updateTimeAgoStrings } from './../lib/time_ago_in_words'

updateTimeAgoStrings({ about: '' })

// Fire up queue worker
const queue = kue.createQueue({ redis: process.env[process.env.REDIS_PROVIDER] })
const clusterWorkerSize = parseInt(process.env.CLUSTER_WORKERS, 10) || 1
const simultaneousWorkerRenders = parseInt(process.env.SIMULTANEOUS_RENDERS, 10) || 1
const renderProcessTimeout = parseInt(process.env.RENDER_PROCESS_TIMEOUT, 10) || 60
const renderJobTtl = (parseInt(process.env.RENDER_JOB_TTL, 10) || 30) * 1000

// Periodically clear stuck jobs
queue.watchStuckJobs()

// Report Kue stats to Librato
librato.configure({
  email: process.env.LIBRATO_EMAIL,
  token: process.env.LIBRATO_TOKEN,
  source: process.env.DYNO,
})
librato.start()
librato.on('error', (err) => {
  Honeybadger.notify(err)
  console.error(err)
})

const libratoReporter = setInterval(() => {
  queue.inactiveCount((err, total) => {
    if (!err) {
      librato.measure('kue.inactive.count', total)
    }
  })
github ello / webapp / src / server / iso.js View on Github external
// Honeybadger "before everything" middleware
app.use(Honeybadger.requestHandler);

// Log requests with Heroku's logfmt
app.use(logfmt.requestLogger({ immediate: false }, (req, res) => {
  const data = logfmt.requestLogger.commonFormatter(req, res)
  data.useragent = req.headers['user-agent']
  return data
}))

// Parse cookies (for determining to pre-render or not)
app.use(cookieParser())

// Send stats to Librato
librato.configure({
  email: process.env.LIBRATO_EMAIL,
  token: process.env.LIBRATO_TOKEN,
  source: process.env.DYNO,
})
librato.start()
app.use(librato.middleware())

librato.on('error', (err) => {
  console.log('[librato] ERROR', err)
})

// Use Helmet to lock things down
app.use(helmet())

const indexStr = fs.readFileSync(path.join(__dirname, './../../public/index.html'), 'utf-8')
const stats = JSON.parse(fs.readFileSync(path.join(__dirname, './../../webpack-stats/server.json'), 'utf-8'))
github ello / webapp / src / server / entrypoint-queue.js View on Github external
const clusterWorkerSize = parseInt(process.env.CLUSTER_WORKERS, 10) || 1
const simultaneousWorkerRenders = parseInt(process.env.SIMULTANEOUS_RENDERS, 10) || 1
const renderProcessTimeout = parseInt(process.env.RENDER_PROCESS_TIMEOUT, 10) || 60
const renderJobTtl = (parseInt(process.env.RENDER_JOB_TTL, 10) || 30) * 1000

// Periodically clear stuck jobs
queue.watchStuckJobs()

// Report Kue stats to Librato
librato.configure({
  email: process.env.LIBRATO_EMAIL,
  token: process.env.LIBRATO_TOKEN,
  source: process.env.DYNO,
})
librato.start()
librato.on('error', (err) => {
  Honeybadger.notify(err)
  console.error(err)
})

const libratoReporter = setInterval(() => {
  queue.inactiveCount((err, total) => {
    if (!err) {
      librato.measure('kue.inactive.count', total)
    }
  })
  queue.activeCount((err, total) => {
    if (!err) {
      librato.measure('kue.active.count', total)
    }
  })
  queue.failedCount((err, total) => {
github ello / webapp / src / server / iso.js View on Github external
return data
}))

// Parse cookies (for determining to pre-render or not)
app.use(cookieParser())

// Send stats to Librato
librato.configure({
  email: process.env.LIBRATO_EMAIL,
  token: process.env.LIBRATO_TOKEN,
  source: process.env.DYNO,
})
librato.start()
app.use(librato.middleware())

librato.on('error', (err) => {
  console.log('[librato] ERROR', err)
})

// Use Helmet to lock things down
app.use(helmet())

const indexStr = fs.readFileSync(path.join(__dirname, './../../public/index.html'), 'utf-8')
const stats = JSON.parse(fs.readFileSync(path.join(__dirname, './../../webpack-stats/server.json'), 'utf-8'))

// Wire up OAuth route
addOauthRoute(app)

// Assets
app.use(express.static('public', { index: false, redirect: false }))
app.use('/static', express.static('public/static', { maxAge: '1y', index: false, redirect: false, fallthrough: false }))
github ello / webapp / src / server / iso.js View on Github external
app.use(logfmt.requestLogger({ immediate: false }, (req, res) => {
  const data = logfmt.requestLogger.commonFormatter(req, res)
  data.useragent = req.headers['user-agent']
  return data
}))

// Parse cookies (for determining to pre-render or not)
app.use(cookieParser())

// Send stats to Librato
librato.configure({
  email: process.env.LIBRATO_EMAIL,
  token: process.env.LIBRATO_TOKEN,
  source: process.env.DYNO,
})
librato.start()
app.use(librato.middleware())

librato.on('error', (err) => {
  console.log('[librato] ERROR', err)
})

// Use Helmet to lock things down
app.use(helmet())

const indexStr = fs.readFileSync(path.join(__dirname, './../../public/index.html'), 'utf-8')
const stats = JSON.parse(fs.readFileSync(path.join(__dirname, './../../webpack-stats/server.json'), 'utf-8'))

// Wire up OAuth route
addOauthRoute(app)

// Assets
github ello / webapp / src / server / entrypoint-queue.js View on Github external
const queue = kue.createQueue({ redis: process.env[process.env.REDIS_PROVIDER] })
const clusterWorkerSize = parseInt(process.env.CLUSTER_WORKERS, 10) || 1
const simultaneousWorkerRenders = parseInt(process.env.SIMULTANEOUS_RENDERS, 10) || 1
const renderProcessTimeout = parseInt(process.env.RENDER_PROCESS_TIMEOUT, 10) || 60
const renderJobTtl = (parseInt(process.env.RENDER_JOB_TTL, 10) || 30) * 1000

// Periodically clear stuck jobs
queue.watchStuckJobs()

// Report Kue stats to Librato
librato.configure({
  email: process.env.LIBRATO_EMAIL,
  token: process.env.LIBRATO_TOKEN,
  source: process.env.DYNO,
})
librato.start()
librato.on('error', (err) => {
  Honeybadger.notify(err)
  console.error(err)
})

const libratoReporter = setInterval(() => {
  queue.inactiveCount((err, total) => {
    if (!err) {
      librato.measure('kue.inactive.count', total)
    }
  })
  queue.activeCount((err, total) => {
    if (!err) {
      librato.measure('kue.active.count', total)
    }
  })
github ello / webapp / src / server / iso.js View on Github external
const data = logfmt.requestLogger.commonFormatter(req, res)
  data.useragent = req.headers['user-agent']
  return data
}))

// Parse cookies (for determining to pre-render or not)
app.use(cookieParser())

// Send stats to Librato
librato.configure({
  email: process.env.LIBRATO_EMAIL,
  token: process.env.LIBRATO_TOKEN,
  source: process.env.DYNO,
})
librato.start()
app.use(librato.middleware())

librato.on('error', (err) => {
  console.log('[librato] ERROR', err)
})

// Use Helmet to lock things down
app.use(helmet())

const indexStr = fs.readFileSync(path.join(__dirname, './../../public/index.html'), 'utf-8')
const stats = JSON.parse(fs.readFileSync(path.join(__dirname, './../../webpack-stats/server.json'), 'utf-8'))

// Wire up OAuth route
addOauthRoute(app)

// Assets
app.use(express.static('public', { index: false, redirect: false }))
github ello / webapp / src / server / iso.js View on Github external
currentToken().then((token) => {
    librato.timing('iso.render_time', (libratoDone) => {
      // Kick off the render
      console.log(`[${requestId}][render] Enqueueing render`)
      const renderOpts = {
        accessToken: token.token.access_token,
        expiresAt: token.token.expires_at,
        originalUrl: req.originalUrl,
        url: req.url,
        timingHeader,
        requestId,
      }

      const job = queue
        .create('render', renderOpts)
        .ttl(1.1 * preRenderTimeout) // So we don't lose the job mid-timeout
        .removeOnComplete(true)
        .save()

librato-node

A node.js client for Librato Metrics (http://metrics.librato.com/)

MIT
Latest version published 4 years ago

Package Health Score

46 / 100
Full package analysis