技术文章 > 服务端 > pomelo-cli使用 

pomelo-cli 使用

    pomelo-cli 交互式命令行 pomelo-cli 提供了一个交互式命令行,开发者可以使用这个工具对使用 pomelo 框架开发的应用和服务进行运维。

安装

npm install -g pomelo-cli

登录

pomelo-cli -h host -P port -u username -p password
默认的 pomelo-cli 登录参数:
pomelo-cli -h 127.0.0.1 -P 3005 -u monitor -p monitor
登录用户的用户名密码权限等级是在 config/adminUser.json 里面进行配置的。
对于 kill, stop, add ,enable, disable 等命令是受权限限制的,非 admin 用户将无权进行操作。

命令

use
使用某个 context 来进行操作,context 可以是 serverId 或者是 all:
use {serverId|all}
之后你的命令就会被应用到该 context。
例一:use area-server-1
例二:use all
quit
敲入 quit 你就会退出 pomelo-cli。
kill
关闭所有服务器,小心使用。
exec
执行脚本文件,在这之前, 需要设置 app master 服务器配置:
app.configure('production|development', 'master', function() {
        app.enable('systemMonitor');
}
exec {filepath}
filepath 可以是相对于 pomelo-cli 命令执行的路径,如:
use chat-server-1 #use all 不可以,必须要指定服务器 Id
exec xxx.js
filepath 也可以是以 / 开头的绝对路径:
exec /home/user/xxx.js
脚本文件的执行是通过 vm 模块,vm context 是 node_modules/pomelo/pomelo-admin/lib/modules/scripts.js 文件:
var context = {
  app: this.app,
  require: require,
  os: require("os"),
  fs: require("fs"),
  process: process,
  util: util
};
只能使用 context 里引用的模块,其他模块都不可用,例如 console.log() 也会报 undefined。 执行结果是通过 result 参数,因此,你在脚本文件里,你需要使用result来得到返回结果,如 getCPUs.js:
var cpus = os.cpus();
result = util.inspect(cpus,true,null);
get
等价于 app.get(key)
set
等价于 app.set(key, value)
add
动态添加服务器到 pomelo 集群中。add 参数是来自于 servers.json 配置文件中的 key = value 对:
add host=127.0.0.1 port=3451 serverType=chat id=chat-server-2  
add host=127.0.0.1 port=3152 serverType=connector id=connector-server-3 clientPort=3012 frontend=true 
添加服务器必须使用正确完整的参数,否则添加的服务器会处于 bad 模式。
stop
停止服务器,以 serverId 作为参数:
stop area-server-1 
show
查看如下信息:servers, connections, logins, modules, status, proxy, handler, components, settings。
show servers
show connections  
show proxy 
show handler 
show logins
只有查看 servers 的时候是可以在任何一个 context 下面的,其他的所有的信息查看必须在某一个 server 的 context 下进行。
enable
启用 admin module 或者 app 。
enable module systemInfo
enable app systemMonitor
disable
禁用 admin module 或者 app 。
dump
dump v8 heap 和 cpu 以供之后的分析。
dump cpu|memory {filepath} [times] [--force]
times 是 cpu dump 所需要的时间,以秒为单位。
使用 --force 来覆盖写入已经存在的文件。如:
dump cpu /home/xxx/test 5  
dump memory /home/xxx/test 

dump cpu /home/xxx/test 5 --force		
dump memory /home/xxx/test --force
分析 dump 结果:打开google chrome浏览器,按下 F12 来打开浏览器控制台,找到profile标签,右键选择 Load profile...,选择dump文件,点击open。


来源:https://github.com/NetEase/pomelo/wiki/pomelo-cli%E4%BD%BF%E7%94%A8,本站 行痴 摘抄,2023-08-23