Giter Site home page Giter Site logo

rcruzper / express-actuator Goto Github PK

View Code? Open in Web Editor NEW
92.0 3.0 23.0 649 KB

Express middleware with endpoints to help you monitor and manage applications

License: MIT License

JavaScript 100.00%
metrics monitor actuator health-check nodejs express middleware

express-actuator's Introduction

Express Actuator

npm version Build Status Coverage Status Known Vulnerabilities Libraries.io dependency status for latest release npm

This middleware creates a series of endpoints to help you monitor and manage your application when it's pushed to production. It's useful when you run your application on kubernetes and you are in need of endpoints for readiness/liveness probe.

It is based on Spring Boot Actuator and the healthcheck-ping module by Mathias Schreck.

Table of Contents

Endpoints

ID Description
info Displays application information.
metrics Shows metrics information for the current application.
health Shows application health information.

Installation

$ npm install --save express-actuator

Typescript

$ npm install --save-dev @types/express-actuator

Usage

const actuator = require('express-actuator');
const app = express();

app.use(actuator());

Configuring Actuator

All defined options are optional:

const options = {
    basePath: '/management', // It will set /management/info instead of /info
    infoGitMode: 'simple', // the amount of git information you want to expose, 'simple' or 'full',
    infoBuildOptions: null, // extra information you want to expose in the build object. Requires an object.
    infoDateFormat: null, // by default, git.commit.time will show as is defined in git.properties. If infoDateFormat is defined, moment will format git.commit.time. See https://momentjs.com/docs/#/displaying/format/.
    customEndpoints: [] // array of custom endpoints
};

app.use(actuator(options));

Custom Endpoints

You can add your own validations using the customEndpoints option:

const options = {
    customEndpoints: [
        {
            id: 'dependencies', // used as endpoint /dependencies or ${basePath}/dependencies
            controller: (req, res) => { // Controller to be called when accessing this endpoint
                // Your custom code here
            }
        }
    ]
};

app.use(actuator(options));

IMPORTANT:

  1. If you call your custom endpoint info it WILL override the default info.
  2. If you provide basePath, your id will be available as ${basePath}/${id}, otherwise, just /${id}.
  3. Consider lightweight code being processed by your endpoint controller or it will compete with your main application.

Deprecated mode

To have backward compatibility with previous versions (<= 1.2.0) the legacy way is still available:

app.use(actuator('/management')); // It will set /management/info instead of /info

IMPORTANT: Deprecated mode will be removed in the next major version.

Endpoints Examples

info

{
    "build": {
        "description": "This is my new app",
        "name": "MyApp",
        "version": "1.0.0"
    },
    "git": {
        "branch": "master",
        "commit": {
            "id": "329a314",
            "time": "2016-11-18 08:16:39-0500"
        }
    }
}

IMPORTANT: To get this information the middleware have some sort of logic:

  1. When the express app is executed with node app.js or npm start the module will look for a file named package.json where the node command was launched.
  2. Git information will show only if exists a git.properties file where the app was launched. You can use node-git-info to generate this file.

metrics

{
    "mem": {
        "heapTotal": 14659584,
        "heapUsed": 10615072,
        "rss": 30093312
    },
    "uptime": 19.797
}

health

{
  "status": "UP"
}

Application Information

Git Commit Information

The info endpoint has a feature to publish information about your git source code repository. If a git.properties file is available on your project path, the git.branch, git.commit.id, and git.commit.time properties are exposed.

TIP: You can use node-git-info to generate git.properties file on your project.

If you want to display the full git information (that is, the full content of git.properties), use the infoGitMode property, as follows:

const options = {
    infoGitMode: 'full'
};

app.use(actuator(options));

Contributing

Third-party contributions are welcome! ๐Ÿ™๐Ÿผ See CONTRIBUTING.md for step-by-step instructions.

If you need help or have a question, let me know via a GitHub issue.

express-actuator's People

Contributors

dependabot[bot] avatar etruta avatar fodor0205 avatar garyboyle avatar mapfap avatar nicolasonespandev avatar rcruzper avatar rmalveis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

express-actuator's Issues

Properties parser parses some git commit IDs as numbers

If you have a git short ID like:

  • 296e115
  • 3324244
    Then both of those are parsed as numbers and returned as numbers from the endpoint. This is not great but less of an issue with the second. However the first one is treated as an exponential and in my case rendered as "2.96e+117".

Blocking file read each time info route is called

The info route calls FS.readFileSync each time the route is called. This is a blocking IO call that will block the event loop added latency to requests and potentially being a route to a DOS attack. It could just be done once on program load or on the first call to the endpoint.

Interface to custom endpoints

Hi!
I really liked the simplicity of this project.

As Spring actuator already knows, sometimes we want custom endpoints for monitoring dependencies or to show another info that is important in our case scenario.
What you think about custom endpoints made by the user?

(maybe some of them can become standard out of the box, but keep this flexible while the standard versions does not exists seems useful)

how can I see the detail for health endpoints?

1653881644(1)

yeah, I want to return some health endpoint details for my node sever by express-actuator middleware, but it can only return { status: 'up' }, no show-detail parameter.
Could you give me some suggestions?
Thank you very much๏ผ

Git Message Unavailable in /Info Endpoint

I See the git info available in the /info endpoint is limited.
Can you please add git message also.

            branch: data['git.branch'],
            commit: {
                id: data['git.commit.id.abbrev'],
                message: data['git.commit.message.short'],
                time: moment(data['git.commit.time'], moment.ISO_8601).valueOf()
            }
        }`

Allow overriding default endpoints

Allow overriding default endpoints (for example /health) with a custom controller definition.

A possible implementation is using the existing customEndpoints array in a backwards-incompatible way like in #37.

Feature Request: Add index page for conformity with Spring Boot Actuator

Would it be possible to output available endpoints when accessing the middleware's root? For example, in Spring Boot's Actuator going to /actuator will return the following result:

{
    "_links": {
        "self": {
            "href": "http://example.com/actuator",
            "templated": false
        },
        "health": {
            "href": "http://example.com/actuator/health",
            "templated": false
        },
        "info": {
            "href": "http://example.com/actuator/info",
            "templated": false
        },
        ...
    }
}

improve tests

The integration tests are not working properly.
The expect section doesn't work and the output from those tests are false positive.
The mock-fs implementation doesn't work either, it only works calling mocha directly, if npm test is called the tests fail so, the CI fails

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.