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

omelox-admin

v4.2.6

Published

[![Build Status](https://travis-ci.org/node-omelox/omelox-admin.svg?branch=master)](https://travis-ci.org/node-omelox/omelox-admin)

Downloads

44

Readme

Build Status

#omelox-admin

omelox-admin is an admin console library for omelox. It provides the a series of utilities to monitor the omelox server clusters.

##Installation

npm install omelox-admin

##Basic conception

###Process roles

There are three process roles in omelox-admin: master, monitor and client.

  • master - the master server process, collects and maintains all the client and monitor status and exports the cluster status for the clients.

  • monitor - monitor proxy, in every server process which needs to be monitored. It should be started during the process starts and registers itself to the master server and reports the monitored process status to the master.

  • client - omelox-admin client process that fetches the status from master server, such as omelox-admin-web and omelox-cli.

###Message types

There are two message types of the communication between processes.

  • request - bidirectional message that cooperated with response.

  • notify - unidirectional message.

##Components

###ConsoleService

Main service of omelox-admin that runs in both master and monitor processes. It maintains the master agent or monitor agent for the process, loads the registed modules and provides the messages routing service for the messages from other processes.

###MasterAgent

omelox-admin agent that runs on the master process to provide the basic network communication and protocol encoding and decoding.

###MonitorAgent

omelox-admin agent that runs on the monitor process to provide the basic network communication and protocol encoding and decoding.

###Module

Module is the place to implement the monitor logic, such as process status collecting. Developer can register modules in omelox-admin to customize all kinds of system monitors.

There are three optional callback functions in each module.

  • function masterHandler(agent, msg, cb) - callback in master process to process a message from monitor process or a timer event in master process.

  • function monitorHandler(agent, msg, cb) - callback in monitor process to process a message from master process or a timer event in monitor process.

  • function clientHandler(agent, msg, cb) - callback in master process to process a message from client.

The relations of the components is as below:

##Usage

var admin = require("omelox-admin");

Create a consoleService instance in master process.

var masterConsole = admin.createMasterConsole({  
    port: masterPort  
});  

Register an admin module.

masterConsole.register(moduleId, module);  

Start masterConsole.

masterConsole.start(function(err) {  
  // start servers  
});  

Create a consoleService instance in monitor process.

var monitorConsole = admin.createMonitorConsole({  
    id: serverId,  
    type: serverType,  
    host: masterInfo.host,  
    port: masterInfo.port,  
    info: serverInfo  
}); 

##Customized modules

Developers can customize modules to collect and export additional status as they need.

###Simple example

var Module = function(app, opts) {
  opts = opts || {};
  this.type = opts.type || 'pull';  // pull or push 
  this.interval = opts.interval || 5; // pull or push interval
};

Module.moduleId = 'helloOmelox';

module.exports = Module;

Module.prototype.monitorHandler = function(agent, msg) {
  var word = agent.id + ' hello omelox';
  // notify admin messages to master
  agent.notify(Module.moduleId, {serverId: agent.id, body: word});
};

Module.prototype.masterHandler = function(agent, msg) {
  // if no message, then notify all monitors to fetch datas
  if(!msg) {
    agent.notifyAll(Module.moduleId);
    return;
  }
  // collect data from monitor
  var data = agent.get(Module.moduleId);
  if(!data) {
    data = {};
    agent.set(Module.moduleId, data);
  }

  data[msg.serverId] = msg;
};

Module.prototype.clientHandler = function(agent, msg, cb) {
  // deal with client request,directly return data cached in master
  cb(null, agent.get(Module.moduleId) || {});
};

###Register customized modules

you must register your customized modules to omelox to make it work.
write in app.js which is in your project's root directory

app.configure('production|development', function() {
  app.registerAdmin('helloOmelox',new helloOmelox());
});

##User level control
omelox-admin defines user level for admin client to login master server in this schema

{
    "id": "user-1",
    "username": "admin",
    "password": "admin",
    "level": 1
}

level defines the user admin level
level 1 means the user has the admin permission, this user can do anything
other level user will have limited permission
currently add, stop, kill will require level 1 permission

note: by default you should provide adminUser.json file under the config dir
adminUser.json

[{
    "id": "user-1",
    "username": "admin",
    "password": "admin",
    "level": 1
}, {
    "id": "user-2",
    "username": "monitor",
    "password": "monitor",
    "level": 2
},{
    "id": "user-3",
    "username": "test",
    "password": "test",
    "level": 2
}
]

##Self-defined auth omelox-admin provides a simple auth function in omelox-admin auth
developers can provide self-defined auth in omelox by
in master server

app.set('adminAuthUser', function(msg, cb){
  if(auth success) {
    cb(user);
  } else {
    cb(null);
  }
})

##Server master auth
server connect to master with authorization
omelox-admin provides a simple auth function in omelox-admin auth
developers can provide self-defined auth in omelox by
in master server

app.set('adminAuthServerMaster', function(msg, cb){
  if(auth success) {
    cb('ok');
  } else {
    cb('bad');
  }
})

in monitor server

app.set('adminAuthServerMonitor', function(msg, cb){
  if(auth success) {
    cb('ok');
  } else {
    cb('bad');
  }
})

note: by default you should provide adminServer.json file under the config dir
adminServer.json

[{
    "type": "connector",
    "token": "agarxhqb98rpajloaxn34ga8xrunpagkjwlaw3ruxnpaagl29w4rxn"
}, {
    "type": "chat",
    "token": "agarxhqb98rpajloaxn34ga8xrunpagkjwlaw3ruxnpaagl29w4rxn"
},{
    "type": "gate",
    "token": "agarxhqb98rpajloaxn34ga8xrunpagkjwlaw3ruxnpaagl29w4rxn"
}
]

type is the serverType, token is a string you can genrate by yourself
when using in omelox, you should fill all your servers with type:token

###Notes

omelox-admin provides a series of useful system modules by default. But most of them are turned off by default. Add a simple line of code in app.js as below to enable them.

app.configure('development', function() {
  // enable the system monitor modules
  app.enable('systemMonitor');
});