Danil_Valov

Simple real-time Monitoring for server

Recommended Posts

Danil_Valov    19

Create file `monitoring.js` to directory `packages/keker` with the following code:

// Require nodejs module `http`
const http = require('http');

// Create web server
const server = http.createServer(function(request, response) {
  // Show monitoring for any request
  response.writeHead(200, {"Content-Type": "text/html"});
  response.write(`<br>Players: ${mp.players.length}/${mp.players.size}`);
  response.write(`<br>Uptime: ${process.uptime()}`);
  response.end();
});

// Turn on the web server on the port 8080
// (you can change it to any port)
server.listen(8080);

// Show message in terminal about successful starting of Monitoring Server
console.log('\nMonitoring Server is listening');

 

Append to file `packages/keker/index.js` the following code:

require('./monitoring');

 

Now when you open url http://your_ip:8080 you see the following data:

Цитата

Players: 1/100
Uptime: 637.516

 

Also you can change the port of web server in `monitoring.js`. And you can change the data format to JSON if you need.

  • Like 4

Share this post


Link to post
Share on other sites
Urukhay    0

Why is "netstat -nlp" not listening port 8080 after running ragemp-server with this monitoring? But service "node monitoring.js" activates the port 8080.

Maybe this because i have installed node_modules in the root server directory (where conf.json)? Because i tested require with another file (mysqlSaver.js that requires npm Mysql) from index.js, but mysql-function was not called from index.js.

Like the:

"use strict";

global.dimensions = {};

const events = require('./events');

var f = require("./mysqlSaver.js"); // my file that requires mysql from npm (provides module.exports.savePlayer as function)

f.savePlayer("Test"); // Mysql-saving not happend

 

Edited by Urukhay

Share this post


Link to post
Share on other sites
Danil_Valov    19
В 11.01.2017 в 10:22, Urukhay сказал:

Why is "netstat -nlp" not listening port 8080 after running ragemp-server with this monitoring? But service "node monitoring.js" activates the port 8080.

If you use the Docker then you need to open this port (8080) there.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.