MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sentinelInfoCommand

Function sentinelInfoCommand

src/sentinel.cpp:3918–3979  ·  view source on GitHub ↗

SENTINEL INFO [section] */

Source from the content-addressed store, hash-verified

3916
3917/* SENTINEL INFO [section] */
3918void sentinelInfoCommand(client *c) {
3919 if (c->argc > 2) {
3920 addReplyErrorObject(c,shared.syntaxerr);
3921 return;
3922 }
3923
3924 int defsections = 0, allsections = 0;
3925 char *section = c->argc == 2 ? szFromObj(c->argv[1]) : NULL;
3926 if (section) {
3927 allsections = !strcasecmp(section,"all");
3928 defsections = !strcasecmp(section,"default");
3929 } else {
3930 defsections = 1;
3931 }
3932
3933 int sections = 0;
3934 sds info = sdsempty();
3935
3936 info_section_from_redis("server");
3937 info_section_from_redis("clients");
3938 info_section_from_redis("cpu");
3939 info_section_from_redis("stats");
3940
3941 if (defsections || allsections || !strcasecmp(section,"sentinel")) {
3942 dictIterator *di;
3943 dictEntry *de;
3944 int master_id = 0;
3945
3946 if (sections++) info = sdscat(info,"\r\n");
3947 info = sdscatprintf(info,
3948 "# Sentinel\r\n"
3949 "sentinel_masters:%lu\r\n"
3950 "sentinel_tilt:%d\r\n"
3951 "sentinel_running_scripts:%d\r\n"
3952 "sentinel_scripts_queue_length:%ld\r\n"
3953 "sentinel_simulate_failure_flags:%lu\r\n",
3954 dictSize(sentinel.masters),
3955 sentinel.tilt,
3956 sentinel.running_scripts,
3957 listLength(sentinel.scripts_queue),
3958 sentinel.simfailure_flags);
3959
3960 di = dictGetIterator(sentinel.masters);
3961 while((de = dictNext(di)) != NULL) {
3962 sentinelRedisInstance *ri = (sentinelRedisInstance*)dictGetVal(de);
3963 const char *status = "ok";
3964
3965 if (ri->flags & SRI_O_DOWN) status = "odown";
3966 else if (ri->flags & SRI_S_DOWN) status = "sdown";
3967 info = sdscatprintf(info,
3968 "master%d:name=%s,status=%s,address=%s:%d,"
3969 "slaves=%lu,sentinels=%lu\r\n",
3970 master_id++, ri->name, status,
3971 announceSentinelAddr(ri->addr), ri->addr->port,
3972 dictSize(ri->slaves),
3973 dictSize(ri->sentinels)+1);
3974 }
3975 dictReleaseIterator(di);

Callers

nothing calls this directly

Calls 10

addReplyErrorObjectFunction · 0.85
szFromObjFunction · 0.85
sdsemptyFunction · 0.85
sdscatFunction · 0.85
sdscatprintfFunction · 0.85
announceSentinelAddrFunction · 0.85
addReplyBulkSdsFunction · 0.85
dictGetIteratorFunction · 0.70
dictNextFunction · 0.70
dictReleaseIteratorFunction · 0.70

Tested by

no test coverage detected