Giter Site home page Giter Site logo

rafalwilinski / express-status-monitor Goto Github PK

View Code? Open in Web Editor NEW
3.6K 47.0 251.0 1 MB

๐Ÿš€ Realtime Monitoring solution for Node.js/Express.js apps, inspired by status.github.com, sponsored by https://dynobase.dev

Home Page: https://dynobase.dev/

License: MIT License

HTML 11.40% JavaScript 81.85% CSS 6.74%
socket middleware express node monitoring monitoring-page observability health-checks health-check javascript

express-status-monitor's Introduction

Hi, I'm Rafal ๐Ÿ‘‹

๐Ÿฆพ AI Lead @ Vendr
๐Ÿ˜Ž Founder of Dynobase & ChatWithCloud - CLI that lets you speak to your AWS cloud using human language
๐Ÿ‡ต๐Ÿ‡ฑ Living in Poznan, Poland

Find me elsewhere ๐ŸŒ

๐Ÿฆ Twitter
๐Ÿ“ธ Instagram
๐Ÿ‘” Linkedin

express-status-monitor's People

Contributors

bcdxn avatar benzi avatar capaj avatar codetriage-readme-bot avatar colinrcummings avatar dependabot[bot] avatar eyalcohen4 avatar fedebertolini avatar hiagodotme avatar julienbreux avatar kerumen avatar logansua avatar lucasvinals avatar malixsys avatar manojkumarmuralidharan avatar maranimatias avatar maxfindel avatar muety avatar openhoat avatar pilotpirxie avatar rafalwilinski avatar snyk-bot avatar soyuka avatar tahayk avatar takipsizad avatar thom-nic avatar tiagojsalmeida avatar tkruczek avatar travelingtechguy avatar yasharf 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

express-status-monitor's Issues

Custom namespace to avoid conflict with existing Socket.io implementation?

I plugged e-s-m into our web application with an existing socket.io component, and whilst the monitor system worked it knocked out our existing functionality with a handshaking problem.

I suspect one socket-io killed the other.

Would allowing the specification of namespace allow it to run alongside an existing socket.io implementation, or is it one socket.io per server?

Alternatively, can it be set to use an existing socket.io setup if it's present, and create it's own if not?

I haven't dug through the source, just thought I'd put it out there in case you knew off the top of your head.

Cannot read property 'listen' of null after 0.1.0 upgrade

getting the following error after the upgrade


  - index.js:39 new Server
    [buharmetre]/[socket.io]/lib/index.js:39:37

  - index.js:38 Server
    [buharmetre]/[socket.io]/lib/index.js:38:41

  - index.js:103
    [buharmetre]/[express-status-monitor]/index.js:103:32

  - layer.js:95 Layer.handle [as handle_request]
    [buharmetre]/[express]/lib/router/layer.js:95:5

  - route.js:131 next
    [buharmetre]/[express]/lib/router/route.js:131:13

  - permissions.js:46 exports.requiresAdmin
    F:/Source/buharmetre/src/lib/auth/permissions.js:46:40

  - layer.js:95 Layer.handle [as handle_request]
    [buharmetre]/[express]/lib/router/layer.js:95:5

  - route.js:131 next
    [buharmetre]/[express]/lib/router/route.js:131:13

  - permissions.js:17 exports.requireSSL
    F:/Source/buharmetre/src/lib/auth/permissions.js:17:29

  - layer.js:95 Layer.handle [as handle_request]
    [buharmetre]/[express]/lib/router/layer.js:95:5

  - route.js:131 next
    [buharmetre]/[express]/lib/router/route.js:131:13

  - route.js:112 Route.dispatch
    [buharmetre]/[express]/lib/router/route.js:112:3

  - layer.js:95 Layer.handle [as handle_request]
    [buharmetre]/[express]/lib/router/layer.js:95:5

  - index.js:277
    [buharmetre]/[express]/lib/router/index.js:277:22

  - index.js:330 Function.process_params
    [buharmetre]/[express]/lib/router/index.js:330:12

  - index.js:271 next
    [buharmetre]/[express]/lib/router/index.js:271:10

  - index.js:176 Function.handle
    [buharmetre]/[express]/lib/router/index.js:176:3

  - index.js:46 router
    [buharmetre]/[express]/lib/router/index.js:46:12

  - layer.js:95 Layer.handle [as handle_request]
    [buharmetre]/[express]/lib/router/layer.js:95:5

  - index.js:312 trim_prefix
    [buharmetre]/[express]/lib/router/index.js:312:13

  - index.js:280
    [buharmetre]/[express]/lib/router/index.js:280:7

  - index.js:330 Function.process_params
    [buharmetre]/[express]/lib/router/index.js:330:12


GET /backend/durum/ 500 1430.152 ms - -

Security Vulnerability in serveral package dependencies WS, Negotiator

NSP found these packages need to be moved from/to to fix security vulnerabilties

WS from 1.1.0 to 1.1.1 (patch fix)
Module ws has a known vulnerability: "DoS due to excessively large websocket message"

Negotiator from 0.4.9 to 0.6.1 (patch fix) ISSUE:
Module negotiator has a known vulnerability: "Regular Expression Denial of Service"

package doesn't work inside of Electron

when using this package in an application, it works fine if run in a pure Node app.

But if it is embedded in an electron app, the same configuration gives the following error when the server is asked to respond to a request:

C:\git\my-application\node_modules\express\lib\application.js:630 TypeError: interval.unref is not a function
    at config.spans.forEach.span (C:\git\my-application\node_modules\express-status-monitor\src\helpers\socket-io-init.js:44:16)
    at Array.forEach (native)
    at module.exports (C:\git\my-application\node_modules\express-status-monitor\src\helpers\socket-io-init.js:38:18)
    at middleware (C:\git\my-application\node_modules\express-status-monitor\src\middleware-wrapper.js:22:5)
    at Layer.handle [as handle_request] (C:\git\my-application\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\git\my-application\node_modules\express\lib\router\index.js:317:13)
    at C:\git\my-application\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\git\my-application\node_modules\express\lib\router\index.js:335:12)
    at next (C:\git\my-application\node_modules\express\lib\router\index.js:275:10)
    at expressInit (C:\git\my-application\node_modules\express\lib\middleware\init.js:40:5)

I can run the exact code by launching it from node and it is fine.

My code is pretty standard Express start up ... here it is :

        var app = express();

        doLogging = true;
        
        app.set('port', port);
        app.use(expressStatusMonitor());

        // point for static assets
        app.use(express.static(publicPath));

        //view engine setup
        app.set('views', viewPath);
        app.engine('html', require('ejs').renderFile);
        app.set('view engine', 'html');

        if (doLogging) {
            app.use(logger('dev'));
        }
        app.use(bodyParser.json());
        app.use(bodyParser.urlencoded({
            extended:true
        }));

        app.use('/', routes);

        app.use(cookieParser());

        var server = app.listen(port, function () {
            if (doLogging) {
                console.log('Express server listening on port ' + server.address().port);
            }
        });

Any help..??? None of my app uses socket IO (not sure if native electron does, but I think it does)...

Kim

ready file to read file sync

Hi @RafalWilinski I was trying to add some tests to the middleware and I just noticed that the routine that reads the html file containing the template is asynchronous; I think it should be synchronous and I believe it will also fix some initial loading problems (sometimes you don't see any info in the console)

I am referring in particular to:

https://github.com/RafalWilinski/express-status-monitor/blob/master/index.js#L79-L85

  let renderedHtml;
  fs.readFile(path.join(__dirname, '/index.html'), function (err, html) {
    renderedHtml = html.toString()
      .replace(/{{title}}/g, config.title)
      .replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/app.js')))
      .replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/style.css')));
  });

the code should be changed into:

  let renderedHtml =
    fs.readFileSync(path.join(__dirname, '/index.html'))
      .toString()
      .replace(/{{title}}/g, config.title)
      .replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/app.js')))
      .replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/style.css')));

if you think this is a good idea I will start raising a PR w/ tests containing also this bit; you can review it and merge it then we can incrementally add more tests

Feature request: Ability to get the status monitor in a iFrame

I am trying to get the express-status-monitor to show up on an iFrame.
The status monitor works well with we directly load the url. But however when trying to load it inside of a frame, it is rejected because of the X-Frame-Options header being set to 'SAMEORIGIN'.
Can we add a option in config, that by default sets it to SAMEORIGIN, but if we want to able to embed, then it disables the X-Frame-Options header for the monitor page ?

Automate publishing to npm once PR is merged

The current version of the module is 0.1.8. However the npm module which is published is 0.1.7. Can we add a step to automate publishing to npm, as soon as a PR is merged ? Also can we publish 0.1.8 to npm, asap ?

Customisable page title

Hi there!

It'd be nice to be able to specify a title property in the config which is used to set the title shown on the status chart page and window title.

e.g

path: '/status',
title: 'AwesomeApp Server Status'
spans: [{
  interval: 1,     // Every second
  retention: 60    // Keep 60 datapoints in memory
}, {
  interval: 5,     // Every 5 seconds
  retention: 60
}, {
  interval: 15,    // Every 15 seconds
  retention: 60
}]

Would then display the specified string (AwesomeApp Server Status) on the output status page rather than the default Express Status

No data

Hi,

I did like requested, I put the code just after init of express :

var app = express();

app.use(require('express-status-monitor')());

And I get no data when I go to /status:

capture d ecran 2016-08-18 a 09 42 49

Any idea how to fix that? (my host is heroku)

Host a demo app on AWS spot instance

Just like title says. Give everyone opportunity to see tool in action without downloading & installing it. Use AWS Spot (probably with spotinst?) because it's one of the most cheapest solutions, it also could integrate very nicely with CodeDeploy + github webhooks etc. Heroku is not an option because it goes down every X minutes.

License in Project

Hey Rafal,

You mention an MIT license in the readme, but don't include the license in the project. Could you add a license.txt with the following or can I create a PR?

Thanks for the project btw!

MIT License

Copyright (c) 2016 Rafal Wilinski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Error: 27676 does not exist at ChildProcess

Not sure if this is a pidusage or a express-status-monitor problem, but when running nodejs I will sometimes(seemingly randomly) get multiple errors that show have the same number error. It appears as follows,

Error: 27676 does not exist
at ChildProcess. (\node_modules\pidusage\lib\stats.js:151:21)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Process.__dirname.ChildProcess._handle.onexit (internal/child_process.js:226:5)

Socket connections are not authenticated

While mounting at a path (barring #63) allows for authenticating the user HTML page the socket connection appears to be unauthenticated.

Looking at this article it is not difficult to authenticate socket.io sessions. The first part (io.use(...)) looks like it can be done by the user and the io instance passed in the config arg down to socketIoInit.

However the second part (checking the socket.request.user on connect) still needs to happen. This could be doable by taking a user-defined callback which you would call inside the connect handler, which should return true if the connection is authorized.

Socket.io not working

Followed instructions getting this error with default settings:

err

Running on:
Ubuntu 14.04.4 with node v6.2.2

support different ports on html and nodejs, or listen(server)

Nice project, thanks for making this!

I found that this does not work for my setup. I have an ngnix sits in front of my nodejs app, and SSL terminates on nginx.

Suppose my site is https://www.a.com

The html will let the js try to connect https://www.a.com:41388, this will not work because nodejs level does not support ssl. I cannot make nginx listen on 41388, because nodejs already took that.

To solve the issue, I think there are 2 options:

  1. extend the config, add one more public port. so js will use this port to connect, it will reach nginx, then redirects to nodejs port. This requires nginx and nodejs listen on two different ports. Now the config does not support that.
  2. let socket.io listen on the same port with express, I think it is doable, by listen(server)

I prefer 2), it is cleaner and use one less port.

Please let me know what do you think, thanks a lot!

unneeded comparison

This kind of comparison config === {} (here) will always return false because {} here is a new object literal.

Unnecessary IIFE in index.js

Why index.js is wrapped in IIFE? As far as I know this is only useful in front-end world if you are not using any module bundler and are worriend about other libraries using global variables with same name.

Since 0.1.1 node 4 not working anymore.

It is missing a "use strict" in the index.js which was there in 0.1.0

/home/app/server/node_modules/express-status-monitor/index.js:7
let io;
^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.exports.init (/home/app/server/app/config/express.js:27:10)
at Object. (/home/app/server/serverapp.js:2:50)
at Module._compile (module.js:409:26)

request/response stats don't appear to work when mounted at a path

I followed the readme example and mounted the monitor like:

    router.get('/status', authenticated, require('express-status-monitor')());

in order to authenticate requests to the status monitor page. However when doing so it appears request stats are no longer captured, presumably because the status monitor isn't acting as a middleware to intercept requests...
screen shot 2016-11-14 at 11 38 27 am

Is there a way to mount the monitor middleware separate from the UI request handler?

Error: Cannot find module 'on-headers'

When I try an example, I got an error message that "Error: Cannot find module 'on-headers'". I resolved it execute "npm install" on parent directory.

  1. clone repository
    git clone https://github.com/RafalWilinski/express-status-monitor.git
  2. change directory
    cd express-status-monitor
  3. execute command
    npm install
  4. change directory
    cd examples
  5. execute command again
    npm install
  6. start server
    node index.js

That's all. You should update README document for your cool software.

Great Job!

Deprecated 'port' config is needed

PORT config is needed especially when running two servers in the same container. Port conflicts occur otherwise.

NodeJS 4.4.7 on Ubuntu Trusty/64-140.4

Error: listen EADDRINUSE :::41338
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at Server.listen (net.js:1382:5)

Add authentication

Would be nice to have authentication for the route, so that only users with a login would be able to view the status page.

400 Bad Request

Got this error
failed: Error during WebSocket handshake: Unexpected response code: 400.
Requests per Second reach Infinity and response stops.

Using module with socket.io in project

Hi, I'm trying to add socket.io support to Hackathon Starter (https://github.com/sahat/hackathon-starter/) and am running into the following issue: sahat/hackathon-starter#621 (comment)

The person who commented was right, disabling Express-Status-Monitor does work, but ideally I'd like to get everything working. The documentation seems a little vague, you mention setting a port but I don't see that config option documented. Regardless, I tried

app.set('port', process.env.PORT || 3000);
...
...
...
app.use(expressStatusMonitor({ websocket: io, port: app.get('port') }));

and I still cannot get everything to work correctly. io is declared as so:

const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);

Can you please advise? Thanks in advance.

Do not use sync IO methods

In

https://github.com/RafalWilinski/express-status-monitor/blob/master/index.js#L99-L100

      .replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/app.js')))
      .replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/style.css')));

You are using sync methods, this seems like a bad idea. As far as I know, sync methods will block the whole thread, while doing the IO. If you use async method, that thread will be free to handle other requests until feadFile is finished.

Spawn EPERM error when trying to run on Microsoft Azure

When trying to run express-status monitor on azure I often get the following error:

Error: spawn EPERM
at exports._errnoException (util.js line 873 col 11)
at ChildProcess.spawn (internal/child_process.js line 298 col 11)
at exports.spawn (child_process.js line 362 col 9)
at Object.stats.win (D:\home\site\wwwroot\node_modules\pidusage\lib\stats.js line 132 col 16)
at Object. (D:\home\site\wwwroot\node_modules\pidusage\index.js line 13 col 28)
at Object.exports.stat (D:\home\site\wwwroot\node_modules\pidusage\index.js line 36 col 20)
at module.exports.pidusage.stat (D:\home\site\wwwroot\node_modules\express-status-monitor\src\helpers\gather-os-metrics.js line 18 col 12)
at null._repeat (D:\home\site\wwwroot\node_modules\express-status-monitor\src\helpers\socket-io-init.js line 23 col 42)
at wrapper [as _onTimeout] (timers.js line 275 col 11)
at Timer.unrefdHandle (timers.js line 312 col 14)

Cannot read property 'memory' of null

I recently installed Express-status-monitor which seems to make use of pidusage and it is causing an error. The status page seems to function fine, but my nodejs app will randomly crash with the following error,

TypeError: Cannot read property 'memory' of null
at \node_modules\express-status-monitor\index.js line 43 col 25)
at ChildProcess. (\node_modules\pidusage\lib\stats.js line 151 col 16)
at emitTwo (events.js line 100 col 13)
at ChildProcess.emit (events.js line 185 col 7)
at maybeClose (internal/child_process.js line 827 col 16)
at Process.__dirname.ChildProcess._handle.onexit (internal/child_process.js line 211 col 5)

Does not work over HTTPS (on Heroku)

Just added the route to an Express app I have deployed to Heroku and I'm getting the following error (repeated every second):

Mixed Content: The page at 'https://mysitename.herokuapp.com/status' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://mysitename.herokuapp.com:41338/socket.io/?EIO=3&transport=polling&t=LQPzECX'. This request has been blocked; the content must be served over HTTPS.

XMLHttpRequest cannot load http://mysitename.herokuapp.com:41338/socket.io/?EIO=3&transport=polling&t=LQPzECX. Failed to start loading.

Can you maybe provide a way to specify whether the Socket.io call be made over HTTPS, or better yet, handle this automatically?

Does not work with nodemon

While running my express app with nodemon version 3.7.3, I did receive the following error:

stat.memory = stat.memory / 1024 / 1024;
TypeError: Cannot read property 'memory' of null

It then ends the nodemon process.

Great package - thank you!

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.