目录
ceph 命令下发流程:命令行-->python 前端部分处理-->Admin Socket后端部分处理
前端部分 python
https://blog.csdn.net/bandaoyu/article/details/123746755
后端部分 Admin Socket
任何一个成熟的项目,必须要提供出接口,就像探针一样,可以让我们探查进程内部的运行情况,进程不能是一个黑盒子。对于ceph而言,Admin Socket 提供了该功能。
Admin Socket 不仅可以查看当前的配置,进程运行的状态,而且,还可以修改配置,获取log等。
下面help可以看出,ceph给出了很多命令,来了解ceph内部的运行情况。
root@test3:~# ceph daemon /var/run/ceph/ceph-osd.4.asok help
{ "config get": "config get : get the config value",
"config set": "config set [ ...]: set a config variable",
"config show": "dump current config settings",
"dump_blacklist": "dump blacklisted clients and times",
"dump_historic_ops": "show slowest recent ops",
"dump_op_pq_state": "dump op priority queue state",
……
}
root@test3:~# ceph daemon /var/run/ceph/ceph-mon.*.asok help
{ "add_bootstrap_peer_hint": "add peer address as potential bootstrap peer for cluster bringup",
"config get": "config get : get the config value",
"config set": "config set [ ...]: set a config variable",
"config show": "dump current config settings",
"get_command_descriptions": "list available commands",
"git_version": "get git sha1",
"help": "list available commands",
"log dump": "dump recent log entries to log file",
……
}
root@test3:~# ceph daemon /var/run/ceph/ceph-mds.*.asok help
{ "config get": "config get : get the config value",
"config set": "config set [ ...]: set a config variable",
"config show": "dump current config settings",
"get_command_descriptions": "list available commands",
"git_version": "get git sha1",
……
}
比如可以查看 ceph的各个模块的当前配置
ceph daemon /var/run/ceph/ceph-mds.*.asok config show
ceph daemon /var/run/ceph/ceph-mon.*.asok config show
ceph daemon /var/run/ceph/ceph-osd.4.asok config show
这个是怎么实现的呢? 这是依靠ceph的AdminSocket机制完成。
CephContext中会创建一个AdminSocket对象,该对象本质是一个线程。
ceph-mon/ceph-osd/ceph-mds这些进程都会有创建一个AdminSocket的线程,负责响应用户的探查命令。
从上面的OSD MON MDS help的不同输出可以看出,他们支持的命令有共同的,也有各自独立的。
首先是共同支持的命令有:
- config show 显示所有的配置项
- config get 获取某个配置项
- config set 设置某个配置项
- log flush 将log 刷入日志文件
- log dump 将最近的若干笔log刷入到log文件
- log reopen 重新打开log文件
- perf dump 输出统计信息
- perf schema 输出统计信息的类型
- version 版本信息
- git_version : git 版本信息
支持的大部分common的命令,注册发生在 CephContext的构造函数:
_admin_hook = new CephContextHook(this);
_admin_socket->register_command("perfcounters_dump", "perfcounters_dump", _admin_hook, "");
_admin_socket->register_command("1", "1", _admin_hook, "");
_admin_socket->register_command("perf dump", "perf dump", _admin_hook, "dump perfcounters value");
_admin_socket->register_command("perfcounters_schema", "perfcounters_schema", _admin_hook, "");
_admin_socket->register_command("2", "2", _admin_hook, "");
_admin_socket->register_command("perf schema", "perf schema", _admin_hook, "dump perfcounters schema");
_admin_socket->register_command("config show", "config show", _admin_hook, "dump current config settings");
_admin_socket->register_command("config set", "config set name=var,type=CephString name=val,type=CephString,n=N", _admin_hook, "config set [ ...]: set a config variable");
_admin_socket->register_command("config get", "config get name=var,type=CephString", _admin_hook, "config get : get the config value");
_admin_socket->register_command("log flush", "log flush", _admin_hook, "flush log entries to log file");
_admin_socket->register_command("log dump", "log dump", _admin_hook, "dump recent log entries to log file");
_admin_socket->register_command("log reopen", "log reopen", _admin_hook, "reopen log file")
(一个AdminSocketHook(_admin_hook)可以对应多个command,里面再细分)
首先定义了个CephContextHook,注册该Hook也作为一个参数传递进去,这个register_command比较简单,就是建立了command字符串和Hook的关联,这个关联有何作用,后面会分析到,暂时按下不表。
int AdminSocket::register_command(std::string command, std::string cmddesc, AdminSocketHook *hook, std::string help)
{
int ret;
m_lock.Lock();
if (m_hooks.count(command)) {
ldout(m_cct, 5) << "register_command " << command << " hook " << hook << " EEXIST" << dendl;
ret = -EEXIST;
} else {
ldout(