-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpt-what
232 lines (189 loc) · 10 KB
/
pt-what
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#! /bin/perl
# pt-what: This tool will tell you which percona tool you can use for your task of choice.
# Version 2.3
# Originally By Kedar Vaijanapurkar @ http://kedar.nitty-witty.com/blog
# MIT License
use strict;
use warnings;
my %tools = (
"pt-archiver" => "Archives and purges table data efficiently with minimal impact on production. Use for: archiving old data, " .
"data retention management, table cleanup, reducing table size, moving data between servers, backup historical data, " .
"maintaining fixed-size tables, defragmentation, disk space management",
"pt-config-diff" => "Compare MySQL configuration files and server variables between servers. Use for: configuration auditing, " .
"ensuring consistency across servers, troubleshooting performance differences, migration verification, " .
"compliance checking, server standardization",
"pt-deadlock-logger" => "Monitors, logs and helps analyze MySQL deadlocks in real-time. Use for: deadlock detection, " .
"transaction analysis, application debugging, lock contention monitoring, InnoDB lock analysis, " .
"performance troubleshooting",
"pt-diskstats" => "Advanced I/O monitoring and analysis for MySQL databases. Use for: disk performance analysis, " .
"I/O bottleneck identification, storage troubleshooting, capacity planning, " .
"disk usage optimization, IOPS monitoring, disk fragmentation monitoring",
"pt-duplicate-key-checker" => "Identifies redundant indexes and foreign keys in MySQL tables. Use for: index optimization, " .
"storage efficiency, performance tuning, schema optimization, reducing maintenance overhead, " .
"identifying unnecessary indexes",
"pt-online-schema-change" => "Performs MySQL schema modifications without downtime. Use for: zero-downtime table alterations, " .
"adding/removing columns, changing indexes, table restructuring, performance optimization, " .
"defrag, defragment, defragmentation, disk space optimization, disk free space management, " .
"constraint modifications, partition management, table reorganization",
"pt-query-digest" => "Analyzes MySQL queries from logs, processlist, and tcpdump. Use for: query performance analysis, " .
"identifying slow queries, query optimization, workload analysis, capacity planning, " .
"performance trending, bottleneck identification",
"pt-table-checksum" => "Verifies MySQL replication integrity efficiently. Use for: replication consistency checking, " .
"data verification, corruption detection, slave synchronization verification, " .
"maintaining data integrity, identifying replication errors",
"pt-table-sync" => "Efficiently synchronizes MySQL tables between servers. Use for: replication repair, " .
"data synchronization, fixing inconsistencies, slave restoration, " .
"maintaining replica consistency, data recovery, table optimization",
"pt-variable-advisor" => "Analyzes MySQL variables for common problems and optimization opportunities. Use for: " .
"configuration optimization, performance tuning, best practice validation, " .
"security hardening, resource allocation",
"pt-slave-find" => "Finds and reports MySQL replication hierarchy and status. Use for: mapping replication topologies, " .
"finding broken replication chains, discovering master-slave relationships, identifying replication loops, " .
"auditing replication configuration, finding the most lagging slave, network replication mapping, " .
"replication health checks, visualizing complex replication setups",
"pt-slave-delay" => "Helps maintain a time-delayed MySQL replica. Use for: delayed disaster recovery setup, " .
"maintaining backup slave servers, point-in-time recovery preparation, preventing replication of harmful queries, " .
"creating delayed replicas, time-shifted backup windows, protection against accidental changes, " .
"testing schema changes with time buffer, verifying data changes before they replicate",
"pt-slave-restart" => "Watches and restarts MySQL replication after errors. Use for: automated slave error recovery, " .
"handling temporary replication failures, skipping problematic statements, maintaining replica uptime, " .
"monitoring slave status, automatic replication healing, continuous replication monitoring, " .
"preventing extended replication downtime, error-resilient replication maintenance"
);
# Helper function to normalize search terms
sub normalize_term {
my ($term) = @_;
$term = lc($term);
# Remove common typos and variations
$term =~ s/defragm[ae]ntation/defrag/i; # Handle variations of defragmentation
$term =~ s/fragm[ae]ntation/defrag/i; # Handle variations without 'de'
$term =~ s/optimi[sz]ation/optimize/i; # Handle optimize variations
$term =~ s/replication/replica/i; # Handle replication variations
$term =~ s/slave/replica/i; # Handle replication variations
return $term;
}
sub print_installation_instructions {
print "\n" . "=" x 60 . "\n";
print "📥 Installation Options\n";
print "=" x 60 . "\n\n";
# Package Manager Section
print "1️⃣ Using Package Manager (Recommended)\n";
print " " . "-" x 40 . "\n";
print " \033[1mDebian/Ubuntu:\033[0m\n";
print " \$ sudo apt update\n";
print " \$ sudo apt install percona-toolkit\n\n";
print " \033[1mRHEL/CentOS:\033[0m\n";
print " \$ sudo yum install percona-toolkit\n\n";
# Manual Download Section
print "2️⃣ Manual Download\n";
print " " . "-" x 40 . "\n";
print " \$ wget percona.com/get/[TOOLNAME]\n";
print " \$ chmod +x [TOOLNAME]\n\n";
# Docker Section
print "3️⃣ Using Docker\n";
print " " . "-" x 40 . "\n";
print " \$ docker pull percona/percona-toolkit\n";
print " \$ docker run --rm percona/percona-toolkit [TOOLNAME] --help\n\n";
# Documentation Link
print "📚 Documentation\n";
print " " . "-" x 40 . "\n";
print " • Detailed Installation Guide:\n";
print " \033[4mhttps://docs.percona.com/percona-toolkit/installation.html\033[0m\n";
print " • Man Pages:\n";
print " \033[4mhttps://docs.percona.com/percona-toolkit/\033[0m\n\n";
}
sub show_random_tool {
my @keys = keys %tools;
my $random_tool = $keys[rand @keys];
print "\n" . "=" x 60 . "\n";
print "💡 Random Tool Suggestion\n";
print "=" x 60 . "\n\n";
# Format tool name with some emphasis
print "Tool: \033[1m$random_tool\033[0m\n\n";
# Split the description into "overview" and "use cases"
my $description = $tools{$random_tool};
my ($overview, $use_cases) = split /Use for:/, $description;
# Print the overview
print "Overview:\n";
print wrap_text($overview, 2) . "\n\n";
# Print use cases in a structured format
print "Use Cases:\n";
if ($use_cases) {
my @cases = split /,/, $use_cases;
foreach my $case (sort @cases) {
$case =~ s/^\s+|\s+$//g; # trim whitespace
print " • $case\n";
}
}
print "\n" . "=" x 60 . "\n";
}
sub help {
print "Usage: pt-what <task>\n";
print "Search for Percona tools that can help with the specified task.\n\n";
print "Examples:\n";
print " pt-what replication # Find tools for replication management\n";
print " pt-what \"performance tuning\" # Find tools for performance optimization\n";
print " pt-what defrag # Find tools for defragmentation\n\n";
print "Options:\n";
print " task Task to search for Percona tools for\n";
print " -h, --help Show this help message\n";
exit;
}
my @tasks = @ARGV or help();
if($tasks[0] eq "-h" || $tasks[0] eq "--help"){
help();
}
if (!@tasks) {
print "Error: No task specified.\n";
help();
&show_random_tool;
exit 0;
}
print "\nPercona tools that may assist you with '@tasks' task:\n";
print "-" x 60 . "\n";
my %matching_tools;
foreach my $task (@tasks) {
my $normalized_task = normalize_term($task);
foreach my $tool (keys %tools) {
if ($tools{$tool} =~ /$task/i || $tools{$tool} =~ /$normalized_task/i) {
$matching_tools{$tool}++;
}
}
}
my @sorted_tools = sort {$matching_tools{$b} <=> $matching_tools{$a}} keys %matching_tools;
foreach my $tool (@sorted_tools) {
print "* $tool:\n " . wrap_text($tools{$tool}, 2) . "\n\n";
}
if(!@sorted_tools) {
print "No matching tools found for the task '@tasks'\n";
print "Try searching with similar terms like:\n";
my $search_term = $tasks[0];
if ($search_term =~ /defragm[ae]nt/i) {
print " - defrag\n - fragmentation\n - optimize\n";
} elsif ($search_term =~ /optimi[sz]/i) {
print " - optimize\n - performance\n - tuning\n";
}
print "\n";
&show_random_tool;
} else {
&print_installation_instructions;
}
# Helper function to wrap text at 80 characters with proper indentation
sub wrap_text {
my ($text, $indent) = @_;
my $width = 78 - $indent;
my $indent_str = " " x $indent;
my @words = split /\s+/, $text;
my @lines;
my $line = "";
foreach my $word (@words) {
if (length($line) + length($word) + 1 <= $width) {
$line .= ($line eq "" ? "" : " ") . $word;
} else {
push @lines, $line if $line;
$line = $word;
}
}
push @lines, $line if $line;
return join("\n$indent_str", @lines);
}