HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //proc/3233645/root/opt/sp_scripts/lstop.py
#!/usr/bin/env python3
# lsTop: LiteSpeed script to display top domains by requests/s.
# Tsvetan Gerov <tsvetan@worldhost.group>
# v0.1

import re
import glob

domain_info = {}
directory = '/tmp/lshttpd/'
file_pattern = '.rtreport*'
files = glob.glob(directory + file_pattern)

for filename in files:
    with open(filename, 'r') as file:
        content = file.read()
        matches = re.findall(r'REQ_RATE \[APVH_(.*?)\]: .* REQ_PER_SEC: ([0-9.]+)', content)
        for domain, requests_per_sec in matches:
            modified_domain = domain.split(':')[0]
            modified_domain = modified_domain.replace("APVH_", "")
            if modified_domain in domain_info:
                domain_info[modified_domain] += int(float(requests_per_sec))
            else:
                domain_info[modified_domain] = int(float(requests_per_sec))

sorted_domains = sorted(domain_info.items(), key=lambda x: x[1])

print("| {:<70s} | {:<8s} |".format("Domain", "Req/s"))
print("|" + "-" * 72 + "|" + "-" * 10 + "|")

for domain, requests_per_sec in sorted_domains:
    print(f"| {domain:<70} | {requests_per_sec:8d} |")

print("|" + "-" * 72 + "|" + "-" * 10 + "|")
print("| {:<70s} | {:<8s} |".format("Domain", "Req/s"))