Skip to content

Commit

Permalink
fix: 修复cluster_helper的metrics_port和pprof_port为0是为该功能不开启,并修改loop函数的日志输出
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvisWai committed Aug 14, 2023
1 parent d99102b commit 467bffb
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions scripts/cluster_helper/cluster_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,32 @@ def stop():

def loop():
while True:
time.sleep(SLEEP_SECONDS)
if stopped:
stop()
print(
f"================ {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ================"
)

metrics = []
for address, shake in nodes.items():
if shake.metrics_port == 0:
break
try:
ret = requests.get(f"http://localhost:{shake.metrics_port}").json()
metrics.append(ret)
except requests.exceptions.RequestException as e:
print(f"get metrics from [{address}] failed: {e}")

if len(metrics) == 0:
print("no metric is running for redis-shake")
break
for metric in sorted(metrics, key=lambda x: x["address"]):
print(f"{metric['address']} {metric['msg']} ")

if len(metrics) == 0:
print("no redis-shake is running")
break

time.sleep(SLEEP_SECONDS)
def is_incr_port(port: int) -> int:
if port == 0:
return 0
return port + 1


def main():
Expand Down Expand Up @@ -141,19 +145,28 @@ def main():
shutil.rmtree("data")
os.mkdir("data")
os.chdir("data")
start_port = (
11007
metrics_start_port = (
0
if toml_template.get("advanced").get("metrics_port", 0) == 0
else toml_template["advanced"]["metrics_port"]
)
pprof_start_port = (
0
if toml_template.get("advanced").get("pprof_port", 0) == 0
else toml_template["advanced"]["pprof_port"]
)
for address in nodes.keys():
workdir = address.replace(".", "_").replace(":", "_")

os.mkdir(workdir)
tmp_toml = toml_template
tmp_toml["source"]["address"] = address
start_port += 1
tmp_toml["advanced"]["metrics_port"] = start_port

# port is 0, means value not need increment
metrics_start_port = is_incr_port(metrics_start_port)
tmp_toml["advanced"]["metrics_port"] = metrics_start_port
pprof_start_port = is_incr_port(pprof_start_port)
tmp_toml["advanced"]["pprof_port"] = pprof_start_port

with open(f"{workdir}/sync.toml", "w") as f:
toml.dump(tmp_toml, f)
Expand All @@ -164,7 +177,7 @@ def main():
args.append(LUA_FILTER_PATH)
launcher = Launcher(args=args, work_dir=workdir)
nodes[address].launcher = launcher
nodes[address].metrics_port = start_port
nodes[address].metrics_port = metrics_start_port

signal.signal(signal.SIGINT, signal_handler)
print("start syncing...")
Expand Down

0 comments on commit 467bffb

Please sign in to comment.