sds genRedisInfoString(char *section) {
sds info = sdsempty();
time_t uptime = server.unixtime-server.stat_starttime;
int j;
struct rusage self_ru, c_ru;
int allsections = 0, defsections = 0;
int sections = 0;
if (section == NULL) section = "default";
allsections = strcasecmp(section,"all") == 0;
defsections = strcasecmp(section,"default") == 0;
getrusage(RUSAGE_SELF, &self_ru);
getrusage(RUSAGE_CHILDREN, &c_ru);
/* Server */
if (allsections || defsections || !strcasecmp(section,"server")) {
static int call_uname = 1;
static struct utsname name;
char *mode;
if (server.cluster_enabled) mode = "cluster";
else if (server.sentinel_mode) mode = "sentinel";
else mode = "standalone";
if (sections++) info = sdscat(info,"\r\n");
if (call_uname) {
/* Uname can be slow and is always the same output. Cache it. */
uname(&name);
call_uname = 0;
}
unsigned int lruclock;
atomicGet(server.lruclock,lruclock);
info = sdscatprintf(info,
"# Server\r\n"
"redis_version:%s\r\n" //redis版本
"redis_git_sha1:%s\r\n" //git sha1
"redis_git_dirty:%d\r\n" //git dirty flag
"redis_build_id:%llx\r\n" //redis build id
"redis_mode:%s\r\n" //运行模式,单机或集群
"os:%s %s %s\r\n" //redis服务器的宿主操作系统
"arch_bits:%d\r\n" //架构(32位或64位)
"multiplexing_api:%s\r\n" //所使用的事件处理机制,epoll
"atomicvar_api:%s\r\n" //new,所使用的GNU Compiler Collection,原子处理API
"gcc_version:%d.%d.%d\r\n" //编译时使用的gcc版本
"process_id:%ld\r\n"//redis服务进程pid
"run_id:%s\r\n" //redis服务器的随机标识符(用于sentinel和集群)
"tcp_port:%d\r\n" //服务器监听端口
"uptime_in_seconds:%jd\r\n" //服务器启动总时间,s
"uptime_in_days:%jd\r\n" //服务启动总时间,单位天
"hz:%d\r\n" //redis内部调度(进行关闭timeout的客户端,删除过期key等等)频率,程序规定serverCron每秒运行10次,实际;根据dynamic-hz的可选值为yes和no,5.0.8新增
"configured_hz:%d\r\n" //new,已设置的hz,基准
"lru_clock:%ld\r\n" //自增的时钟,用于LRU管理,该时钟100ms(hz=10,因此每1000ms/10=100ms执行一次定时任务)更新一次。
"executable:%s\r\n" //执行文件的位置
"config_file:%s\r\n", //配置文件的路径
REDIS_VERSION,
redisGitSHA1(),
strtol(redisGitDirty(),NULL,10) > 0,
(unsigned long long) redisBuildId(),
mode,
name.sysname, name.release, name.machine,
server.arch_bits,
aeGetApiName(),
REDIS_ATOMIC_API,
#ifdef __GNUC__
__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__,
#else
0,0,0,
#endif
(long) getpid(),
server.runid,
server.port,
(intmax_t)uptime,
(intmax_t)(uptime/(3600*24)),
server.hz,
server.config_hz,
(unsigned long) lruclock,
server.executable ? server.executable : "",
server.configfile ? server.configfile : "");
}
/* Clients */
if (allsections || defsections || !strcasecmp(section,"clients")) {
size_t maxin, maxout;
getExpansiveClientsInfo(&maxin,&maxout);
if (sections++) info = sdscat(info,"\r\n");
info = sdscatprintf(info,
"# Clients\r\n"
"connected_clients:%lu\r\n" //已连接的客户端数目(不包括slave)
"client_recent_max_input_buffer:%zu\r\n" //new,当前连接的客户端当中,最大输入缓存,与3.2.8求法不同
"client_recent_max_output_buffer:%zu\r\n" //当前连接的客户端当中,最长的输出列表
"blocked_clients:%d\r\n", //正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客户端的数量
listLength(server.clients)-listLength(server.slaves),
maxin, maxout,
server.blocked_clients);
}
/* Memory */
if (allsections || defsections || !strcasecmp(section,"memory")) {
char hmem[64];
char peak_hmem[64];
char total_system_hmem[64];
char used_memory_lua_hmem[64];
char used_memory_scripts_hmem[64];
char used_memory_rss_hmem[64];
char maxmemory_hmem[64];
size_t zmalloc_used = zmalloc_used_memory();
size_t total_system_mem = server.system_memory_size;
const char *evict_policy = evictPolicyToString();
long long memory_lua = (long long)lua_gc(server.lua,LUA_GCCOUNT,0)*1024;
struct redisMemOverhead *mh = getMemoryOverheadData();
/* Peak memory is updated from time to time by serverCron() so it
* may happen that the instantaneous value is slightly bigger than
* the peak value. This may confuse users, so we update the peak
* if found smaller than the current memory usage. */
if (zmalloc_used > server.stat_peak_memory)
server.stat_peak_memory = zmalloc_used;
bytesToHuman(hmem,zmalloc_used);
bytesToHuman(peak_hmem,server.stat_peak_memory);
bytesToHuman(total_system_hmem,total_system_mem);
bytesToHuman(used_memory_lua_hmem,memory_lua);
bytesToHuman(used_memory_scripts_hmem,mh->lua_caches);
Redis 5.0 info信息(包含与3.0对比新增属性说明)
最新推荐文章于 2022-07-19 17:04:53 发布