Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions agent/database_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,46 +237,6 @@ def flush_tables(self, private_ip: str, mariadb_root_password: str):
)
mariadb.execute_sql("FLUSH TABLES;")

def search_binary_log(
self,
log,
database,
start_datetime,
stop_datetime,
search_pattern,
max_lines,
):
log = os.path.join(self.mariadb_directory, log)
LINES_TO_SKIP = r"^(USE|COMMIT|START TRANSACTION|DELIMITER|ROLLBACK|#)"
command = (
f"mysqlbinlog --short-form --database {database} "
f"--start-datetime '{start_datetime}' "
f"--stop-datetime '{stop_datetime}' "
f" {log} | grep -Piv '{LINES_TO_SKIP}'"
)

DELIMITER = "/*!*/;"

events = []
timestamp = 0
for line in self.execute(command, skip_output_log=True)["output"].split(DELIMITER):
line = line.strip()
if line.startswith("SET TIMESTAMP"):
timestamp = int(line.split("=")[-1].split(".")[0])
else:
if any(line.startswith(skip) for skip in ["SET", "/*!"]):
continue
if line and timestamp and re.search(search_pattern, line):
events.append(
{
"query": line,
"timestamp": str(datetime.utcfromtimestamp(timestamp)),
}
)
if len(events) > max_lines:
break
return events

@property
def binary_logs(self):
BINARY_LOG_FILE_PATTERN = r"mysql-bin.\d+"
Expand Down
15 changes: 0 additions & 15 deletions agent/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,21 +1338,6 @@ def kill_database_processes():
return jsonify(DatabaseServer().kill_processes(**data))


@application.route("/database/binary/logs/<string:log>", methods=["POST"])
def get_binary_log(log):
data = request.json
return jsonify(
DatabaseServer().search_binary_log(
log,
data["database"],
data["start_datetime"],
data["stop_datetime"],
data["search_pattern"],
data["max_lines"],
)
)


@application.route("/database/stalks")
def get_stalks():
return jsonify(DatabaseServer().get_stalks())
Expand Down
Loading