npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sematext-agent-express

v2.1.7

Published

Express.js Monitoring and Logging Agent by Sematext.

Downloads

564

Readme

Sematext Agent Express

Build Status

NPM

This is the Express.js monitoring and logging agent for Sematext. The following data is collected and shipped to Sematext Cloud / Enterprise:

  • OS Metrics (CPU / Mem)
  • Process Memory
  • Process Metrics
  • EventLoop Metrics
  • Garbage Collector Metrics
  • Web Server Metrics:
    • request rate
    • error rate
    • response times
    • content size
  • HTTP Logs per API endpoint:
    • response times
    • content size
    • URL
    • status
    • method
  • Custom Logs:
    • Instead of using console.log ship all logs directly to Sematext Logs with stLogger

Quickstart

  1. Sign up to Sematext for free
  2. Create a Node.js Monitoring App and copy the Monitoring App Token
  3. Create a Logs App and copy the Logs App Token
  4. Install the sematext-agent-express npm module
  5. Configure environment variables
  6. Run the agent using the App tokens provided for your Monitoring and Logs Apps

Create Apps in Sematext

After you sign up to Sematext here, you need to create Apps to store metrics and logs data.

  1. Create a Logs App
  2. Create a Monitoring App

Installation

Install the package from the NPM registry.

npm i sematext-agent-express

Configure Environment

Make sure to configure your ENVIRONMENT variables before adding sematext-agent-express. You can do this either by exporting the variables to your environment or by using dotenv. We suggest you use dotenv.

Export env vars

If you are using the US region of Sematext Cloud:

export MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
export LOGS_TOKEN=<YOUR_LOGS_TOKEN>
export INFRA_TOKEN=<YOUR_INFRA_TOKEN>

If you are using the EU region of Sematext Cloud:

export REGION=EU
export MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
export LOGS_TOKEN=<YOUR_LOGS_TOKEN>
export INFRA_TOKEN=<YOUR_INFRA_TOKEN>

Use dotenv

npm i dotenv

Create a .env file in the root of your project.

Add this code if you are using the US region of Sematext Cloud:

MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
LOGS_TOKEN=<YOUR_LOGS_TOKEN>
INFRA_TOKEN=<YOUR_INFRA_TOKEN>

Add this code if you are using the EU region of Sematext Cloud:

REGION=EU
MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
LOGS_TOKEN=<YOUR_LOGS_TOKEN>
INFRA_TOKEN=<YOUR_INFRA_TOKEN>

Configure Agent

Make sure to load the environment variables at the top of your JavaScript entry point file. Then require sematext-agent-express.

The Agent has 3 parts:

  • stMonitor - Monitors metrics and sends to Sematext Monitoring
  • stLogger - A logger based on winston, that will send logs directly to Sematext Logs
  • stHttpLoggerMiddleware - Express.js middleware function that will send all HTTP endpoint logs to Sematext Logs

Usage

// Load env vars
require('dotenv').config()

// require all agents
const { stMonitor, stLogger, stHttpLoggerMiddleware } = require('sematext-agent-express')

// Start monitoring metrics
stMonitor.start()

// ...

// At the top of your routes add the stHttpLoggerMiddleware to send HTTP logs to Sematext
const express = require('express')
const app = express()
app.use(stHttpLoggerMiddleware)

// ...

// Use the stLogger to send all types of logs directly to Sematext
app.get('/api', (req, res, next) => {
  stLogger.info('Hello World.')
  stLogger.error('Some error.')
  res.status(200).send('Hello World.')
})

You can use all parts of the Agent of use them separately. It's all up to you.

Result

The Agents will capture both metrics, logs, and HTTP logs per API endpoint.

Metrics

Logs

Troubleshooting

Check out our documentation for more information.

Built with

LICENSE

Apache 2 - see the LICENSE file.