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

aegis-net

v1.1.3

Published

Lightweight endpoing monitoring for any express, koa or http servers

Downloads

15

Readme

Logo

Fast and light weight api and endpoint monitoring backed by Redis and carefully written for performace.

build npm GitHub

Features:

  • [X] Url request monitoring
  • [X] Easily integratable with Express, Koa, and standard http
  • [X] Fast and efficient data storage based on Redis
  • [X] Monitoring daily requests
  • [X] Moinotring requests per hour
  • [X] Monitoring response times
  • [X] Custom options

The Rundown:

  • An object is made in redis that is defined as an event. An event is a collection of the route, the method, the status code, the number of requests, and date and hour (depending on what key is specified).

  • Redis stores the data per request into three separate keys:

    1. The total number of requests per event (date and hour are not included here)
    2. The total number of requests per event per day
    3. The total number of requests per event per hour of every day.
    4. The time in milliseconds each event takes per request.
  • Note: These keys are stored by default as key names: 'total', 'daily', 'hourly', and 'response-times'.

Install

    $ npm install aegis-net

Usage:

Express:

const express = require('express')
const {AegisNet}  = require('aegis-net');
const app = express();
app.use(express.json());
const aegis = new AegisNet;

app.use(aegis.express())

Koa:

const koa = require('koa');
const {AegisNet}  = require('aegis-net');
const router = require('@koa/router');
const app = new koa();
const router = new Router();

app.use(aegis.koa());

http:

const http = require('http');
const {AegisNet}  = require('aegis-net');

const server = http.createServer((req, res) => {
    // server code here
    aegis.http(req, res);
});
server.listen(3000, () => "Listening");

Adding custom options:

const express = require('express')
const {AegisNet}  = require('aegis-net');
const app = express();
app.use(express.json());
const aegis = new AegisNet;

app.use(aegis.express({port: 6379, host: 'localhost', dailyKey: "foo"}))

Retrieving the data:

app.get('/api/users',  (_, res) => {
      // note: Redis will store the data as a JSON string 
     //  so it's important you parse after you retrieve it first to work with it.
    client.get('total', (err, stats) => {
        res.status(200).send(stats);
    });
});

API:

|options|about|type| |---------|-------|------| | port | Redis port number| number |host|Redis host|string |totalKey| Key name for total requests, defaults to "total"| string| |dailyKey| Key name for daily requests, defaults to "daily"| string |hourlyKey| Key name for hourly requests, defaults to "hourly"| string| |responseKey| Key name for response-time key, defaults to "response-times"| string|

Example data:

[ { "method": "GET", "route": "/api/users", "statusCode": 200, "requests": 10 }]
[ { "method": "POST", "route": "/api/users", "statusCode": 200, "requests": 5, "date": "9/20/2020" }]
[ { "method": "GET", "route": "/api/users", "statusCode": 304, "requests": 2, "date": "9/20/2020", "hour": "12" }]

Side Notes:

  • It is very important you initialize the middleware before any of your routes or custom middleware. If you don't do this, you may find some unkown error. Further testing with it is required.
  • Any unkown request sent to the server will send the event with route of "unkown route".

Contributing:

Look at how to contribute to see how you can contribute to this project.