Customizing pt-stalk to capture the diagnostics data you really need
Updating a Module
My very simple PR modifies the --collect-oprofile command which, as the name implies, is part of the collect module. This means that from the root directory of the repo, we need to edit the lib/bash/collect.sh file. There is one small catch, which is that the toolkit's scripts that we end up executing as users (i.e. those that live under the /bin/ directory of the repo) include all (or most of, in the case of the perl tools) the modules used by the tool. In the perl based tools' comments, this is described as being 'fat-packed', and it means there is one more step we need to take in order to update the end-user script with our changes made to modules. In the case of my PR, here is what I had to run before committing my changes:./util/update-modules bin/pt-stalk collect This can be read as 'update the modules used by pt-stalk to include the latest version of collect'. If you think this means the repo has redundant code, you are right. If you think this has the risk of a given branch being internally inconsistent, once again, you are right. It is up to the maintainer of a branch (or the author of a PR, in this case) to make sure this does not happen. I think it's a trade-off worth making in order to keep the code reasonably maintainable and easy to use at the same time.
Writing Plugins
What if we wanted to alter the way pt-stalk monitors for the trigger condition? You'll notice there is no stalk module under lib/bash, so, in this case, we may have to modify the pt-stalk script directly. However, the script supports plugins, so in most cases, we should be able to achieve the desired behavior just by writing one. Over the years, I have been collecting such plugins, as written by community members, including myself, in this repo. You'll notice there are two types of plugins there:- function plugins, which alter the way pt-stalk monitors for a condition, and
- general plugins, which alter the way pt-stalk collects data.
Forking the Project
Finally, sometimes a change is big enough that none of the clean, 'proper' ways to extend pt-stalk work. In that case, you have to fork. Doing so is not complicated, but doing so in a way that makes the resulting code easy to merge back takes some effort, which is why I am, for now, keeping this branch with MongoDB support as 'just a fork'. Maybe one day I will decide that the effort to keep up with upstream's changes is enough to warrant some invested time to make a PR, but for now, whenever I need to use pt-stalk with MongoDB, I just grab that code. What factors do I take into account when deciding if a fork is worth the work of creating a PR? Among others, I ask myself these questions:- Can I easily test the new behavior using the existing test cases and environment (the answer is 'yes' to my changes to collect-oprofile, but 'no' to adding MongoDB support. As expected, there are no MongoDB tests in pt-stalk, and the sandboxes used to test Percona Toolkit are only MySQL based.
- Does this behavior have the potential to benefit lots of people? If not, it does not make sense for me to spend time creating the PR, and for the upstream maintainers to review it and merge it.
- What are the odds that my changes will break something else in a way that is not detected by existing test cases? Adding MongoDB support is a pretty big change. It is a risk worth taking if I will use my fork only on MongoDB servers, and use upstream's on MySQL. But if it were to be integrated into the project, a lot more effort would be needed to make sure that MySQL users aren't negatively impacted by any changes made to support MongoDB.
Conclusion
While showing its age, pt-stalk is still a very good option to monitor servers for rare-to-catch problems, and it incorporates a lot of knowledge that we may miss if we were to write a similar tool from scratch. Important knowledge, like how to make sure the monitoring tool itself won't cause a service disruption by filling up a partition or eating up all available database connections. Hopefully, this post shows that 'showing its age' is something that anyone with some time and determination can help with, by:- updating some modules,
- writing plugins, or
- forking entire tools.
On this page
Share this
Share this
More resources
Learn more about Pythian by reading the following blogs and articles.
How to Run DBSAT 2.2.0 on Oracle Cloud PDB using Wallet

How to Run DBSAT 2.2.0 on Oracle Cloud PDB using Wallet
Feb 13, 2020 12:00:00 AM
10
min read
ASMCMD> a better DU, version 2
ASMCMD> a better DU, version 2
Jun 21, 2016 12:00:00 AM
2
min read
How to remove grid 12.2 after an 18c upgrade
How to remove grid 12.2 after an 18c upgrade
May 13, 2019 12:00:00 AM
4
min read
Ready to unlock value from your data?
With Pythian, you can accomplish your data transformation goals and more.