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

detective-node

v0.1.1

Published

๐Ÿ”Ž A distributed application health monitoring library

Downloads

9

Readme

Detective ๐Ÿ”Ž

Build Status Coverage Status

Detective is a distributed application health monitoring library. It allows you to monitor arbitrary dependencies in your application, and compose other detective instances to create a distributed monitoring framework.

โœ… Zero npm dependencies
โœ… Interoperable with instances using the Go client
โœ… Compatible with the standard HTTP server implementation and express.js

Installation

npm install --save detective-node

or

yarn add detective-node

Usage

For detailed documentation, visit the Godocs page

A typical service oriented architecture looks like this:

Detective allows you to enable each application to monitor its own dependencies, including dependencies with contain another detective instance. By doing so, you can monitor your infrastructure in a distributed manner, where each service only monitors it's own dependencies.

service oriented architecture with detective

Monitoring a single application

Detective exposes a straightforward API to monitor an arbitrary dependency:

const Detective = require('detective-node')

// Initialize a new detective instance
const detective = new Detective('Another Application')

// Initialize an arbitrary dependency, and set its detector function
detective.dependency('db').detect((cb) => {
  // The detector function is supplied with a callback argument
  // `cb` should be called with no arguments for a successful check
  // or with a single argument (typically an `Error` type) for a failed dependency
  // Here, we use the database client of the `pg` node module to make a ping query to our database
  client.query('select now()', (err) => cb(err))
})

// The `handler` method returns an http handler that can be used with
// the standard node HTTP server
const server = http.createServer(detective.handler())

server.listen(8081)

See the "basic usage" example

The HTTP endpoint can then be used to monitor the health of the application. A GET request to http://localhost:8081/ will return information on the health of the overall application:

{
  "name": "Another Application",
  "active": true,
  "status": "Ok",
  "latency": 0,
  "dependencies": [
    {
      "name": "db",
      "active": true,
      "status": "Ok",
      "latency": 500848512
    }
  ]
}

Composing instances

The endpoint in the previous example can also be used by other detective instances. For example, an application that makes use of "Another application" can monitor it as well:

const detective = new Detective('your application')

detective.dependency('cache').detect((cb) => {
  myCache.ping(err => {
    cb(err)
  })
})

detective.dependency('db').detect((cb) => {
  client.query('select now()', (err) => cb(err))
})

// Add an endpoint, which represents another detective instance ("Another application" in this case)
detective.endpoint('http://localhost:8081')

const server1 = http.createServer(detective.handler())
server1.listen(8080)

See the "composing detective instances" example

Now, when we hit GET http://localhost:8080/, its detective instance will monitor its own dependencies as usual, but also hit the previous dependencies endpoint, and as a result monitor it's dependencies as well :

{
  "name": "your application",
  "active": true,
  "status": "Ok",
  "latency": 0,
  "dependencies": [
    {
      "name": "Another application",
      "active": true,
      "status": "Ok",
      "latency": 0,
      "dependencies": [
        {
          "name": "db",
          "active": true,
          "status": "Ok",
          "latency": 502210954
        }
      ]
    },
    {
      "name": "db",
      "active": true,
      "status": "Ok",
      "latency": 2500328773
    },
    {
      "name": "db",
      "active": true,
      "status": "Ok",
      "latency": 2500248450
    }
  ]
}

Circular dependencies

It's possible for two applications to depend on each other, either directly, or indirectly. Normally, if you registered two detective instances as dependents of each other, it would result in an infinite loop of HTTP calls to each others ping handler. Detective protects against this situation by adding information about a calling instance to the HTTP header of its request. The callee then inspects this header to find out if it was already part of the calling chain, in which case it ceases to send endpoint HTTP requests, and breaks the circular dependency chain.

Dashboard

The dashboard helps visualize your dependency tree and detect any faulty dependencies, along with their latency:

dashboard picture

To run the dashboard, download the binary from the releases

Or, if you have Go installed, install the binary with:

go get github.com/sohamkamani/detective/detective-dashboard
go install github.com/sohamkamani/detective/detective-dashboard

Then start the dashboard with:

detective-dashboard -p 8080
## Starts dashboard on http://localhost:8080/

You will then have to enter the URL of any detective endpoint to view its dashboard.

Examples

API documentation

The detailed API documentation can be found here