pax_global_header00006660000000000000000000000064134360713560014522gustar00rootroot0000000000000052 comment=750185d835eea98649b7a95e12f648c8667c4163 recap-2.0.2/000077500000000000000000000000001343607135600126155ustar00rootroot00000000000000recap-2.0.2/.travis.yml000066400000000000000000000025131343607135600147270ustar00rootroot00000000000000--- language: bash sudo: enabled branches: only: - master - development - testing matrix: include: - name: "CentOS 6" env: - DISTRO='centos:6' - name: "CentOS 7" env: - DISTRO='centos:7' - name: "Ubuntu 14.04 (trusty)" env: - DISTRO='ubuntu:14.04' - name: "Ubuntu 16.04 (xenial)" env: - DISTRO='ubuntu:16.04' - name: "Ubuntu 18.04 (bionic)" env: - DISTRO='ubuntu:18.04' - name: "Debian 8 (jessie)" env: - DISTRO='debian:8' - name: "Debian 9 (stretch)" env: - DISTRO='debian:9' - name: "Debian (buster)" env: - DISTRO='debian:buster' before_install: - docker pull ${DISTRO} install: - | docker run \ --detach \ --rm \ --tty \ --privileged \ --network=host \ --name recap_on_${DISTRO/:/_} \ --mount type=bind,src="$(pwd)",dst=/recap \ ${DISTRO} - docker exec recap_on_${DISTRO/:/_} /recap/tests/install_deps.sh ${DISTRO} - docker exec recap_on_${DISTRO/:/_} /recap/tests/test_install_recap.sh script: - docker exec recap_on_${DISTRO/:/_} bash -c 'recap --version' - docker exec recap_on_${DISTRO/:/_} /recap/tests/run_recap.sh - docker exec recap_on_${DISTRO/:/_} bash -c 'ls -tr /var/log/recap/*log | xargs tail -v -n+0' ... recap-2.0.2/CHANGELOG.md000066400000000000000000000221371343607135600144330ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. ## [Unreleased] - ## [2.0.2] - 2018-02-25 - Dynamically find CPU field to sort top CPU report [(#203)][203] ## [2.0.1] - 2018-02-05 - Fix bug related to DESTDIR included in recap script [(#195)][195] [(#198)][198]. ## [2.0.0] - 2018-01-22 - Add plugin support [(#155)][155]. - Split recap functionality between core functions and plugins. - Plugins are not enabled by default on this version. - Plugins added:redis, docker_top, http_status, kernel_cmd. - Complete the deprecation of `/etc/recap` config file for `/etc/recap.conf` [(#80)][80]. - All the old config references have been removed. - Old config is now ignored. - Deprecating BACKUP_ITEMS, instead finding reports/logs dynamically [(#115)][115]. - Dependency change, `elinks` used instead of `links` for `http_status` plugin [(#169)][169] [(#170)][170]. - Replace the use of `@PATTERN@` in cron/timers to make dev and testing easier. - Add multi-distro testing on travis (CI). - Add ansible playbook to (un)install recap. - More detailed information included in the `recap.log` regarding reports. - Standardize options across scripts [(#111)][111]. - All script now support short and long argument options. - `recaplog` deprecates the use of action options. - Rename of man pages now including `recap.conf(5)` [(#175)][175]. - Fix version inconsistency on recap scripts [(#174)][174]. ## [1.4.0] - 2018-07-12 - Continue with the deprecation of `/etc/recap` config file for `/etc/recap.conf` - New config file now takes precedence over old one. - Added support to multiple mysql config files. - Bug fixes: - Use defaults-file instead of defaults-extra-file - Better handling on stderr. - Disk space compatibility for el6. - Set right perms to BASEDIR on runtime. ## [1.3.0] - 2017-12-06 - Start the deprecation of `/etc/recap` config file for `/etc/recap.conf`. - Add systemd support for units and timers. - Add log capabilities for recap. - Bug fixing (logging and clean up functions). ## [1.2.0] - 2017-11-01 - Use of modern tools for netstat reports, `net-tools` are now deprecated. - Deprecated the use of `OPTS_CURL` in favor of `OPTS_LINKS` [(#125)][125] - Default changed for `OPTS_STATUSURL` [(#125)][125] - Deprecated the use of `MAXLOAD`. [(#123)][123] - Timeout added to cronjobs with a default of 5m for most cases. [(#123)][123] - Added `version` option. - Dependencies: - Removed:`bc`, `net-tools`. - Added: `links`, `iproute`/`iproute2`. ## [1.1.0] - 2017-09-01 - Align default settings on recap.conf to script defaults. - Default setting changed for: USEDF, USENETSTAT, OPTS_PSTREE. - Removed old unused settings. - Added new setting(OPTS_STATUSURL) to remove dependency to apache httpd. - Updated man pages to reflect new defaults. - Corrected exit codes. - Added new options(OPTS_CURL). - Added version argument to scripts(recap, recaplog, recaptool). - RPM spec file moved out of the repo. ## [1.0.0] - 2017-05-15 - Record point-in-time CPU. - Multiple bug fixing on recaptool. - Multiple bug fixing on recap. - Refactor of recaplog. - Fix plesk mysql bug. - Include recaptool man page. - RPM spec file specifics: modified to update requirements, obsoletes, provides rs-sysmon. - Better support for multiple mysql instances. - Makefile updated to allow multiple distros alignment and to include new man pages. - Adjust spec for Makefile. - Makefile now uses /usr/local as default for DESTDIR. - fdisk warnings(stderr) are now included in the logs(stdin). ## [0.9.14] - 2016-05-11 - Fix #55 Code clean up, typos fixed and functions renamed ## [0.9.13] - 2016-05-04 - Fix #52 recaptool globbing - Fix #54 install recaplog man page ## [0.9.12] - 2016-04-22 - Fix #41 (add sysstat and iotop to dependencies) - Fix #49 (reorg and Makefile) - Fix #51 (typo on recaptool suffix path on log files) ## [0.9.11] - 2015-12-23 - updates to handling multiple DOTMYDOTCNF logic ## [0.9.10] - 2015-12-21 - Adjusted Default MAXLOAD value - Fixed #27 (Document MAXLOAD) ## [0.9.9-development] - 2015-01-31 - Fix #17 by merging plesk check into print_mysql_procs and print_mysql - Created branch for development and tags for stable and development versions ## [0.9.8] - 2015-01-07 - Fix #12 (custom .my.cnf, multi-mysql support) - Fix #13 (log files not being copied to /var/log/recap/backups) - Fix #15/22 (ensure apachectl and mysqladmin are available) ## [0.9.7] - 2013-10-31 - command line options can be specified in 'Configuration stanza' - timestamp is appended to log filenames - implemented log rotation (see: 'recaplog', rotated log files can be Gzip'd) ## [0.9.6] - 2012-11-01 - First public release GPLv2, special thanks to Rackspace IPC, Brent Oswald, and Benjamin H. Graham - Changed name to recap, added links for new repository - Integrated recaptool - Added simple installer - (tested on debian) - Added MacOSX support to installer ## [0.9.5] - 2012-11-01 - First release under GPL ## [0.9.4] - 2012-11-01 - Modified output of MySQL report to include full query output - Corrected output of iostat ## [0.9.3-2] - 2012-11-01 - Changed default mode on /var/log/rs-sysmon from 750 to 700 - Corrected @reboot cron job (was missing the user name) ## [0.9.3] - 2012-11-01 - All reports are now optional (configurable in /etc/rs-sysmon) - Modified backup functionality so that backups are only generated for reports that are currently configured to run (won't create backups for stale files) ## [0.9.2] - 2012-11-01 - Consolidated function calls to generate reports. Calls to generate individual reports are now encapsulated into one wrapper function per report - Code clean-up to standardize style throughout script - Added more explicit handling for invalid user input (multiple flags, invalid flags) - Changed the default mode on the output directory to 750 (no longer world readable) - Laid the groundwork for making all reports optional - Updated backup and snapshot functionality to better handle optional reports - Moved the standard location for the configuration file to /etc/sysconfig - Updated man pages to reflect changes ## [0.9.1] - 2012-11-01 - Added check to ensure that the script is running as root - Moved check for output directory so that it takes place after CLI flags have been interpreted ## [0.9] - 2012-11-01 - Consolidated bash functions - Consolidated output directories - Updated spec file to automate consolidation of log files on install - Removed documented options for changing output directories - Added optional reports for network connections and MySQL status ## [0.8-2] - 2012-11-01 - Modified the call to mktemp so that it uses a template. This is to improve compatibility with RHEL 2.1 ## [0.8] - 2012-11-01 - Modified the send_mail function so that it generates a random tmp directory to use rather than always writing to the same location ## [0.7] - 2012-11-01 - Added flag to perform snapshots. A snapshot is a one-time report that generates time-stamped output files. These files are not included in the output file rotation - Added flag to perform a backup of the latest reports. There was an issue on some servers where the second "@reboot" command would not be executed from cron. This creates a time-stamped copy (similar to the snapshots above, but labeled "backup") of the latest set of report files - Wrapped almost all functionality in bash functions to allow for more flexible execution of rs-sysmon functionality. This is still a mess and will continue to be addressed in future releases. --- # Contributors - Alan Pearce - Andrew Howard(StafDehat) - Ben Harper (b-harper) - Benjamin H. Graham (bhgraham) - Blake Moore - Brandon Tomlinson (thebwt) - Brent A. Oswald (buzzboy23) - Carl George (carlwgeorge) - Carl Thompson(redragon) - Christian (thtieig) - Cian Brennan (lil-cain) - David King - Erik Ljungstrom - Jacob Walcik - James Belchamber - Josh Soref (jsoref) - Sean Dennis (jamrok) - Jay Goldberg - Jeffrey Ness - John Schwinghammer (schwing) - Luke Hanley (LukeHandle) - Man Chung (man-chung) - Piers Cornwell (piersc) - rackerjimmy - Ryan Stark (ryansyah) - Sammy Larbi (codeodor) - Sean Roberts (seanorama) - Simone Soldateschi (siso) - Tony Garcia (tonyskapunk) --- [80]: https://github.com/rackerlabs/recap/issues/80 [111]: https://github.com/rackerlabs/recap/issues/111 [115]: https://github.com/rackerlabs/recap/issues/115 [123]: https://github.com/rackerlabs/recap/issues/123 [125]: https://github.com/rackerlabs/recap/issues/125 [155]: https://github.com/rackerlabs/recap/issues/155 [169]: https://github.com/rackerlabs/recap/issues/169 [170]: https://github.com/rackerlabs/recap/issues/170 [174]: https://github.com/rackerlabs/recap/issues/174 [175]: https://github.com/rackerlabs/recap/issues/175 [195]: https://github.com/rackerlabs/recap/issues/195 [198]: https://github.com/rackerlabs/recap/issues/198 [203]: https://github.com/rackerlabs/recap/issues/203 recap-2.0.2/CONTRIBUTING.md000066400000000000000000000031551343607135600150520ustar00rootroot00000000000000# Workflow This project uses gitflow, here some documentation about [how gitflow works](https://datasift.github.io/gitflow/IntroducingGitFlow.html) # Issues Bugs, RFE or others should be documented in the [issues](https://github.com/rackerlabs/recap/issues/). ## Guidelines 1. Before opening an issue, search [open](https://github.com/rackerlabs/recap/issues?q=is%3Aopen+is%3Aissue) and [closed](https://github.com/rackerlabs/recap/issues?q=is%3Aissue+is%3Aclosed) issues to ensure the issue has not ben reported previously. 1. Ensure the issue can be reproduced with the latest [`development`](https://github.com/rackerlabs/recap/tree/development) version. 1. The issue should contain detailed instructions and when possible logs, as well as the expected result. 1. Include details of the environment where it's running, e.g. Debian Jessie, CentOS 7.3, etc. 1. For RFE explain *Why would this feature be useful?* # Pull Requests Code contributions are greatly appreciated, please make sure you follow the guidelines below. ## Pull requests should be 1. Made against the `development` branch. 1. Made from a git feature/fix branch. 1. Associated to a documented issue. ## Pull requests will not be accepted that 1. Are not made against the `development` branch 1. Are made by editing files via the GitHub website 1. Does not have a documented [issue](https://github.com/rackerlabs/recap/issues/) for it. # Coding Guidelines There is no enforcement of a code guideline, as there is no standard for it; this styleguide is to some extent being used, hence recommended. [Shell Style Guide](https://google.github.io/styleguide/shell.xml). recap-2.0.2/COPYING000066400000000000000000000432541343607135600136600ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. recap-2.0.2/Makefile000066400000000000000000000131571343607135600142640ustar00rootroot00000000000000# Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. DESTDIR ?= BINPATH ?= /sbin PREFIX ?= /usr/local BINDIR ?= $(PREFIX)$(BINPATH) LIBDIR ?= $(PREFIX)/lib MANDIR ?= $(PREFIX)/share/man DOCDIR ?= $(PREFIX)/share/doc SYSCONFDIR ?= /etc CRONDIR ?= $(SYSCONFDIR)/cron.d SYSTEMDDIR ?= /usr/lib/systemd/system LOGDIR ?= /var/log ifneq ("$(wildcard /bin/systemctl)","") type=systemd else type=cron endif all: @echo "Nothing to compile, please choose a specific target:" @echo " install (includes install-base, install-man, install-doc and install-(cron/systemd)*)" @echo " install-base" @echo " install-cron" @echo " install-systemd" @echo " install-man" @echo " install-doc" @echo " uninstall (includes uninstall-base, uninstall-man, uninstall-doc and uninstall-(cron/systemd)*)" @echo " uninstall-base" @echo " uninstall-cron" @echo " uninstall-systemd" @echo " uninstall-man" @echo " uninstall-doc" @echo "" @echo "*If systemd is available it will (un)install systemd units instead of cron" @echo "Current type detected is: $(type)" recap.cron: @sed -e 's|^\s*\(BINDIR=\).*$$|\1$(BINDIR)|' src/utils/recap.cron.in > src/utils/recap.cron recap.systemd: @for service_file in src/utils/*.service.in; do \ sed -e 's|^\s*\(Environment=BINDIR=\).*$$|\1$(BINDIR)|' $${service_file} > $${service_file%.in}; \ done clean: @rm -f src/utils/recap.cron @rm -f src/utils/*.service install: install-base install-man install-doc install-$(type) uninstall: uninstall-base uninstall-man uninstall-doc uninstall-$(type) install-base: @echo "Installing scripts..." @sed -i.orig 's|^\s*\(declare\s\+-r\s\+LIBDIR=\).*$$|\1"$(LIBDIR)/recap"|' src/recap @install -Dm0755 src/recap $(DESTDIR)$(BINDIR)/recap @install -Dm0755 src/recaplog $(DESTDIR)$(BINDIR)/recaplog @install -Dm0755 src/recaptool $(DESTDIR)$(BINDIR)/recaptool @mv -f src/recap.orig src/recap @echo "Installing libraries..." @install -dm0755 $(DESTDIR)$(LIBDIR)/recap @install -dm0755 $(DESTDIR)$(LIBDIR)/recap/core @install -dm0755 $(DESTDIR)$(LIBDIR)/recap/plugins-available @install -dm0755 $(DESTDIR)$(LIBDIR)/recap/plugins-enabled @install -Dm0644 src/core/* $(DESTDIR)$(LIBDIR)/recap/core/ @install -Dm0644 src/plugins/* $(DESTDIR)$(LIBDIR)/recap/plugins-available/ @echo "Installing configuration..." @install -Dm0644 src/recap.conf $(DESTDIR)$(SYSCONFDIR)/recap.conf @echo "Creating log directories..." @install -dm0750 $(DESTDIR)$(LOGDIR)/recap @install -dm0755 $(DESTDIR)$(LOGDIR)/recap/backups @install -dm0755 $(DESTDIR)$(LOGDIR)/recap/snapshots install-cron: recap.cron @echo "Installing cron job..." @install -Dm0644 src/utils/recap.cron $(DESTDIR)$(CRONDIR)/recap install-systemd: recap.systemd @echo "Installing systemd timers and services..." @install -dm0755 $(DESTDIR)$(SYSTEMDDIR) @install -Dm0644 src/utils/*.service $(DESTDIR)$(SYSTEMDDIR)/ @install -Dm0644 src/utils/*.timer $(DESTDIR)$(SYSTEMDDIR)/ @echo "Use the following to enable the systemd timers:" @echo "sudo systemctl enable recap.timer --now" @echo "sudo systemctl enable recaplog.timer --now" @echo "sudo systemctl enable recap-onboot.timer --now" install-man: @echo "Installing man pages..." @install -Dm0644 src/recap.conf.5 $(DESTDIR)$(MANDIR)/man5/recap.conf.5 @install -Dm0644 src/recap.8 $(DESTDIR)$(MANDIR)/man8/recap.8 @install -Dm0644 src/recaplog.8 $(DESTDIR)$(MANDIR)/man8/recaplog.8 @install -Dm0644 src/recaptool.8 $(DESTDIR)$(MANDIR)/man8/recaptool.8 install-doc: @echo "Installing docs..." @install -dm0755 $(DESTDIR)$(DOCDIR)/recap @install -Dm0644 CHANGELOG.md README.md COPYING -t $(DESTDIR)$(DOCDIR)/recap uninstall-base: @echo "Removing scripts..." @rm -f $(DESTDIR)$(BINDIR)/recap @rm -f $(DESTDIR)$(BINDIR)/recaplog @rm -f $(DESTDIR)$(BINDIR)/recaptool @echo "Removing libraries..." @rm -Rf $(DESTDIR)$(LIBDIR)/recap/core @rm -Rf $(DESTDIR)$(LIBDIR)/recap/plugins-available @rm -Rf $(DESTDIR)$(LIBDIR)/recap/plugins-enabled @echo "Removing configuration..." @rm -f $(DESTDIR)$(SYSCONFDIR)/recap uninstall-cron: @echo "Removing cron job..." @rm -f $(DESTDIR)$(CRONDIR)/recap uninstall-systemd: @echo "Removing systemd timers and services..." @rm -f $(DESTDIR)$(SYSTEMDDIR)/recap*.{service,timer} @echo "Use the following to disable the systemd timers:" @echo "sudo systemctl disable recap.timer --now" @echo "sudo systemctl disable recaplog.timer --now" @echo "sudo systemctl disable recap-onboot.timer --now" uninstall-man: @echo "Removing man pages..." @rm -f $(DESTDIR)$(MANDIR)/man5/recap.conf.5 @rm -f $(DESTDIR)$(MANDIR)/man8/recap.8 @rm -f $(DESTDIR)$(MANDIR)/man8/recaplog.8 @rm -f $(DESTDIR)$(MANDIR)/man8/recaptool.8 uninstall-doc: @echo "Removing docs..." @rm -Rf $(DESTDIR)$(DOCDIR)/recap .PHONY: install install-base install-cron install-systemd install-man install-doc uninstall uninstall-base uninstall-cron uninstall-systemd uninstall-man uninstall-doc clean recap-2.0.2/README.md000066400000000000000000000375561343607135600141140ustar00rootroot00000000000000# Recap [![Build Master Status](https://img.shields.io/travis/rackerlabs/recap/master.svg?logo=travis&label=master)](https://travis-ci.org/rackerlabs/recap) [![Build Development Status](https://img.shields.io/travis/rackerlabs/recap/development.svg?logo=travis&label=development)](https://travis-ci.org/rackerlabs/recap) [![GitHub release](https://img.shields.io/github/release/rackerlabs/recap.svg)](https://github.com/rackerlabs/recap/releases/latest) [![GitHub license](https://img.shields.io/github/license/rackerlabs/recap.svg)](https://raw.githubusercontent.com/rackerlabs/recap/master/COPYING) [![GitHub stars](https://img.shields.io/github/stars/rackerlabs/recap.svg?style=social&label=Star)](https://github.com/rackerlabs/recap) [![Twitter](https://img.shields.io/twitter/url/https/github.com/rackerlabs/recap.svg?style=social)](https://twitter.com/intent/tweet?text=Check%20this%20out:&url=https%3A%2F%2Fgithub.com%2Frackerlabs%2Frecap) **recap** is a system status reporting tool. A reporting script that generates reports of various information about the server. ## Contribution Contribution guidelines can be found in [CONTRIBUTING.md](https://github.com/rackerlabs/recap/blob/master/CONTRIBUTING.md) ## Dependencies - bash >= 4 - coreutils - gawk - grep - iotop - iproute/iproute2 - elinks - procps - psmisc - sysstat >= 9 ## Versioning `recap` is following the `x.y.z` versioning as defined below: - **x** *(major)* - Changes that prevent at least some rolling upgrades. - **y** *(minor)* - Changes that don't break any rolling upgrades but require closer user attention for example configuration defaults, function behavior, tools used to produce reports, among others. - **z** *(patch)* - Changes that are backward-compatible including features and/or bug fixes. ## Installation It is highly recommended to make use of a package to install `recap` is the easiest way to keep it updated whenever there is a new release. ### Fedora `recap` is available from the main Fedora repository ([spec file](https://src.fedoraproject.org/rpms/recap/blob/master/f/recap.spec)). ``` dnf install recap ``` ### RHEL/CentOS `recap` is available from the [EPEL](https://fedoraproject.org/wiki/EPEL) repository ([spec file](https://src.fedoraproject.org/rpms/recap/blob/master/f/recap.spec)). ``` yum install recap ``` ### Debian Currently only available in [testing](https://packages.debian.org/source/testing/recap) and [unstable](https://packages.debian.org/source/unstable/recap). For other releases see the options to build a deb package or install from source. The official Debian files are available in this [repository](https://github.com/jkirk/recap) ### Ubuntu At the moment there is no public repository for Ubuntu, two options are available, build a deb package or install manually, see instructions down below. ### Build a deb package This [repository](https://github.com/jkirk/recap) contains the official Debian files required to build a deb package. These steps used to be used to build the deb package, use them as a guide: ```bash # Install all the packages required for building the package apt-get update apt-get install debhelper devscripts git -y ## For Ubuntu: apt-get install equivs -y # Create the working dir: mkdir recap cd recap # Get the Debian configs git init git remote add origin https://github.com/jkirk/recap.git git fetch --no-tags origin git checkout -qf FETCH_HEAD git submodule update --init --recursive export LATEST=$( git log --format="%h" --no-merges -1 ) # Build dependencies echo "yes" | mk-build-deps --install --remove debian/control # Get upstream recap code git checkout --orphan upstream git reset --hard git remote add upstream https://github.com/rackerlabs/recap.git git fetch -t upstream latest_tag=$( git tag | tail -1 ) git archive ${latest_tag} -o ../recap_${latest_tag}.orig.tar.gz tar -zxf ../recap_${latest_tag}.orig.tar.gz git fetch --no-tags origin git checkout ${LATEST} -- debian # Build the package debuild -us -uc --lintian-opts --profile debian # Package will be created in ../recap_${latest_tag}-_all.deb # RELEASE comes from the changelog in the Debian repository. ``` ### Manual 1. Install the required dependencies. 2. Clone this repository: `git clone https://github.com/rackerlabs/recap.git` 3. Change into the new directory: `cd recap` 4. Install the program: `sudo make install` The information captured will be found in log files in the `/var/log/recap/` directory. #### About the locations of the scripts - The default location of the install is `"/"` it can be overridden with `DESTDIR`. - The scripts, man pages and docs are installed under "`"/usr/local"` by default, this can be overridden with `PREFIX`. Main scripts are installed on in "`./sbin`" by default, this can be overriden with `BINDIR`. - The core scripts and the plugins are installed on top of `PREFIX` in "`./recap/plugins-available`" by default, this can be overridden with `LIBDIR` The following example is a common location for most of the distributions, this will install `recap` under `/usr`: ``` $ sudo make PREFIX="/usr" install ``` This other example will install `recap` under your homedirectory but using the default locations for the script, i.e. under `"~/usr/local"`: ``` $ make DESTDIR="~" install ``` The `Makefile` scripts attempts to detect systemd if so, the `install` option will install the systemd unit files. The install will **not** enable the timers, but it will show the commands required to enable each of the timers. When systemd is not detected the cronjobs will be installed. Is up to each package distribution to follow their own best practices regarding enabling/disabling the timers on install/remove of the package. ### Ansible An ansible playbook could be used to install `recap` from a git repository. The playbook is located in `tools` under `ansible_recap.yml` the playbook can be used to install it on Red Hat based and Debian based distros. Or to uninstall it defining the `uninstall` variable. #### Variables - `repo` - The location of the repository, default: `https://github.com/rackerlabs/recap.git`. - `ref` - The reference to use this could be a branch, a tag or commit, default: `master`. - `binpath` - The value of *BINPATH*, default: `/sbin`. - `destdir` - The value of *DESTDIR*, default: `""`. - `prefix` - The value of *PREFIX*, default: `/usr`. - `tmp_install_dir` - The location where the cloned repo will be placed, default: `/tmp/recap`. - `uninstall` - Then this is defined it will remove `recap`, default: *undefined*. - `enable_plugins` - To enable the global plugin configuration default: `false`. - `plugin_list` - A list of plugins to enable, from the `plugin-available` directory, default: `all`. #### Install (default) Install the stable version of `recap`: ``` ansible-playbook tools/ansible_recap.yml ``` Install the development version of `recap`: ``` ansible-playbook tools/ansible_recap.yml -e ref=development ``` Install branch `foo` from a different repository: ``` ansible-playbook tools/ansible_recap.yml -e ref=foo -e repo=https://github.com/bar/recap.git ``` Install recap with *BINPATH* in `/bin`: ``` ansible-playbook tools/ansible_recap.yml -e binpath=/bin ``` Install recap with all plugins enabled: ``` ansible-playbook tools/ansible_recap.yml -e enable_plugins=true ``` Install recap with a list of plugins to enable: ``` ansible-playbook tools/ansible_recap.yml \ -e enable_plugins=true \ -e '{"plugin_list":[docker_top,redis]}' ``` #### Uninstall Uninstall `recap` from the default path: ``` ansible-playbook tools/ansible_recap.yml -e uninstall=yes ``` Uninstall `recap` from a custom location: ``` ansible-playbook tools/ansible_recap.yml -e uninstall=yes -e destdir=/tmp/test ``` ## Cron/Timers and Configuration ### Timers(systemd) Multiple unit files are available to make use of `timers`, here the default schedules for the recap scripts: - recap (default every 10min) - recap-onboot (runs at boot time) - recaplog (default: Once a day 1am) #### Enabling timers Each one of the timers can be enabled with: ```bash sudo systemctl enable recap.timer --now" sudo systemctl enable recaplog.timer --now" sudo systemctl enable recap-onboot.timer --now" ``` #### Disabling timers Each one of the timers can be disabled with: ```bash sudo systemctl disable recap.timer --now" sudo systemctl disable recaplog.timer --now" sudo systemctl disable recap-onboot.timer --now" ``` ### Cron The cron file (`/etc/cron.d/recap`) is used to determine the execution time of `recap` and `recaplog`. By default the cron execution for `recap` is enabled to run every 10 min. and `recaplog` is expected to run every day at 1 am, but those can be adjusted as needed. ### Configuration The following variables are commented out with the defaults values in the configuration file `/etc/recap.conf` which can be overridden. #### Settings shared by recap scripts - **BASEDIR** - Directory where the logs are saved. Default: `BASEDIR="/var/log/recap"` - **LIBDIR** - Directory where the libraries/functions are located. The default value depends on the `PREFIX` used when installing, the default `PREFIX` on the `Makefile` is `/usr/local`, then: Default: `LIBDIR="/usr/local/lib/recap"` But packages use `/usr` as the `PREFIX`, then through a package it is expected to be: Default: `LIBDIR="/usr/lib/recap"` #### Settings used only by `recaplog` - **LOG_COMPRESS** - Enable or disable log compression. Default: `LOG_COMPRESS=1` - **LOG_EXPIRY** - Log files will be deleted after LOG_EXPIRY days Default: `LOG_EXPIRY=15` #### Settings used only by `recap` - **MAILTO** - Send a report to the email defined. Default: `MAILTO=""` - **MIN_FREE_SPACE** - Minimum free space (in MB) required in `${BASEDIR}` to run recap, a value of 0 deactivates this check. Default: `MIN_FREE_SPACE=0` #### Reports These are the type of reports generated and their dependencies. ##### fdisk - **USEFDISK** - Generates logs from "fdisk `${OPTS_FDISK}`" Default: `USEFDISK="no"` ##### mysql - **USEMYSQL** - Generates logs from "mysqladmin status" Makes use of `DOTMYDOTCNF`. Required by: `USEMYSQLPROCESSLIST`, `USEINNODB` Default: `USEMYSQL="no"` - **USEMYSQLPROCESSLIST** - Generates logs from "mysqladmin processlist" Makes use of `DOTMYDOTCNF` and `MYSQL_PROCESS_LIST` Requires: `USEMYSQL` Default: `USEMYSQLPROCESSLIST="no"` - **USEINNODB** - Generates logs from "mysql show engine innodb status" Makes use of `DOTMYDOTCNF` Requires: `USEMYSQL` Default: `USEINNODB="no"` ##### netstat - **USENETSTAT** - Generates network stats from "ss `${OPTS_NETSTAT}`" Required by: `USENETSTATSUM` Default: `USENETSTAT="yes"` - **USENETSTATSUM** - Generates logs from "nstat `${OPTS_NETSTAT_SUM}`". Requires: `USENETSTAT` Default: `USENETSTATSUM="no"` ##### ps - **USEPS** - Generates logs from "ps" Options can be modified in `OTPS_PS` Default: `USEPS="yes"` ##### pstree - **USEPSTREE** - Generates logs from pstree Options can be modified in `OTPS_PSTREE` Default: `USEPSTREE="no"` ##### resources - **USERESOURCES** - Generates "resources"(uptime, free, vmstat, iostat, iotop) log Required by: `USEDF`, `USESLAB`, `USESAR`, `USESARQ`, `USESARR` Default: `USERESOURCES="yes"` - **USEDF** - Generates logs from df Requires: `USERESOURCES` Options can be modified in `OPTS_DF` Default: `USEDF="yes"` - **USESLAB** - Generates logs from the slab table. Requires: `USERESOURCES` Default: `USESLAB="no"` - **USERSAR** - Generates logs from sar. Requires: `USERESOURCES` Default: `USESAR="yes"` - **USESARQ** - Generates logs from "sar -q" (logs queue length, load data) Requires: `USERESOURCES` Default: `USESARQ="no"` - **USESARR** - Generates logs from"sar -r" (logs memory data) Requires: `USERESOURCES` Default: `USESARR="no"` #### Options Options used by the tools generating the reports - **DOTMYDOTCNF** - Defines the path to the mysql client configuration file Required by: `USEMYSQL`, `USEMYSQLPROCESSLIST`, `USEINNODB` Default: `DOTMYDOTCNF="/root/.my.cnf"` - **MYSQL_PROCESS_LIST** - Format to display MySQL process list, options are "table" or "vertical". Required by: `USEMYSQLPROCESSLIST` Default: `MYSQL_PROCESS_LIST="table"` - **OPTS_DF** - df options Required by: `USEDF` Default: `OPTS_DF="-x nfs"` - **OPTS_FDISK** - Option used by USEFDISK. Required by: `USEFDISK` Default: `OPTS_FDISK="-l"` - **OPTS_FREE** - free options Required by: `USEFREE` Default: `OPTS_FREE=""` - **OPTS_IOSTAT** - iostat options Required by: `USERESOURCES` Default: `OPTS_IOSTAT="-t -x 1 3"` - **OPTS_IOTOP** - iotop options Required by: `USERESOURCES` Default: `OPTS_IOTOP="-b -o -t -n 3"` - **OPTS_NETSTAT** - ss options Required by: `USENETSTAT` Default: `OPTS_NETSTAT="-atunp"` - **OPTS_NETSTAT_SUM** - nstat options Required by: `USENETSTATSUM` Default: `OPTS_NETSTAT_SUM="-a"` - **OPTS_PS** - ps options Required by: `USEPS` Default: `OPTS_PS="auxfww"` - **OPTS_PSTREE** - pstree options Required by: `USEPSTREE` Default: `OPTS_PSTREE="-p"` - **OPTS_VMSTAT** - vmstat options Required by: `USERESOURCES` Default: `OPTS_VMSTAT="-S M 1 3"` ## Plugins - **USEPLUGINS** - Enable/Disable plugins usage. Default: `USEPLUGINS=no` Plugins are stored in the plugin directory, defined by **LIBDIR**/plugins-available Default: /usr/lib/local/recap/plugin-available ### Enabling plugins To enable plugins, the following is required to: - Setting `USEPLUGINS="yes"` in `/etc/recap.conf` - Symlinking `plugins-enabled/plugin_name` to `plugins-available/plugin_name` ### Naming conventions: - Plugin scripts can be named in any way. It's desired that they describe the purpose of the plugin in one word. When multiple words are required use underscores (`_`). Don't use extensions or dates (e.g. `YYYYMMDD`) in the plugin name. Some examples: - **Good** names for plugins - redis - memcache - docker_images - memcache_13 - **Bad** names for plugins - johndoe_apache (not very descriptive) - myplugin (non explicit) - test.sh (non explicit, using extension) - recap-plugin (non explicit, using hyphens) - Sendmail (CamelCase) - redis.bak (extension) - ms sql (space between words) - reports_20202020 (use of a date) - Allowed naming convention for plugin **OPTIONS** in /etc/recap.conf: **PLUGIN_OPTS__** Some examples: - **Good** plugin option names: - **PLUGIN_OPTS_MEMCACHE_PROTO** - **PLUGIN_OPTS_AWS_KEY** - **PLUGIN_OPTS_REDIS_PORT** - **PLUGIN_OPTS_DOCKER_HUB_URL** - **Bad** plugin option names: - plugin_opts_my_plugin (lower case) - PLUGIN_OPTS_MY_VARIABLE (lacking plugin reference) - PLUGIN_OPTS_DOCKER_port (CamelCase) - PLUGIN-OPTS-NTP (using hyphens instead of underscores, missing the option) - Inside the plugin file/script it is expected **only** functions. recap will **only** call **one** function: `print_` where `plugin_name` must match the name of the file. - Optionally, other functions can be defined to create different entries in the log. Those other functions could be controlled by plugin variables (**PLUGIN_OPTS__**). Those variables are set in `/etc/recap.conf` and conditionally called from the main plugin function `plugin_name` - Any plugin variable defined **must** have a default value. - The plugins are expected to follow some of the practices followed in `recap`. Please refer to [CONTRIBUTING.md](https://github.com/rackerlabs/recap/blob/master/CONTRIBUTING.md) - A template of a plugin is provided in `doc/plugin_template` ## Changelog & Contributions Information about changes and contributors is documented in the [CHANGELOG.md](https://github.com/rackerlabs/recap/blob/master/CHANGELOG.md) ## License *recap* is licensed under the [GNU General Public License v2.0](https://raw.githubusercontent.com/rackerlabs/recap/master/COPYING) recap-2.0.2/doc/000077500000000000000000000000001343607135600133625ustar00rootroot00000000000000recap-2.0.2/doc/plugin_template000066400000000000000000000021331343607135600164750ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # print_() { local LOGFILE="$1" local plugin_name=${FUNCNAME[0]/print_/} log INFO "Starting '${plugin_name}' report - ${LOGFILE##*/}" ## Write your plugin here, redirect output to ${LOGFILE} # echo hello from >> "${LOGFILE}" ## End of your plugin log INFO "Ended '${plugin_name}' report" } recap-2.0.2/src/000077500000000000000000000000001343607135600134045ustar00rootroot00000000000000recap-2.0.2/src/core/000077500000000000000000000000001343607135600143345ustar00rootroot00000000000000recap-2.0.2/src/core/fdisk000066400000000000000000000020451343607135600153600ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Print the disk partitions to the fdisk file print_fdisk() { local LOGFILE="$1" log INFO "Starting 'disk partition' report - ${LOGFILE##*/}" echo "Disk partitions" >> "${LOGFILE}" fdisk ${OPTS_FDISK} 2>&1 >> "${LOGFILE}" log INFO "Ended 'disk partition' report" } recap-2.0.2/src/core/mysql000066400000000000000000000113051343607135600154240ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Print the output of "mysqladmin status" to the mysql file print_mysql() { log INFO "Starting 'mysql status' report - ${LOGFILE##*/}" local LOGFILE="$1" local MYCNF="$2" local PLESK_FILE="/etc/psa/.psa.shadow" if [[ -r "${PLESK_FILE}" ]]; then echo "MySQL (plesk) status" >> "${LOGFILE}" mysqladmin \ -uadmin \ -p$(cat "${PLESK_FILE}") \ --connect-timeout=5 \ status >> "${LOGFILE}" else echo "MySQL (${MYCNF}) status" >> "${LOGFILE}" mysqladmin \ --defaults-file="${MYCNF}" \ --connect-timeout=5 \ status >> "${LOGFILE}" fi print_blankline "${LOGFILE}" log INFO "Ended 'mysql status' report" } # Print the non-truncated innodb status to the mysql file print_mysql_innodb_status() { log INFO "Starting 'mysql innodb' report - ${LOGFILE##*/}" local LOGFILE="$1" local MYCNF="$2" local mysql_cmd='' unset MYVALS PID_FILE TMPDIR if [[ -r "${PLESK_FILE}" ]]; then echo "MySQL (plesk) InnoDB status" >> "${LOGFILE}" mysql_cmd="mysql -uadmin -p$(cat ${PLESK_FILE}) --connect-timeout=5" else echo "MySQL (${MYCNF}) InnoDB status" >> "${LOGFILE}" mysql_cmd="mysql --defaults-file=${MYCNF} --connect-timeout=5" fi # First, we establish which tmpdir and pid_file are in use, strip any # trailing slash and populate the file with current information. # We throw away the output of the "show engine innodb status" command as # it is likely being truncated, which we attempt to work around: local -a MYVALS=( $( IFS=$'\t' ${mysql_cmd} \ -Bse "SHOW VARIABLES LIKE 'pid_file'; \ SHOW VARIABLES LIKE 'tmpdir'; \ SHOW ENGINE INNODB STATUS;" \ 2>/dev/null \ | head -n 2 ) ) local PID_FILE="${MYVALS[1]%/}" local TMPDIR="${MYVALS[3]%/}" # Next, we grab a list of descriptors in the tmpdir: if [[ -r "${PID_FILE}" && -d "${TMPDIR}" ]]; then for name in "/proc/"$(cat ${PID_FILE})"/fd/"*; do # We know that InnoDB's temporary files are always in the mysql tmpdir # and start with the string 'ib' followed by a randomly generated series # of characters. Now we can compare the canonicalized path of fd to the # tmpdir/ib* pattern: if [[ "$(readlink -f "${name}")" == "${TMPDIR}"/ib* ]]; then # If any files match that pattern, we see if the first line in the file # starts with "===", which is the case in the particular InnoDB file we # care about: head -c8 "${name}" | grep -q '^====' && cat "${name}" >> "${LOGFILE}" fi done fi log INFO "Ended 'mysql innodb' report" } # Print the output of "mysqladmin processlist" to the mysql file print_mysql_procs() { log INFO "Starting 'mysql processlist' report - ${LOGFILE##*/}" local LOGFILE="$1" local MYCNF="$2" local PLESK_FILE="/etc/psa/.psa.shadow" if [[ -r "${PLESK_FILE}" ]]; then echo "MySQL (plesk) processes" >> "${LOGFILE}" if [[ ${MYSQL_PROCESS_LIST,,} == "table" ]]; then mysqladmin \ -uadmin \ -p$( cat "${PLESK_FILE}" ) \ -v processlist \ --connect-timeout=5 \ >> "${LOGFILE}" fi if [[ ${MYSQL_PROCESS_LIST,,} == "vertical" ]]; then mysql \ -uadmin \ -p$( cat "${PLESK_FILE}" ) \ --connect-timeout=5 \ -e "show full processlist\G" \ >> "${LOGFILE}" fi else echo "MySQL (${MYCNF}) processes" >> "${LOGFILE}" if [[ ${MYSQL_PROCESS_LIST} == "table" ]]; then mysqladmin \ --defaults-file="${MYCNF}" \ -v processlist \ --connect-timeout=5 \ >> "${LOGFILE}" elif [[ ${MYSQL_PROCESS_LIST,,} == "vertical" ]]; then mysql \ --defaults-file="${MYCNF}" \ --connect-timeout=5 \ -e "show full processlist\G" \ >> "${LOGFILE}" fi fi print_blankline "${LOGFILE}" log INFO "Ended 'mysql processlist' report" } recap-2.0.2/src/core/netstat000066400000000000000000000034351343607135600157460ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Print the output of "ss -atunp" to the specified file print_netstat() { local LOGFILE="$1" log INFO "Starting 'network socket' report - ${LOGFILE##*/}" echo "Network connections" >> "${LOGFILE}" if ss ${OPTS_NETSTAT} &>/dev/null; then ss ${OPTS_NETSTAT} >> "${LOGFILE}" else ss ${default_OPTS_NETSTAT} >> "${LOGFILE}" log WARNING "Bad config: '${OPTS_NETSTAT}', "\ "using default: '${default_OPTS_NETSTAT}'" fi log INFO "Ended 'network socket' report" } # Print the output of "nstat -a" to the specified file print_netstat_sum() { local LOGFILE="$1" log INFO "Starting 'network summary' report - ${LOGFILE##*/}" echo "Network traffic summary" >> "${LOGFILE}" if nstat ${OPTS_NETSTAT_SUM} &>/dev/null; then nstat ${OPTS_NETSTAT_SUM} >> "${LOGFILE}" else nstat ${default_OPTS_NETSTAT_SUM} >> "${LOGFILE}" log WARNING "Bad config: '${OPTS_NETSTAT_SUM}', "\ "using default: '${default_OPTS_NETSTAT_SUM}'" fi log INFO "Ended 'network summary' report" } recap-2.0.2/src/core/ps000066400000000000000000000017341343607135600147060ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Print output of "ps auxfww" to the specified file print_ps() { local LOGFILE="$1" log INFO "Starting 'ps' report - ${LOGFILE##*/}" ps ${OPTS_PS} >> "${LOGFILE}" log INFO "Ended 'ps' report" } recap-2.0.2/src/core/pstree000066400000000000000000000017511343607135600155650ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Print output of "pstree" to specified file print_pstree() { local LOGFILE="$1" log INFO "Starting 'pstree' report - ${LOGFILE##*/}" pstree ${OPTS_PSTREE} >> "${LOGFILE}" log INFO "Ended 'pstree' report" } recap-2.0.2/src/core/resources000066400000000000000000000105541343607135600162760ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Print the output of "uptime" to the specified file print_uptime() { local LOGFILE="$1" log INFO "Starting 'uptime' report - ${LOGFILE##*/}" echo "UPTIME report" >> "${LOGFILE}" uptime >> "${LOGFILE}" log INFO "Ended 'uptime' report" } # Print the output of "free" to the specified file print_free() { local LOGFILE="$1" log INFO "Starting 'free' report - ${LOGFILE##*/}" echo "FREE report" >> "${LOGFILE}" free ${OPTS_FREE} >> "${LOGFILE}" log INFO "Ended 'free' report" } # Print the output of "vmstat" to the specified file print_vmstat() { local LOGFILE="$1" log INFO "Starting 'vmstat' report - ${LOGFILE##*/}" echo "VMSTAT report" >> "${LOGFILE}" vmstat ${OPTS_VMSTAT} >> "${LOGFILE}" log INFO "Ended 'vmstat' report" } # Print the output of "iostat" to the specified file print_iostat() { local LOGFILE="$1" log INFO "Starting 'iostat' report - ${LOGFILE##*/}" echo "IOSTAT report" >> "${LOGFILE}" iostat ${OPTS_IOSTAT} >> "${LOGFILE}" log INFO "Ended 'iostat' report" } # Print the output of "iotop" to the specified file print_iotop() { local LOGFILE="$1" log INFO "Starting 'iotop' report - ${LOGFILE##*/}" echo "IOTOP report" >> "${LOGFILE}" iotop ${OPTS_IOTOP} >> "${LOGFILE}" log INFO "Ended 'iotop' report" } # Print the output of sar to the specified file print_sar() { local LOGFILE="$1" local OPTION="$2" log INFO "Starting 'sar' report - ${LOGFILE##*/}" local FLAGS='' # check to see if we're going to use any parameters for sar if [[ "${OPTION}" == "r" ]]; then FLAGS="-r" elif [[ "${OPTION}" == "q" ]]; then FLAGS="-q" else FLAGS="" fi echo "SAR${FLAGS} report" >> "${LOGFILE}" sar "${FLAGS}" >> "${LOGFILE}" log INFO "Ended 'sar' report" } # Print the disk utilization to the defined file print_df() { local LOGFILE="$1" log INFO "Starting 'disk utilization' report - ${LOGFILE##*/}" local LOGFILE="$1" echo "Disk Utilization" >> "${LOGFILE}" df ${OPTS_DF} >> "${LOGFILE}" log INFO "Ended 'disk utilization' report" } # Print the slabinfo command to the defined file print_slabinfo() { local LOGFILE="$1" log INFO "Starting 'slab info' report - ${LOGFILE##*/}" echo "Slab Information" >> "${LOGFILE}" printf "name\tactive\tnum_obj\tobj_size\thuh\n" >> "${LOGFILE}" tail -n+2 /proc/slabinfo | awk 'size=$3*$4 {print $1"\t"$2"\t"$3"\t"$4"\t"size/1048576}' | sort -k5gr >> "${LOGFILE}" log INFO "Ended 'slab info' report" } # Print the top 10 processes (by cpu usage) to the defined file print_top_10_cpu() { local LOGFILE="$1" log INFO "Starting 'top 10 cpu' report - ${LOGFILE##*/}" local pidstat_cpufield=0 # Systat versions have the CPU field in different places. # Calculate dynamically the %CPU field local pidstat_fields=( $(LC_ALL=C pidstat | sed -n '3p') ) for index in $(seq 0 ${#pidstat_fields[@]}); do if [[ "${pidstat_fields[${index}]}" == "%CPU" ]]; then # Array is 0 index, sorting is not, we add 1 pidstat_cpufield=$(( ${index} + 1 )) break fi done echo "Top 10 cpu using processes" >> "${LOGFILE}" # capture header LC_ALL=C pidstat | sed -n '3p' >> "${LOGFILE}" LC_ALL=C pidstat -l 2 2 | grep -v '%system' | egrep ^Average: | sort -nr -k ${pidstat_cpufield} | head -11 >> "${LOGFILE}" log INFO "Ended 'top 10 cpu' report" } # Print the top 10 processes (by memory usage) to the defined file print_top_10_mem() { local LOGFILE="$1" log INFO "Starting 'top 10 memory' report - ${LOGFILE##*/}" echo "Top 10 memory using processes" >> "${LOGFILE}" ps auxww --sort=-rss | head -11 >> "${LOGFILE}" log INFO "Ended 'top 10 memory' report" } recap-2.0.2/src/core/send_mail000066400000000000000000000035741343607135600162230ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Send the report via email send_mail() { log INFO "Starting email report" # create a temp directory local TEMPDIR=$( mktemp -d "/tmp/rs.XXXXXXXXXX" ) local REPORT="${TEMPDIR}/report.log" local ITEM_FILE="" local ITEM_USE="" # echo report files into temporary file for mailing local -a items=( $( get_report_names_of_run ) ) for item in ${items[@]}; do ITEM_FILE="${BASEDIR}/${item}_${LOG_SUFFIX}.log" # Build the variable to use and then use indirect ref to obtain its value ITEM_USE="USE${item^^}" if [[ -r "${ITEM_FILE}" && "${!ITEM_USE,,}" == "yes" ]]; then echo "-----BEGIN ${item^^} REPORT-----" >> "${REPORT}" cat "${ITEM_FILE}" >> "${REPORT}" echo "-----END ${item^^} REPORT-----" >> "${REPORT}" echo " " >> "${REPORT}" fi done log INFO "Ended email report" # send email summary to MAILTO address log INFO "Sending email report to: ${MAILTO}" if [[ -r "${REPORT}" ]]; then cat "${REPORT}" | mail -s "System Monitor Report - ${HOSTNAME}" "${MAILTO}" # Remove the temporary files rm -rf "${TEMPDIR}" fi log INFO "Sent email report" } recap-2.0.2/src/plugins/000077500000000000000000000000001343607135600150655ustar00rootroot00000000000000recap-2.0.2/src/plugins/docker_top000066400000000000000000000030761343607135600171470ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # print_docker_top() { local LOGFILE="$1" local plugin_name=${FUNCNAME[0]/print_/} log INFO "Starting '${plugin_name}' report - ${LOGFILE##*/}" ## DOCKER=$( type -p docker || true ) if [[ -z ${DOCKER} ]]; then echo "Docker is not installed" >> "${LOGFILE}" log INFO "Ended '${plugin_name}' report" return fi local -a docker_running_containers docker_running_containers+=( $( ${DOCKER} ps 2>/dev/null \ --filter status=running \ --format="{{.Names}}:{{.ID}}" ) ) for container in ${docker_running_containers[@]}; do c_name=${container//:*} c_id=${container##*:} echo "${c_name} - ${c_id}" >> "${LOGFILE}" ${DOCKER} top ${c_id} >> "${LOGFILE}" echo -e "---\n" >> "${LOGFILE}" done ## log INFO "Ended '${plugin_name}' report" } recap-2.0.2/src/plugins/http_status000066400000000000000000000035441343607135600174000ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Performs an http request(GET) to the defined URL print_http_status() { local LOGFILE="$1" local plugin_name=${FUNCNAME[0]/print_/} log INFO "Starting '${plugin_name}' report - ${LOGFILE##*/}" ## # Default settings: local default_args='-dump' local default_timeout=5 local default_url='http://localhost:80/server-status' # These values can be overriden in the config file, Examples: # PLUGIN_OPTS_HTTP_STATUS_ARGS='-dump -dump-width 90 -dump-charset iso-8859-2' # PLUGIN_OPTS_HTTP_STATUS_URL='http://localhost/nginx_status' local http_status_args=${PLUGIN_OPTS_HTTP_STATUS_ARGS:-${default_args}} local http_status_url=${PLUGIN_OPTS_HTTP_STATUS_URL:-${default_url}} # Check if html dump tool is available http_tool=$( type -p elinks ) if [[ -z ${http_tool} ]]; then echo "elinks is not installed" >> "${LOGFILE}" log INFO "Ended '${plugin_name}' report" return fi timeout ${default_timeout} \ ${http_tool} \ ${http_status_args} \ "${http_status_url}" \ 2>/dev/null >> "${LOGFILE}" ## log INFO "Ended '${plugin_name}' report" } recap-2.0.2/src/plugins/kernel_cmd000066400000000000000000000020531343607135600171130ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # # Print output of "ps auxfww" to the specified file print_kernel_cmd() { local LOGFILE="$1" local plugin_name=${FUNCNAME[0]/print_/} log INFO "Starting '${plugin_name}' report - ${LOGFILE##*/}" cat /proc/cmdline >> "${LOGFILE}" log INFO "Ended '${plugin_name}' report" } recap-2.0.2/src/plugins/redis000066400000000000000000000074671343607135600161340ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # print_redis() { local LOGFILE="$1" local plugin_name=${FUNCNAME[0]/print_/} local redis_cli=$( type -p redis-cli ) local host=${PLUGIN_OPTS_REDIS_HOST:-"127.0.0.1"} local port=${PLUGIN_OPTS_REDIS_PORT:-"6379"} # Wrap the more time consuming tests behind a default "no" flag local timings=${PLUGIN_OPTS_REDIS_TIMINGS:-"no"} # Wrap the less useful client listing behind a default "no" flag local clients=${PLUGIN_OPTS_REDIS_CLIENTS:-"no"} log INFO "Starting '${plugin_name}' report - ${LOGFILE##*/}" print_blankline "${LOGFILE}" if [[ -n "${redis_cli}" ]]; then if [[ "${timings,,}" == "yes" ]]; then print_redis_timings print_blankline "${LOGFILE}" fi print_redis_cmd "INFO ALL" print_blankline "${LOGFILE}" if [[ "${clients,,}" == "yes" ]]; then print_redis_cmd "CLIENT LIST" print_blankline "${LOGFILE}" fi else # If the redis-cli is unavailable, fallback to ncat print_redis_cmd_fallback "INFO ALL" if [[ "${clients,,}" == "yes" ]]; then print_redis_cmd_fallback "CLIENT LIST" fi fi log INFO "Ended '${plugin_name}' report" } # Executing this functions takes ~20 seconds as each command is sampling # performance in a timeframe print_redis_timings() { echo "Redis stat (+delta / 0.5s)" >> "${LOGFILE}" # stdbuf is used to ensure we get output from buffer before it's terminated timeout 5 stdbuf -oL \ "${redis_cli}" -h "${host}" -p "${port}" --stat -i 0.5 &>> "${LOGFILE}" print_blankline "${LOGFILE}" # Tests latency by sending "PING" and waiting for "PONG" echo "Redis average latencies (3s)" >> "${LOGFILE}" print_redis_latency print_redis_latency print_redis_latency print_blankline "${LOGFILE}" # Tests the client where the command is ran from for system latency echo "Local System Intrinsic Latency (5s)" >> "${LOGFILE}" "${redis_cli}" --intrinsic-latency 5 &>> "${LOGFILE}" } print_redis_latency() { # Redis 4 changes the output and auto-exits after 1 second (default interval) # Once 3.2 is EOL, remove the "timeout" and just use the set "interval" local latency=$( timeout 3 \ "${redis_cli}" -h "${host}" -p "${port}" --latency -i 2.5 2>&1 ) # We have to filter the output for the last occurrence (splitting on the # ANSI 2K "Clear entire line") # Running "redis-cli --latency | cat -e" would show the problem this resolves echo "$( ts ) ${latency##*2K}" >> "${LOGFILE}" } print_redis_cmd() { local command="$1" echo "Redis ${command}" >> "${LOGFILE}" # The redis-cli client doesn't have built-in connection timeout handling, # thus we must use "timeout" to stop it hanging when we don't get a reply timeout 3 \ "${redis_cli}" -h "${host}" -p "${port}" ${command} &>> "${LOGFILE}" } print_redis_cmd_fallback() { local command="$1" echo "Redis ${command} (via ncat)" >> "${LOGFILE}" # Connection timeout of 3 seconds and forcing CRLF for lines ( printf "${command}\r\n"; sleep 1 ) | \ ncat -w 3 -C "${host}" "${port}" &>> "${LOGFILE}" || echo "Unable to connect to Redis on ${host}:${port}" >> "${LOGFILE}" } recap-2.0.2/src/recap000077500000000000000000000427521343607135600144360ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # #~ Usage: _tool_ [OPTION] #~ Options: #~ -h, --help Print this help. #~ -B, --backup Copy the last log file to the backups dir. #~ -S, --snapshot Take a timestamped snapshot outside the regular rotation. #~ -V, --version Print version and exit. #~ ## Version declare -r _VERSION='2.0.2' ## Default settings(can *NOT* be overridden in config file) declare -r DATE=$( date +%F_%T ) declare -r LOCKFILE="/var/lock/recap.lock" declare -r LOG_SUFFIX=$( date +%Y%m%d-%H%M%S ) declare -r LIBDIR="/usr/local/lib/recap" declare -r COREDIR="${LIBDIR}/core" declare -r PLUGIN_A_DIR="${LIBDIR}/plugins-available" declare -r PLUGIN_E_DIR="${LIBDIR}/plugins-enabled" PATH=/bin:/usr/bin:/sbin:/usr/sbin ## Default settings(modified through command line arguments) declare -r default_BACKUP="no" declare -r default_SNAPSHOT="no" BACKUP="${default_BACKUP}" SNAPSHOT="${default_SNAPSHOT}" ## Default settings(can be overridden in config file) declare -r default_BASEDIR="/var/log/recap" declare -r default_RECAPLOG="${default_BASEDIR}/recap.log" declare -r default_MAILTO="" declare -r default_MIN_FREE_SPACE=0 declare -r default_USEFDISK="no" declare -r default_USEPS="yes" declare -r default_USEPSTREE="no" declare -r default_USESLAB="no" declare -r default_USEPLUGINS="no" BASEDIR="${default_BASEDIR}" RECAPLOG="${default_RECAPLOG}" MAILTO="${default_MAILTO}" MIN_FREE_SPACE=${default_MIN_FREE_SPACE} USEFDISK="${default_USEFDISK}" USEPS="${default_USEPS}" USEPSTREE="${default_USEPSTREE}" USESLAB="${default_USESLAB}" USEPLUGINS="${default_USEPLUGINS}" # Parent setting(other settings depend on this) declare -r default_USERESOURCES="yes" USERESOURCES="${default_USERESOURCES}" # These depend on USERRESOURCES to be enabled("yes") declare -r default_USEDF="yes" declare -r default_USESAR="yes" declare -r default_USESARQ="no" declare -r default_USESARR="no" USEDF="${default_USEDF}" USESAR="${default_USESAR}" USESARQ="${default_USESARQ}" USESARR="${default_USESARR}" # Parent setting(other settings depend on this) declare -r default_USENETSTAT="yes" USENETSTAT="${default_USENETSTAT}" # These depend on USENETSTAT to be enabled("yes") declare -r default_USENETSTATSUM="no" USENETSTATSUM="${default_USENETSTATSUM}" # Parent setting(other settings depend on this) declare -r default_USEMYSQL="no" USEMYSQL="${default_USEMYSQL}" # These depend on USEMYSQL to be enabled("yes") declare -r default_DOTMYDOTCNF="/root/.my.cnf" declare -r default_MYSQL_PROCESS_LIST="table" declare -r default_USEINNODB="no" declare -r default_USEMYSQLPROCESSLIST="no" DOTMYDOTCNF="${default_DOTMYDOTCNF}" MYSQL_PROCESS_LIST="${default_MYSQL_PROCESS_LIST}" USEINNODB="${default_USEINNODB}" USEMYSQLPROCESSLIST="${default_USEMYSQLPROCESSLIST}" # Default command options(can be overridden in config file) declare -r default_OPTS_DF="-x nfs" declare -r default_OPTS_FDISK="-l" declare -r default_OPTS_FREE="" declare -r default_OPTS_IOSTAT="-t -x 1 3" declare -r default_OPTS_IOTOP="-b -o -t -n 3" declare -r default_OPTS_NETSTAT="-atunp" declare -r default_OPTS_NETSTAT_SUM="-a" declare -r default_OPTS_PS="auxfww" declare -r default_OPTS_PSTREE="-p" declare -r default_OPTS_VMSTAT="-S M 1 3" OPTS_DF="${default_OPTS_DF}" OPTS_FDISK="${default_OPTS_FDISK}" OPTS_FREE="${default_OPTS_FREE}" OPTS_IOSTAT="${default_OPTS_IOSTAT}" OPTS_IOTOP="${default_OPTS_IOTOP}" OPTS_NETSTAT="${default_OPTS_NETSTAT}" OPTS_NETSTAT_SUM="${default_OPTS_NETSTAT_SUM}" OPTS_PS="${default_OPTS_PS}" OPTS_PSTREE="${default_OPTS_PSTREE}" OPTS_VMSTAT="${default_OPTS_VMSTAT}" # Internal variables banner_start="--- Starting $( basename $0 )[$$] ---" banner_end="--- Ending $( basename $0 )[$$] ---" # Functions # Timestamps ts() { TS_FLAGS='--rfc-3339=seconds' date "${TS_FLAGS}" } # Logging messages log() { # does not work in a while-loop as spawns a new shell local msg_type=$1 shift local log_entry="$*" ## This avoids sending any output to stdout when executed through cron ## is helpful to avoid emails submitted, instead the logs contain the ## possible ERRORS if ! tty -s; then echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 >> "${RECAPLOG}" return 0 fi if [[ "${VERBOSE}" ]]; then echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 | tee -a "${RECAPLOG}" return 0 fi if [[ "${msg_type}" =~ "ERROR" || "${msg_type}" =~ "WARNING" ]]; then echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 | tee -a "${RECAPLOG}" else echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 >> "${RECAPLOG}" fi } # Usage print_usage() { grep -E '^#~' $0 | sed -e 's/^#~\s\?//' \ -e "s/_tool_/$( basename $0 )/" } # Cleanup function to remove lock cleanup() { log INFO "$( basename $0 )[$$]: Caught signal - deleting ${LOCKFILE}" rm -f "${LOCKFILE}" log INFO "Execution time: ${SECONDS}s" log INFO "${banner_end}" } # Create a Lock so that recap does not try to run over itself. recaplock() { (set -C; echo "$$" > "${LOCKFILE}") 2>/dev/null if [[ $? -ne 0 ]]; then log ERROR "$( basename $0 )[$$]: Lock File exists - exiting" exit 1 else trap 'exit 2' 1 2 15 23 trap 'cleanup' EXIT log INFO "$( basename $0 )[$$]: Created lock file: ${LOCKFILE}" fi } # Ensure our output directories exist before we start creating files create_output_dirs() { BACKUPDIR="${BASEDIR}/backups" SNAPSHOTSDIR="${BASEDIR}/snapshots" local -a OUTPUT_DIRS OUTPUT_DIRS+=( "${BASEDIR}" ) OUTPUT_DIRS+=( "${BACKUPDIR}" ) OUTPUT_DIRS+=( "${SNAPSHOTSDIR}" ) for OUTPUT_DIR in ${OUTPUT_DIRS[@]}; do if [[ ! -d "${OUTPUT_DIR}" ]]; then mkdir -p "${OUTPUT_DIR}" fi done chmod 0750 "${BASEDIR}" } # Create output file create_output_file() { local OUTPUT_FILE="$1" if [[ -d "${OUTPUT_FILE}" ]]; then log ERROR "Target file already exists: ${OUTPUT_FILE}" exit else #print the data to the output file echo "${DATE}" > "${OUTPUT_FILE}" fi } # Check to see if the output directory exists check_output_file() { local OUTPUT_FILE="$1" if [[ ! -r "${OUTPUT_FILE}" ]]; then log ERROR "The output file does not exist: ${OUTPUT_FILE}" exit fi } # Print a blank line to the specified file print_blankline() { local LOGFILE="$1" echo " " >> "${LOGFILE}" } # Plugin names # Obtain the list of files/plugins on a directory plugins_list() { local plugin_dir="$1" local p_names=( $( ls -1 "${plugin_dir}" | tr '\n' ' ') ) echo ${p_names[@]} } # Plugin info plugins_info(){ for dir in "${PLUGIN_A_DIR}" "${PLUGIN_E_DIR}"; do log INFO "Finding plugins in ${dir}" plugins=( $( plugins_list "${dir}" ) ) if [[ ${#plugins[@]} == 0 ]]; then log INFO "No plugins found." else log INFO "${#plugins[@]} plugins found: ${plugins[@]}" fi done } # Loads plugins plugins_load() { local plugin_dir="$1" log INFO "Loading plugins from: ${plugin_dir}" while read plugin; do log INFO "Loading plugin: ${plugin}" source "${plugin_dir}/${plugin}" done < <(ls -1 "${plugin_dir}" 2>/dev/null) } # Load core functions source ${COREDIR}/ps source ${COREDIR}/fdisk source ${COREDIR}/mysql source ${COREDIR}/pstree source ${COREDIR}/netstat source ${COREDIR}/resources source ${COREDIR}/send_mail # Manage item report run_item_report() { local item="$1" local ITEM_FILE="${BASEDIR}/${item}_${LOG_SUFFIX}.log" if [[ "${SNAPSHOT,,}" == "yes" ]]; then ITEM_FILE="${SNAPSHOTSDIR}/${item}_${LOG_SUFFIX}.log_snapshot" fi create_output_file "${ITEM_FILE}" check_output_file "${ITEM_FILE}" eval "print_${item}" "${ITEM_FILE}" } # Manage resources report run_resources_report() { local item="resources" local ITEM_FILE="${BASEDIR}/${item}_${LOG_SUFFIX}.log" if [[ "${SNAPSHOT,,}" == "yes" ]]; then ITEM_FILE="${SNAPSHOTSDIR}/${item}_${LOG_SUFFIX}.log_snapshot" fi create_output_file "${ITEM_FILE}" check_output_file "${ITEM_FILE}" print_uptime "${ITEM_FILE}" print_blankline "${ITEM_FILE}" print_free "${ITEM_FILE}" print_blankline "${ITEM_FILE}" print_vmstat "${ITEM_FILE}" print_blankline "${ITEM_FILE}" print_iostat "${ITEM_FILE}" print_blankline "${ITEM_FILE}" print_iotop "${ITEM_FILE}" print_blankline "${ITEM_FILE}" # check to see if sar should be run if [[ "${USESAR,,}" == "yes" ]]; then print_blankline "${ITEM_FILE}" print_sar "${ITEM_FILE}" fi # check to see if sar -r should be run if [[ "${USESARR,,}" == "yes" ]]; then # send sar -r output to output file print_blankline "${ITEM_FILE}" print_sar "${ITEM_FILE}" "r" fi # check to see if sar -q should be run if [[ "${USESARQ,,}" == "yes" ]]; then # send sar -q output to output file print_blankline "${ITEM_FILE}" print_sar "${ITEM_FILE}" "q" fi if [[ "${USEDF,,}" == "yes" ]]; then # send df -h output to output file print_blankline "${ITEM_FILE}" print_df "${ITEM_FILE}" fi if [[ "${USESLAB,,}" == "yes" ]]; then # send slabinfo output to output file print_blankline "${ITEM_FILE}" print_slabinfo "${ITEM_FILE}" fi print_blankline "${ITEM_FILE}" print_top_10_cpu "${ITEM_FILE}" print_blankline "${ITEM_FILE}" print_top_10_mem "${ITEM_FILE}" } # Manage netstat report run_netstat_report() { local item="netstat" local ITEM_FILE="${BASEDIR}/${item}_${LOG_SUFFIX}.log" if [[ "${SNAPSHOT,,}" == "yes" ]]; then ITEM_FILE="${SNAPSHOTSDIR}/${item}_${LOG_SUFFIX}.log_snapshot" fi create_output_file "${ITEM_FILE}" check_output_file "${ITEM_FILE}" print_netstat "${ITEM_FILE}" # check to see if optional netstat summary report should be run if [[ "${USENETSTATSUM,,}" == "yes" ]]; then print_blankline "${ITEM_FILE}" print_netstat_sum "${ITEM_FILE}" fi } # Manage mysql report run_mysql_report() { local item="mysql" local ITEM_FILE="${BASEDIR}/${item}_${LOG_SUFFIX}.log" if [[ "${SNAPSHOT,,}" == "yes" ]]; then ITEM_FILE="${SNAPSHOTSDIR}/${item}_${LOG_SUFFIX}.log_snapshot" fi create_output_file "${ITEM_FILE}" check_output_file "${ITEM_FILE}" log INFO "Starting iteration of mysql report(s)" # Iterate through the list of DOTMYDOTCNF config files local -a MYCNFS=( ${DOTMYDOTCNF//,/ } ) for MYCNF in ${MYCNFS[@]}; do # Don't run reports if can't read the config file if [[ ! -r "${MYCNF}" ]]; then log ERROR "Unable to read: '${MYCNF}' in the 'DOTMYDOTCNF' config." continue fi # Don't run reports if can't connect to the instance if ! mysqladmin \ --defaults-file="${MYCNF}" \ --connect-timeout=5 \ ping &>/dev/null; then log ERROR "Unable to connect using '${MYCNF}' in the 'DOTMYDOTCNF'"\ "config." continue fi print_mysql "${ITEM_FILE}" "${MYCNF}" # check to see if the optional mysql process list should be generated if [[ "${USEMYSQLPROCESSLIST,,}" == "yes" ]]; then print_blankline "${ITEM_FILE}" print_mysql_procs "${ITEM_FILE}" "${MYCNF}" fi if [[ "${USEINNODB,,}" == "yes" ]]; then # send df -h output to output file print_blankline "${ITEM_FILE}" print_mysql_innodb_status "${ITEM_FILE}" "${MYCNF}" fi done log INFO "Ended iteration of mysql report(s)" } # Generates a list of names from the current run, using LOG_SUFFIX get_report_names_of_run() { local -a reports=() log INFO "Finding reports from this run: ${LOG_SUFFIX}" reports=( $( ls -1 "${BASEDIR}" 2>/dev/null | awk -F_ '/'${LOG_SUFFIX}'\.log$/ {print $1}' | sort -u ) ) log INFO "Reports found: [ ${reports[@]} ]" echo "${reports[@]}" } # Generates a list of names from the last reports logged get_last_report_names() { local -a reports=() local last_suffix='' last_suffix=$( ls -1 "${BASEDIR}" 2>/dev/null | grep -P '_\d{8}-\d{6}\.log$' | grep -oP '\d{8}-\d{6}' | sort -ur | head -1 ) if [[ -z ${last_suffix} ]]; then log ERROR "No previous run has been found, unable to find report names." else log INFO "Last run was on: ${last_suffix}" reports=( $( ls -1 "${BASEDIR}" 2>/dev/null | awk -F. ' /'${last_suffix}'\.log$/ {sub("_'${last_suffix}'","",$1); print $1} ' ) ) log INFO "Reports found: [ ${reports[@]} ]" fi echo "${reports[@]}" } # Copy the last log file set to ${BACKUPDIR} create_backup() { log INFO "Starting backup of reports" local -a log_files=( $( get_last_report_names ) ) if [[ -z ${log_files} ]]; then log ERROR "Unable to backup unexisting reports." else for log_file in ${log_files[@]}; do ls -1t ${BASEDIR}/${log_file}_*.log 2>/dev/null | head -1 | xargs -I {} cp {} ${BACKUPDIR} done fi log INFO "Ended backup of reports" } # Check enough disk space is free check_disk_space() { log INFO "Starting check for disk space" if [[ ${MIN_FREE_SPACE} -eq 0 ]]; then log INFO "Ended check for disk space" return 0 else FREE_SPACE=$( df -PBM "${BASEDIR}" | awk '!/-blocks/ {print $4}' ) FREE_SPACE=${FREE_SPACE%M} if [[ "${MIN_FREE_SPACE}" -ge "${FREE_SPACE}" ]]; then log ERROR "Unable to run recap due to not enough disk space" fi fi log INFO "Ended check for disk space" } ## Main # Set options OPTIONS=VBhS LONG_OPTIONS=version,backup,help,snapshot # Parse options and show usage if invalid options provided ! ALL_ARGS=$(getopt --options=${OPTIONS} --longoptions=${LONG_OPTIONS} --name "$0" -- "$@") if [[ ${PIPESTATUS[0]} -ne 0 ]]; then print_usage exit 1 fi # Set the positional parameters to the parsed options set -- ${ALL_ARGS} # Act on the valid arguments provided while true; do case "$1" in -V|--version) echo "${_VERSION}" exit 0 ;; -B|--backup) # backup latest log files BACKUP="yes" shift ;; -h|--help) # print usage print_usage exit 0 ;; -S|--snapshot) # take a snapshot outside of the regular output rotation SNAPSHOT="yes" shift ;; --) shift; break ;; *) # user entered an invalid flag, print warning and exit log ERROR "Invalid Input" print_usage exit 1 esac done if [[ "${BACKUP,,}" == "yes" && "${SNAPSHOT,,}" == "yes" ]]; then log ERROR "Backup and Snapshot options are mutually exclusive" print_usage exit 1 fi # Error if unparsed arguments exist if [[ "$#" -gt 0 ]]; then log ERROR "Error: Unexpected argument(s): $@" print_usage exit 1 fi # Verify that script is being run as root if [[ "$(id -u)" != "0" ]]; then log ERROR "This script must be run as root." exit fi # Grab the server's host name HOSTNAME="$( hostname )" # Start logging log INFO "${banner_start}" log INFO "-- bash info: ${BASH_VERSINFO[@]}" # Check for the configuration file. if [[ ! -r /etc/recap.conf ]]; then log WARNING "No configuration file found. Expecting /etc/recap.conf." log WARNING "Proceeding with defaults." else source /etc/recap.conf fi # Create lock recaplock # Create output directory if it is not already present create_output_dirs # Check disk space before generating reports check_disk_space # Take a backup when needed if [[ "${BACKUP,,}" == "yes" ]]; then log INFO "-- Taking backup, storing reports in ${BACKUPDIR}" create_backup exit 0 fi # Log when running a snapshot if [[ "${SNAPSHOT,,}" == "yes" ]]; then log INFO "-- Taking snapshot, storing reports in ${SNAPSHOTSDIR}" fi ## Proceed to report generation log INFO "-- Report suffix: ${LOG_SUFFIX}" # Run the ps report if [[ "${USEPS,,}" == "yes" ]]; then run_item_report "ps" fi # Run the resources report #TODO: standardize the run_resources_report if [[ "${USERESOURCES,,}" == "yes" ]]; then run_resources_report fi # Run the pstree report if [[ "${USEPSTREE,,}" == "yes" ]]; then run_item_report "pstree" fi # Run the netstat report #TODO: standardize the run_netstat_report if [[ "${USENETSTAT,,}" == "yes" ]]; then run_netstat_report fi # Run the fdisk report if [[ "${USEFDISK,,}" == "yes" ]]; then run_item_report "fdisk" fi # Run the mysql report #TODO: standardize the run_mysql_report if [[ "${USEMYSQL,,}" == "yes" ]]; then if type -p 'mysqladmin' > /dev/null; then run_mysql_report else log ERROR "mysql client is not installed, can't run mysql reports" fi fi # Load and Run plugins enabled if [[ "${USEPLUGINS,,}" == "yes" ]]; then # Log the info about plugins(available and enabled) plugins_info # Load only enabled plugins plugins_load "${PLUGIN_E_DIR}" plugins=( $( plugins_list "${PLUGIN_E_DIR}" ) ) if [[ "${#plugins[@]}" == 0 ]]; then log WARNING "No plugins found to execute in: ${PLUGIN_E_DIR}" else # Run the plugins enabled for plugin in ${plugins[@]}; do run_item_report "${plugin}" done fi fi # Check to see if report should be emailed #TODO: Validate MAILTO format. if [[ -n "${MAILTO}" ]]; then send_mail fi # We're done, time to exit log INFO "Ended all the reports" exit 0 recap-2.0.2/src/recap.8000066400000000000000000000053211343607135600145700ustar00rootroot00000000000000.\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 51 Franklin Street, Fifth Floor, .\" Boston, MA 02110-1301 USA. .\" .TH RECAP 8 "Aug 18, 2017" .SH NAME recap \- dumps periodic information about running applications and resource usage .SH SYNOPSIS .BI "recap " [OPTION] .SH DESCRIPTION recap is a user\-configurable script that can be run once, or run periodically out of cron or systemd.timers to dump information about running processes and resource usage. It's useful on servers that have periodic, mysterious performance anomalies for tracking down what may be going on at the time of any particular incident. The values for which reports are generated and how many reports are stored can be overridden in .IR /etc/recap.conf "." The output files from the script are written to .IR BASEDIR "." .TP .BR "\-B, \-\-backup" This will perform a "backup". It will copy the latest log files from the last execution to the "backups" directory inside BASEDIR. The files will be identified by a timestamp in the name. .TP .BR "\-S, \-\-snapshot" This will perform a "snapshot" report. It will generate a set of output files in the "snapshot" directory inside BASEDIR outside of the standard rotation. The files will be identified by a timestamp in the name. .TP .BR "\-V, \-\-version" Print version and exit. .TP .SH FILES .nf /etc/recap.conf /etc/cron.d/recap /usr/lib/systemd/system/recap.{service,timer} \- Unit files for running recap periodically. /usr/lib/systemd/system/recap\-onboot.{service,timer} \- Unit files for running recap on boot. .SH "REPORTING BUGS" Bugs and issues to be submitted via github . .SH AUTHOR The recap scripts are maintained by Rackspace, the list of contributors is available at https://github.com/rackerlabs/recap/blob/master/CHANGELOG.md#contributors. .SH "SEE ALSO" .BR recap.conf (5), .BR recaplog (8), .BR crontab (5), .BR systemd.timer (5) recap-2.0.2/src/recap.conf000066400000000000000000000135561343607135600153570ustar00rootroot00000000000000# Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # ### settings shared by recap scripts # BASEDIR - Directory where the logs are saved. # Example, to log in a different location: BASEDIR="/opt/recap" #BASEDIR="/var/log/recap" # LIBDIR - Directory where the functions are located. # Example, to use a different location: LIBDIR="/opt/recap/lib" #LIBDIR="/usr/lib/recap" ### settings used only by recaplog # LOG_COMPRESS - Enable or disable log compression. # Example, to disable: LOG_COMPRESS=0 #LOG_COMPRESS=1 # LOG_EXPIRY - Log files will be deleted after LOG_EXPIRY days # Example: LOG_EXPIRY=30 #LOG_EXPIRY=15 ### settings used only by recap # MAILTO - Send a report to the email defined. # Example: MAILTO="user@example.com" #MAILTO="" # MIN_FREE_SPACE - Minimum free space (in MB) required in ${BASEDIR} to # run recap, a value of 0 deactivates this check. # Example, ensure there are at least 5MB: MIN_FREE_SPACE=5 #MIN_FREE_SPACE=0 ### recap Reports ## Report: fdisk # USEFDISK - Generates logs from "fdisk ${OPTS_FDISK}" # Options can be modified in OPTS_FDISK # Example, to enable: USEFDISK="yes" #USEFDISK="no" ## Report: mysql # USEMYSQL - Generates logs from "mysqladmin status" # makes use of DOTMYDOTCNF. # Required by: USEMYSQLPROCESSLIST, USEINNODB # Example, to enable: USEMYSQL="yes" #USEMYSQL="no" # USEMYSQLPROCESSLIST - Generates logs from "mysqladmin processlist" # Makes use of DOTMYDOTCNF and MYSQL_PROCESS_LIST # requires: USEMYSQL # Example, to enable: USEMYSQLPROCESSLIST="yes" #USEMYSQLPROCESSLIST="no" # USEINNODB - Generates logs from "mysql show engine innodb status" # Makes use of DOTMYDOTCNF # requires: USEMYSQL # Example, to enable: USEINNODB="yes" #USEINNODB="no" ## Report: netstat # USENETSTAT - Generates network stats from "ss ${OPTS_NETSTAT}" # Required by: USENETSTATSUM # Example, to disable: USENETSTATSUM="no" #USENETSTAT="yes" # USENETSTATSUM - Generates logs from "nstat ${OPTS_NETSTAT_SUM}". # requires: USENETSTAT # Example, to enable: USENETSTATSUM="yes" #USENETSTATSUM="no" ## Report: ps # USEPS - Generates logs from "ps" # Options can be modified in OTPS_PS # Example, to disable: USEPS="no" #USEPS="yes" ## Report: pstree # USEPSTREE - Generates logs from pstree # Options can be modified in OTPS_PSTREE # Example, to enable: USEPSTREE="yes" #USEPSTREE="no" ## Report: resources # USERESOURCES - Generates "resources"(uptime, free, vmstat, iostat, iotop) log # Required by: USEDF, USESLAB, USESAR, USESARQ, USESARR # Example, to disable: USERESOURCES="no" #USERESOURCES="yes" # USEDF - Generates logs from df # requires: USERESOURCES # Options can be modified in OPTS_DF # Example, to disable: USEDF="no" #USEDF="yes" # USESLAB - Generates logs from the slab table. # requires: USERESOURCES # Example, to enable: USESLAB="yes" #USESLAB="no" # USERSAR - Generates logs from sar. # requires: USERESOURCES # Example, to disable: USESAR="no" #USESAR="yes" # USESARQ - Generates logs from "sar -q" (logs queue length, load data) # requires: USERESOURCES # Example, to enable: USESARQ="yes" #USESARQ="no" # USESARR - Generates logs from"sar -r" (logs memory data) # requires: USERESOURCES # Example, to enable: USESARR="yes" #USESARR="no" # USEPLUGINS - Enables the use of plugins, loaded from LIBDIR/plugins-enabled # Example, to enable: USEPLUGINS="yes" #USEPLUGINS="no" ### Options used by the tools generating the reports # DOTMYDOTCNF - Defines the path(s) to the mysql client configuration file # uses a comma separated list of config files. No need to define any path # for plesk, automatically will attempt to use plesk db config file if found. # NOTE: Spaces in filenames are not supported. # Required by: USEMYSQL, USEMYSQLPROCESSLIST, USEINNODB # Example: DOTMYDOTCNF="/root/.my_alternative.cnf,/root/.my_second.cnf" #DOTMYDOTCNF="/root/.my.cnf" # MYSQL_PROCESS_LIST - Format to display MySQL process list, options are # "table" or "vertical". This requires that USEMYSQLPROCESSLIST be set # "yes". # Required by: USEMYSQLPROCESSLIST # Example, generate vertical output: MYSQL_PROCESS_LIST="vertical" #MYSQL_PROCESS_LIST="table" # OPTS_DF - df options # Required by: USEDF # Example: OPTS_DF="-PhT -x nfs" #OPTS_DF="-x nfs" # OPTS_FDISK - Option used by USEFDISK. # Required by: USEFDISK # Example: OPTS_FDISK="-o gpt -l" #OPTS_FDISK="-l" # OPTS_FREE - free options # Required by: USEFREE # Example: OPTS_FREE="-lwt" #OPTS_FREE="" # OPTS_IOSTAT - iostat options # Required by: USERESOURCES # used by "iostat" # Example: OPTS_IOSTAT="-Ntx 3 3" #OPTS_IOSTAT="-t -x 1 3" # OPTS_IOTOP - iotop options # Required by: USERESOURCES # used by "iotop" # Example: OPTS_IOTOP="-botqn3 -d3" #OPTS_IOTOP="-b -o -t -n 3" # OPTS_NETSTAT - ss options # Required by: USENETSTAT # Example: OPTS_NETSTAT="-atunompie" #OPTS_NETSTAT="-atunp" # OPTS_NETSTAT_SUM - nstat options # Required by: USENETSTATSUM # Example: OPTS_NETSTAT_SUM="-z" #OPTS_NETSTAT_SUM="-a" # OPTS_PS - ps options # Required by: USEPS # Example: OPTS_PS="-Laef" #OPTS_PS="auxfww" # OPTS_PSTREE - pstree options # Required by: USEPSTREE # Example: OPTS_PSTREE="-cApu" #OPTS_PSTREE="-p" # OPTS_VMSTAT - vmstat options # Required by: USERESOURCES # used by "vmstat" # Example: OPTS_VMSTAT="-aSM 3 3" #OPTS_VMSTAT="-S M 1 3" recap-2.0.2/src/recap.conf.5000066400000000000000000000155341343607135600155200ustar00rootroot00000000000000.\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 51 Franklin Street, Fifth Floor, .\" Boston, MA 02110-1301 USA. .\" .TH RECAP.CONF 5 "July 7, 2017" .SH NAME recap.conf \- recap configuration file .SH DESCRIPTION The .IR /etc/recap.conf file contains configuration information for recap. It stores the default values that determine which reports get generated and how many reports are generated. The output files from the script are written to .IR BASEDIR "." .SH OPTIONS .LP .IP \fBBASEDIR\fR .br Directory where recap logs will be written, if defined is used by recaplog and recaptool. (default: /var/log/recap) .IP \fBMAILTO\fR .br Define this variable if you would like the reports to be sent via email .IP \fBMIN_FREE_SPACE\fR .br The minimum free disk space (in MB) required in ${BASEDIR} to run recap. (Disabled by default) (default: 0) .PP REPORTS .RS 4 .IP \fBUSEFDISK\fR .br Can be set to yes or no to enable or not "fdisk ${OPTS_FDISK}. This output is written in .IR ${BASEDIR}/fdisk.log (default: no) .IP \fBUSEPS\fR .br Can be set to yes or no to enable or disable the ps.log. (default: yes) .IP \fBUSERESOURCES\fR .br Can be set to yes or no to enable or disable the resources.log. (default: yes) .IP \fBUSEDF\fR .br Can be set to yes or no depending on whether or not "df ${OPTS_DF}" output should be stored in the report output. This requires that USERESOURCES be set to yes. (default: yes) .IP \fBUSESLAB\fR .br Can be set to yes or no depending on whether or not the slab counters should be stored in the report output. This requires that USERESOURCES be set to yes. (default: no) .IP \fBUSESAR\fR .br Can be set to yes or no depending on whether or not "sar" output should be stored in the report output. This requires that USERESOURCES be set to yes. (default: yes) .IP \fBUSESARQ\fR .br Can be set to yes or no depending on whether or not "sar \-q"(Queue length, load) output should be stored in the report output. This requires that USERESOURCES be set to yes. (default: no) .IP \fBUSESARR\fR .br Can be set to yes or no depending on whether or not "sar \-r"(memory data) output should be stored in the report output. This requires that USERESOURCES be set to yes. (default: no) .IP \fBUSEFULLSTATUS\fR .br Can be set to yes or no depending on whether or not a http request(GET) to OPTS_STATUSURL is required, it requires that the webserver url(OPTS_STATUSURL) is configured to respond to this request. Nginx(nginx_status) and Apache HTTPD(server\-status) offer a functionality to provide the status of the webserver via URL. This requires that USERESOURCES be set to yes. (default: no) .IP \fBUSEPSTREE\fR .br Can be set to yes or no depending on whether or not the output of the "pstree" command should be recorded. Makes use of OPTS_PSTREE to modify its options. Please note that this output is written to a separate file in .IR ${BASEDIR}/pstree.log (default: no) .IP \fBUSENETSTAT\fR .br Can be set to yes or no depending on whether or not the output of "ss ${OPTS_NETSTAT}" command should be recorded. Please note that this output is written to a separate file in .IR ${BASEDIR}/netstat.log is required by USENETSTATSUM. (default: yes) .IP \fBUSENETSTATSUM\fR .br Can be set to yes or no depending on whether or not the output of "nstat ${OPTS_NETSTAT_SUM}" command should be recorded. This report requires that USENETSTAT be set to "yes". This output is written in .IR ${BASEDIR}/netstat.log (default: no) .IP \fBUSEMYSQL\fR .br Can be set to yes or no depending on whether or not the output of "mysqladmin status" command should be recorded. Before enabling this option, please make sure that DOTMYDOTCNF points to the file that has appropriate credentials for accessing MySQL. Please note that this output is written to a separate file in .IR ${BASEDIR}/mysql.log (default: no) .IP \fBUSEMYSQLPROCESSLIST\fR .br Can be set to yes or no depending on whether or not the output of "mysqladmin processlist" command should be recorded. This report requires that USEMYSQL be set to "yes". This option makes use of MYSQL_PROCESS_LIST, to produce the output vertical or in a table. This output is written in .IR ${BASEDIR}/mysql.log (default: no) .IP \fBUSEINNODB\fR .br Can be set to yes or no depending on whether or not the output of "mysql show engine innodb status" and other variables(pid_files, tmpdir) command should be recorded. This report requires that USEMYSQL be set to "yes". This output is written in .IR ${BASEDIR}/mysql.log (default: no) .PP COMMAND OPTIONS .RS 4 Options used by the tools generating the reports .IP \fBDOTMYDOTCNF\fR .br Option required by USEMYSQL, USEMYSQLPROCESSLIST, USEINNODB, defines the path to the mysql client configuration file. (default: "/root/.my.cnf") .IP \fBMYSQL_PROCESS_LIST\fR .br Format to display MySQL process list, options are "table" or "vertical". This requires that USEMYSQLPROCESSLIST be set "yes". (default: table). .IP \fBOPTS_LINKS\fR .br Options used by links, when using USEFULLSTATUS (default: '\-dump') .IP \fBOPTS_DF\fR .br df options (default: '\-x nfs') .IP \fBOPTS_FDISK\fR .br Option used by USEFDISK. (default: "\-l") .IP \fBOPTS_FREE\fR .br free options (default: "") .IP \fBOPTS_IOSTAT\fR .br iostat options (default: "\-t \-x 1 3" ) .IP \fBOPTS_IOTOP\fR .br iotop options (default: "\-b \-o \-t \-n 3") .IP \fBOPTS_NETSTAT\fR .br ss options (default: "\-atunp") .IP \fBOPTS_NETSTAT_SUM\fR .br nstat statistics options (default: "\-a") .IP \fBOPTS_PS\fR .br ps options (default: "auxfww") .IP \fBOPTS_PSTREE\fR .br pstree options (default: "\-p") .IP \fBOPTS_STATUSURL\fR .br URL to perform the http request when USEFULLSTATUS is enabled. (default: "http://localhost:80/server\-status") .IP \fBOPTS_VMSTAT\fR .br vmstat options (default: "\-S M 1 3") .SH "REPORTING BUGS" Bugs and issues to be submitted via github . .SH AUTHOR The recap scripts are maintained by Rackspace, the list of contributors is available at https://github.com/rackerlabs/recap/blob/master/CHANGELOG.md#contributors. .SH "SEE ALSO" .BR recap (8), .BR recaplog (8), .BR crontab (5) .BR systemd.timer (5) recap-2.0.2/src/recaplog000077500000000000000000000225661343607135600151410ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # #~ Usage: _tool_ [OPTIONS] #~ Options: #~ -h, --help Print this help. #~ -n, --dry-run Dry run. #~ -v, --verbose Verbose. #~ -V, --version Print version and exit. #~ #~ recaplog will not produce output if no tty is found, this is useful when #~ running from cron. #~ ## Version declare -r _VERSION='2.0.2' ## Default settings PATH=/bin:/usr/bin:/sbin:/usr/sbin BASEDIR="/var/log/recap" LOCKFILE="/var/lock/recaplog.lock" LOG_COMPRESS=1 LOG_EXPIRY=15 LOGFILE="${BASEDIR}/recaplog.log" # Usage Function print_usage() { grep -E '^#~' "${0}" | sed -e 's/^#~\s\?//' -e "s/_tool_/$( basename ${0} )/" } # Function to generate timestamps ts() { TS_FLAGS='--rfc-3339=seconds' date "${TS_FLAGS}" } # Function to log messages log() { # does not work in a while-loop as spawns a new shell local msg_type=$1 shift local log_entry="$*" ## This avoids sending any output to stdout when executed through cron ## is helpful to avoid emails submitted, instead the logs contain the ## possible ERRORS if ! tty -s; then echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 >> "${LOGFILE}" return 0 fi if [[ "${VERBOSE}" ]]; then echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 | tee -a "${LOGFILE}" return 0 fi if [[ "${msg_type}" =~ "ERROR" || "${msg_type}" =~ "WARNING" ]]; then echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 | tee -a "${LOGFILE}" else echo "$( ts ) [${msg_type}] ${log_entry}" 2>&1 >> "${LOGFILE}" fi } # Function to delete log files older than LOG_EXPIRY days delete_old_logs() { local matched_files='' local empty_dirs='' local count_files=0 local count_dirs=0 if [[ "${LOG_EXPIRY}" -eq 0 ]]; then log INFO "Skipping old log file expiration..." return 0 fi # Proceed with deletion of old logs log INFO "Deleting log files older than ${LOG_EXPIRY} days..." # Matching files and empty directories if any. # Using now posix-extended regex flavor to ease the matching of logs, gzips # or tarballs matched_files=$( find "${BASEDIR}" -maxdepth 2 -regextype posix-extended \ -type f -mtime +${LOG_EXPIRY} -regex \ "^${BASEDIR}/(.*/)?[a-z]+_([a-z]+_)*[0-9]{8}(-[0-9]{6})?\.log(\.tar)?(\.gz)?$" ) if [[ -n "${matched_files}" ]]; then count_files=$( wc -l <<<"${matched_files}" ) fi # If dry run, log and return if [[ "${DRYRUN}" ]]; then log INFO "Would delete: ${count_files} log files." return 0 else log INFO "Deleting: ${count_files} log files." fi # Deleting old logs, compressed/tarballs and empty dirs if any if [[ "${count_files}" -gt 0 ]]; then while read matched_file; do rm -f "${matched_file}" done <<< "${matched_files}" fi # Deleting empty dirs generated by recaplog when no compressing logs. empty_dirs=$( find "${BASEDIR}" -maxdepth 1 -regextype posix-extended \ -regex "^${BASEDIR}/[a-z]+_[a-z]+_[0-9]{8}$" -empty \ -type d ) if [[ -n "${empty_dirs}" ]]; then count_dirs=$( wc -l <<<"${empty_dirs}" ) fi log INFO "Deleting: ${count_dirs} empty directories." if [[ "${count_dirs}" -gt 0 ]]; then while read empty_dir; do rmdir "${empty_dir}" done <<< "${empty_dirs}" fi } # Generates a list of names from a date with the format "YYYYMMDD" declare -a reports=() get_report_names_of_day() { local day="$1" log INFO "Finding reports from: ${day}" reports=( $( ls -1 "${BASEDIR}" 2>/dev/null | awk -F. \ ' /'${day}'-[0-9]{6}\.log$/ {sub("_'${day}'-[0-9]{6}","",$1); print $1} ' | sort -u ) ) log INFO "Reports found: [ ${reports[@]} ]" } # Function to compress/move daily log files # Previously the logs were concatenated and could be compressed, that is a # problem for parsing them at a later time as reported in: # https://github.com/rackerlabs/recap/pull/28 # The new behaviour is to move the log files to a directory then opt for # compression, if compressed then it will delete the original logs. pack_old_logs() { local -a errors local YESTERDAYDATE=$( date -d "now -1 day" "+%Y%m%d" ) if [[ "${LOG_COMPRESS}" -eq 1 ]]; then log INFO "Compressing old log files" else log INFO "Not compressing old log files" fi # Backing up only items found in the YESTERDAYDATE get_report_names_of_day "${YESTERDAYDATE}" local -a items=${reports[@]} if [[ -z ${items} ]]; then log ERROR "Unable to archive unexisting reports." return 0 fi for item in ${items[@]}; do YESTERDAY_ITEM_DIR="${BASEDIR}/${item}_daily_${YESTERDAYDATE}" err='' log INFO "Packing ${item}..." # Finding logs for item from yesterday date. output=$( ls -1 "${BASEDIR}/${item}_${YESTERDAYDATE}"-*.log 2>&1 ) if [[ $? -ne 0 ]]; then output=$( tr -d '\n' <<< "${output}" ) log ERROR "An error occurred while reading logs: '${output}', skipping..." continue fi log_count=$( wc -l <<< "${output}" ) # Moving logs to yesterday item's directory if [[ "${DRYRUN}" ]]; then log INFO "Would move ${log_count} logs to: ${YESTERDAY_ITEM_DIR}" else log INFO "Moving ${log_count} logs to: ${YESTERDAY_ITEM_DIR}" err=$( { mkdir -p "${YESTERDAY_ITEM_DIR}"; mv "${BASEDIR}/${item}_${YESTERDAYDATE}"-*.log \ "${YESTERDAY_ITEM_DIR}"; } 2>&1 ) err=$( tr -d '\n' <<< "${err}" ) if [[ ! -z "${err}" ]]; then log ERROR "An error occurred while attempting to move logs: '${err}', "\ "skipping..." continue fi fi # Compressing logs # Move to the next loop if compress is not enabled if [[ "${LOG_COMPRESS}" -ne 1 ]]; then continue fi OUTPUTFILE="${YESTERDAY_ITEM_DIR}.log.tar.gz" if [[ "${DRYRUN}" ]]; then log INFO "Would compress ${log_count} logs into: ${OUTPUTFILE}" continue fi # Compressing logs when enabled log INFO "Compressing ${log_count} logs into: ${OUTPUTFILE}" err=$( { tar czf "${OUTPUTFILE}" \ "${YESTERDAY_ITEM_DIR}"/*.log 2>/dev/null && touch -t ${YESTERDAYDATE}0000 "${OUTPUTFILE}"; } 2>&1 ) err=$(tr -d '\n' <<< "${err}" ) if [[ ! -z "${err}" ]]; then log ERROR "An error occurred while attempting to compress logs: '${err}'"\ ", skipping..." continue fi log INFO "Deleting ${log_count} logs." rm_err=$( { rm -Rf "${YESTERDAY_ITEM_DIR}"; } 2>&1 >/dev/null ) rm_err=$( tr -d '\n' <<< "${rm_err}" ) if [[ ! -z "${rm_err}" ]]; then log ERROR "An error occurred while deleting logs '${rm_err}', skipping..." fi done } # Cleanup function to remove lock cleanup() { log INFO "$( basename $0 ) ($$): Caught signal - deleting ${LOCKFILE}" rm -f "${LOCKFILE}" log INFO "${banner_end}" } # Create a Lock so that recaplog does not try to run over itself. recaploglock() { (set -C; echo "$$" > "${LOCKFILE}") 2>/dev/null if [[ $? -ne 0 ]]; then log ERROR "$( basename $0 ) ($$): Lock File exists - exiting" exit 1 else trap 'exit 2' 1 2 15 17 23 trap 'cleanup' EXIT log INFO "$( basename $0 ) ($$): Created lock file: ${LOCKFILE}" fi } # Set options OPTIONS=hnvV LONG_OPTIONS=help,dry-run,verbose,version # Parse options and show usage if invalid options provided ! ALL_ARGS=$(getopt --options=${OPTIONS} --longoptions=${LONG_OPTIONS} --name "$0" -- "$@") if [[ ${PIPESTATUS[0]} -ne 0 ]]; then print_usage exit 1 fi # Set the positional parameters to the parsed options eval set -- "${ALL_ARGS}" # Avoid external variables to be defined unset VERBOSE unset DRYRUN while [[ ${#} -gt 0 ]]; do case "${1}" in -n|--dry-run) DRYRUN=true VERBOSE=true shift ;; -v|--verbose) VERBOSE=true shift ;; -V|--version) echo "${_VERSION}" exit 0 ;; -h|--help) print_usage exit 1 ;; --) shift; break ;; esac done # Verify running as root if [[ "$( id -u )" != "0" ]]; then echo "This script must be run as root." >&2 exit 1 fi # Define the headers for the run if [[ "${DRYRUN}" ]]; then banner_start="--- Starting $( basename $0 )[$$] (dry-run) ---" banner_end="--- Ending $( basename $0 )[$$] (dry-run) ---" else banner_start="--- Starting $( basename $0 )[$$] ---" banner_end="--- Ending $( basename $0 )[$$] ---" fi # Start logging log INFO "${banner_start}" # Check for the configuration file. if [[ ! -r /etc/recap.conf ]]; then log WARNING "No configuration file found. Expecting /etc/recap.conf." log WARNING "Proceeding with defaults." else source /etc/recap.conf fi # Acquire lock recaploglock # recap the logs pack_old_logs delete_old_logs exit 0 recap-2.0.2/src/recaplog.8000066400000000000000000000047741343607135600153050ustar00rootroot00000000000000.\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 51 Franklin Street, Fifth Floor, .\" Boston, MA 02110-1301 USA. .\" .TH "RECAPLOG" "8" "Aug 18, 2017" .SH NAME .PP recaplog \- Handles the logs generated by recap; compressing and/or deleting log files. .SH SYNOPSIS .BR "recaptool " "[\-n|\-v|\-h|\-V]" .SH DESCRIPTION recaplog is a user\-configurable script that runs periodically out of cron or systemd.timer to compress recap log files older than one day, and delete log files older than a configurable amount of days, recaplog will not produce output if a tty is not found, this is useful when running from cron. .SH OPTIONS .TP .BR "\-h, \-\-help" .BR "" "Print out the help." .TP .BR "\-n, \-\-dry\-run" .BR "" "Performs a dry run, implies verbose." .TP .BR "\-v, \-\-verbose" .BR "" "Prints to stdout." .TP .BR "\-V, \-\-version" .BR "" "Print version and exit." .SH SETTINGS These can be modified via the config file. .TP .BI LOG_COMPRESS .BR "" "Enables(1) or disables(0) log compression." .BR "(default: 1)" .TP .BI LOG_EXPIRY .BR "" "Number of days held for the logs." .BR "(default: 15)" .SH FILES .nf /etc/recap.conf \- The configuration file. /etc/cront.d/recap \- The cronjob file. /usr/lib/systemd/systemd/recaplog.{service,timer} \- Unit files for recaplog. /var/log/recap/recaplog.log \- The recaplog file. .SH "REPORTING BUGS" Bugs and issues to be submitted via github . .SH AUTHOR The recap scripts are maintained by Rackspace, the list of contributors is available at https://github.com/rackerlabs/recap/blob/master/CHANGELOG.md#contributors. .SH "SEE ALSO" .BR recap.conf (5), .BR recap (8), .BR crontab (5), .BR systemd.timer (5) recap-2.0.2/src/recaptool000077500000000000000000000122511343607135600153230ustar00rootroot00000000000000#!/bin/bash # # Copyright (C) 2017 Rackspace, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # #~ Usage: _tool_ OPTIONS #~ Options: #~ -c, --connections PORT Show all network connections of a PORT. #~ -e, --established PORT Show only established network connections of a PORT. #~ -d, --path PATH Specify the recap log PATH. #~ -m, --mem PROCESS_NAME Show mem info of PROCESS_NAME. #~ -p, --proc PROCESS_NAME Show proc info of PROCESS_NAME. #~ -b, --memproc PROCESS_NAME Show both mem and proc info of PROCESS_NAME. #~ -q, --querycount Show mysql connections. #~ -h, --help Print this help. #~ -V, --version Print version and exit. #~ ## Version declare -r _VERSION='2.0.2' ## Default settings BASEDIR="/var/log/recap" cmds="" CONFFILE="/etc/recap.conf" ## Overriding defaults if [[ -r "${CONFFILE}" ]]; then source "${CONFFILE}" fi memproc() { PROCESS="${@}" TMP=$( mktemp ) >"${TMP}" for i in $( ls "${BASEDIR}"/ps_*.log ); do head -n 1 "${i}" | tr "\n" "\t" >> "${TMP}" egrep "${PROCESS}" "${i}" -c | tr "\n" "\t" >> "${TMP}" egrep "${PROCESS}" "${i}" | awk '{ SUM += $6 } END {print SUM/1024, "M"};' >> "${TMP}" done sort "${TMP}" rm -f "${TMP}" } proc() { PROCESS="${@}" TMP=$( mktemp ) >"${TMP}" for i in $( ls "${BASEDIR}"/ps_*.log ); do head -n 1 "${i}" | tr "\n" "\t" >> "${TMP}" egrep "${PROCESS}" "${i}" -c >> "${TMP}" done sort "${TMP}" rm -f "${TMP}" } mem() { PROCESS="${@}" TMP=$( mktemp ) >"${TMP}" for i in $( ls "${BASEDIR}"/ps_*.log ); do head -n 1 "${i}" | tr "\n" "\t" >> "${TMP}" egrep "${PROCESS}" "${i}" | awk '{ SUM += $6 } END {print SUM/1024, "M"};' >> "${TMP}" done sort "${TMP}" rm -f "${TMP}" } connections() { PORT="${@}" TMP=$( mktemp ) >"${TMP}" for i in $( ls "${BASEDIR}"/netstat_*.log ); do head -n 1 "${i}" | tr "\n" "\t" >> "${TMP}" egrep -c ":${PORT} " "${i}" >> "${TMP}" done sort "${TMP}" rm -f "${TMP}" } established() { PORT="${@}" TMP=$( mktemp ) >"${TMP}" for i in $( ls "${BASEDIR}"/netstat_*.log ); do head -n 1 "${i}" | tr "\n" "\t" >> "${TMP}" egrep -c "ESTAB .*:${PORT} " "${i}" >> "${TMP}" done sort "${TMP}" rm -f "${TMP}" } querycount() { TMP=$( mktemp ) >"${TMP}" for i in $( ls "${BASEDIR}"/mysql_*.log ); do head -n 1 "${i}" | tr "\n" "\t" >> "${TMP}" grep "Query" -c "${i}" >> "${TMP}" done sort "${TMP}" rm -f "${TMP}" } print_usage() { echo grep -E '^#~' "${0}" | sed -e 's/^#~\s\?//' \ -e "s/_tool_/$( basename ${0} )/" } # Set options OPTIONS=Vc:d:e:m:p:b:qh LONG_OPTIONS=version,connections:,path:,established:,mem:,proc:,memproc:,querycount,help # Parse options and show usage if invalid options provided ! ALL_ARGS=$(getopt --options=${OPTIONS} --longoptions=${LONG_OPTIONS} --name "$0" -- "$@") if [[ ${PIPESTATUS[0]} -ne 0 ]]; then print_usage exit 1 fi # Set the positional parameters to the parsed options eval set -- "${ALL_ARGS}" # Create an array to store commands to be executed declare -a CMDS # Act on the valid arguments provided while [[ ${#} -gt 0 ]]; do case "${1}" in -V|--version) echo "${_VERSION}" exit 0 ;; -c|--connections) PORT=${2} shift 2 CMDS+=("connections ${PORT}") ;; -e|--established) PORT=${2} shift 2 CMDS+=("established ${PORT}") ;; -d|--path) DIR=true if [[ -d "${2}" ]]; then BASEDIR="${2}" shift 2 else echo "Error: ${2} is not a valid directory." print_usage exit 1 fi ;; -m|--mem) PROCESS_NAME="${2}" shift 2 CMDS+=("mem ${PROCESS_NAME}") ;; -p|--proc) PROCESS_NAME="${2}" shift 2 CMDS+=("proc ${PROCESS_NAME}") ;; -b|--memproc) PROCESS_NAME="${2}" shift 2 CMDS+=("memproc ${PROCESS_NAME}") ;; -q|--querycount) CMDS+=(querycount) shift ;; -h|--help) print_usage exit 0 ;; --) shift; break ;; esac done if [[ ${#CMDS[@]} -eq 0 ]]; then msg="Error: Please supply more arguments." [[ $DIR ]] && msg="${msg} The 'path' option is not enough." echo "${msg}" print_usage exit 1 fi echo "Information: Using ${BASEDIR} as recap log path" for cmd in "${CMDS[@]}"; do echo "Information: Executing ${cmd}" eval ${cmd} echo done exit 0 recap-2.0.2/src/recaptool.8000066400000000000000000000104121343607135600154630ustar00rootroot00000000000000.\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 51 Franklin Street, Fifth Floor, .\" Boston, MA 02110-1301 USA. .\" .TH "RECAPTOOL" "8" "Aug 18, 2017" .SH NAME .PP recaptool \- parses the logs and prints specific information about memory, processes, network connections or queries to a mysql db. .SH SYNOPSIS .BR "recaptool " "OPTIONS... " .SH DESCRIPTION recaptool is a parsing tool for recap logs that shows specific information like processes, memory, network or querycount. Useful for seeing trends on a particular option in the logs. .SH "OPTIONS" Note: Different options can be combined to get more information. .TP .BI "\-m, \-\-mem " "PROCESS_NAME" .RI "Shows the memory consumption for " "PROCESS_NAME" " from the logs." .TP .BI "\-p, \-\-proc " "PROCESS_NAME" .RI "Shows the amount of processes found for " "PROCESS_NAME" " from the logs." .TP .BI "\-b, \-\-memproc " "PROCESS_NAME" .RI "Shows both process count and memory consumption for " "PROCESS_NAME" " from the logs." .TP .BI "\-c, \-\-connections " "PORT" .RI "Shows the amount of connections to " "PORT" " from the logs." .TP .BI "\-e, \-\-established " "PORT" .RB "Shows the amount of " "ESTABLISHED" " connections to " .IR "PORT" " from the logs." .TP .BI "\-q, \-\-querycount" .RB "Shows the amount of " "mysql" " connections from the logs." .TP .BI "\-d, \-\-path " "PATH" .RB "Overrides the recap log " "PATH" ". Default uses BASEDIR" .I /var/log/recap/ .RB "(can be changed in config file)." .TP .BI "\-V, \-\-version" .RB "Print version and exit." .TP .BI "\-h, \-\-help" .RB "Prints the help information and exit." .SH FILES .IR /var/log/recap/*.log " (unless overridden by 'path' option)" .SH EXAMPLES .TP Show the memory and amount of processes running for httpd: .nf $ sudo recaptool \-\-memproc http Information: Using /var/log/recap as recap log path Information: Executing memproc http 2016\-10\-07_00:00:01 1101 3032.535 M 2016\-10\-07_00:10:01 1120 3132.832 M 2016\-10\-07_00:20:01 1128 3186.153 M .fi .TP .RB "Show the amount of " "established " "connections on port 443:" .nf $ sudo recaptool \-e 443 Information: Using /var/log/recap as recap log path Information: Executing established 443 2016\-10\-07_00:00:01 302 2016\-10\-07_00:10:01 311 2016\-10\-07_00:20:01 312 .fi .TP Show the amount of query connections to the mysql db: .nf $ sudo recaptool \-\-querycount Information: Using /var/log/recap as recap log path Information: Executing querycount 2016\-10\-07_00:00:01 124 2016\-10\-07_00:10:01 125 2016\-10\-07_00:20:01 128 .fi .TP Show all of the above in a single command: .nf $ sudo recaptool \-\-memproc http \-e 443 \-\-querycount Information: Using /var/log/recap as recap log path Information: Executing memproc http 2016\-10\-07_00:00:01 1101 3032.535 M 2016\-10\-07_00:10:01 1120 3132.832 M 2016\-10\-07_00:20:01 1128 3186.153 M Information: Executing established 443 2016\-10\-07_00:00:01 302 2016\-10\-07_00:10:01 311 2016\-10\-07_00:20:01 312 Information: Executing querycount 2016\-10\-07_00:00:01 124 2016\-10\-07_00:10:01 125 2016\-10\-07_00:20:01 128 .fi .SH "REPORTING BUGS" Bugs and issues to be submitted via github . .SH AUTHOR The recap scripts are maintained by Rackspace, the list of contributors is available at https://github.com/rackerlabs/recap/blob/master/CHANGELOG.md#contributors. .SH "SEE ALSO" .BR recap.conf (5), .BR recap (8), recap-2.0.2/src/utils/000077500000000000000000000000001343607135600145445ustar00rootroot00000000000000recap-2.0.2/src/utils/recap-onboot.service.in000066400000000000000000000003521343607135600211230ustar00rootroot00000000000000[Unit] Description=recap on boot Documentation=man:recap.conf(5) man:recap(8) After=network-online.target Wants=network-online.target [Service] Environment=BINDIR=/usr/local/bin Type=oneshot ExecStart=/bin/sh -c "${BINDIR}/recap -B" recap-2.0.2/src/utils/recap-onboot.timer000066400000000000000000000001431343607135600201740ustar00rootroot00000000000000[Unit] Description=Timer for recap-onboot [Timer] OnBootSec=10s [Install] WantedBy=timers.target recap-2.0.2/src/utils/recap.cron.in000066400000000000000000000017041343607135600171300ustar00rootroot00000000000000#The next 2 lines will make a backup copy of the log files at reboot for crash diagnosis #uncomment for the files you want saved BINDIR=/usr/local/bin # runs at boot, backup the last set of reports generated prior to a reboot @reboot root timeout 5m "${BINDIR}"/recap -B #The following are examples of times to run recap #This file should be in /etc/cron.d #Only uncomment or create one active line per installation #At 2am every day #0 2 * * * root timeout 5m "${BINDIR}"/recap #At 2am and 2pm every day #0 2,14 * * * root timeout 5m "${BINDIR}"/recap #At 2am, 8am, 2pm, 8pm every day #0 2,8,14,20 * * * root timeout 5m "${BINDIR}"/recap #Every hour #0 * * * * root timeout 5m "${BINDIR}"/recap #Every 30 minutes #*/30 * * * * root timeout 5m "${BINDIR}"/recap #Every 10 minutes */10 * * * * root timeout 5m "${BINDIR}"/recap #Every 5 minutes #*/5 * * * * root timeout 4m "${BINDIR}"/recap # Pack and clear log files 0 1 * * * root "${BINDIR}"/recaplog recap-2.0.2/src/utils/recap.service.in000066400000000000000000000003371343607135600176300ustar00rootroot00000000000000[Unit] Description=recap Documentation=man:recap.conf(5) man:recap(8) After=network-online.target Wants=network-online.target [Service] Environment=BINDIR=/usr/local/bin Type=oneshot ExecStart=/bin/sh -c "${BINDIR}/recap" recap-2.0.2/src/utils/recap.timer000066400000000000000000000001721343607135600167000ustar00rootroot00000000000000[Unit] Description=Timer for recap [Timer] OnCalendar=*-*-* *:00/10:00 Persistent=true [Install] WantedBy=timers.target recap-2.0.2/src/utils/recaplog.service.in000066400000000000000000000003261343607135600203300ustar00rootroot00000000000000[Unit] Description=recaplog Documentation=man:recaplog(8) After=network-online.target Wants=network-online.target [Service] Environment=BINDIR=/usr/local/bin Type=oneshot ExecStart=/bin/sh -c "${BINDIR}/recaplog" recap-2.0.2/src/utils/recaplog.timer000066400000000000000000000001731343607135600174030ustar00rootroot00000000000000[Unit] Description=Timer for recaplog [Timer] OnCalendar=*-*-* 01:00:00 Persistent=true [Install] WantedBy=timers.target recap-2.0.2/tests/000077500000000000000000000000001343607135600137575ustar00rootroot00000000000000recap-2.0.2/tests/install_deps.sh000077500000000000000000000010201343607135600167700ustar00rootroot00000000000000#!/bin/bash DISTRO="$1" packages=( "bash" "coreutils" "gawk" "grep" "iotop" "elinks" "make" "procps" "psmisc" "sysstat" ) case ${DISTRO} in centos*) packages+=("iproute") yum install ${packages[@]} -y || exit $? ;; debian*|ubuntu*) packages+=("iproute2") apt-get update apt-get install ${packages[@]} -y || exit $? ;; *) echo "Unknown distro: ${DISTRO}" exit 1 ;; esac recap-2.0.2/tests/run_recap.sh000077500000000000000000000012421343607135600162730ustar00rootroot00000000000000#!/bin/bash # Get full path to recap recap_path=$(type -p recap) # Insert 'set -e' on line 2 of recap to exit after any failure sed -i "2iset -e" "${recap_path}"; # Save debugging info and record the status of the recap run debug_info=$(bash -x "${recap_path}" 2>&1) stat=$? # Save the debugging info that occurred right before the cleanup operation cleanup_trigger=$(echo "${debug_info}" | grep -P "^\+\s+cleanup" -B 20) # Show the info that triggered the cleanup if there was an error running recap if [[ ${stat} -ne 0 ]]; then echo "An error occurred while doing the following:" echo "${cleanup_trigger}" fi # Exit with the status of the recap run exit ${stat} recap-2.0.2/tests/test_install_recap.sh000077500000000000000000000003261343607135600201760ustar00rootroot00000000000000#!/bin/bash # Switch to the bind mount to install recap cd /recap # Install recap make install # Clean temporary files make clean # Verify recap is available after installation type -p recap >/dev/null exit $? recap-2.0.2/tools/000077500000000000000000000000001343607135600137555ustar00rootroot00000000000000recap-2.0.2/tools/ansible_recap.yml000066400000000000000000000074421343607135600172760ustar00rootroot00000000000000--- - name: Install recap from repo hosts: all become: "yes" vars: repo: https://github.com/rackerlabs/recap.git ref: master binpath: "/sbin" destdir: "" prefix: "/usr" tmp_install_dir: /tmp/recap install_deps: - git - make systemd_unit_dir: "{{ destdir }}/usr/lib/systemd/system" enable_plugins: "no" plugin_list: - all tasks: - name: Set dependencies and timers set_fact: dependencies: - bash - coreutils - gawk - grep - iotop - "iproute{{'2' if ansible_os_family is match('Debian|Archlinux') else ''}}" - elinks - "{{ 'procps-ng' if ansible_os_family is match('Archlinux') else 'procps' }}" - psmisc - sysstat timers: - recap.timer - recaplog.timer - recap-onboot.timer - name: Install package and build dependencies package: name: "{{ dependencies + install_deps }}" state: present update_cache: "yes" when: uninstall is undefined - name: Clone the repo git: repo: "{{ repo }}" version: "{{ ref }}" dest: "{{ tmp_install_dir }}" - name: Installation block: - name: Install recap make: chdir: "{{ tmp_install_dir }}" target: install params: BINPATH: "{{ binpath }}" DESTDIR: "{{ destdir }}" PREFIX: "{{ prefix }}" - name: Enabling plugins block: - name: Finding all plugins available block: - name: Find all plugins find: paths: "{{ prefix }}/lib/recap/plugins-available" register: plugins_found - name: Create plugin list with all plugins found set_fact: plugin_list: "{{ plugin_list + [ item.path | basename ] }}" with_items: "{{ plugins_found.files }}" when: plugins_found.matched - name: Remove "all" from list set_fact: plugin_list: "{{ plugin_list | difference(['all']) }}" when: "'all' in plugin_list" - name: enable plugins in global config lineinfile: path: /etc/recap.conf insertafter: '#USEPLUGINS="no"' line: 'USEPLUGINS="yes"' state: present - name: enable list of plugins file: dest: "{{ prefix }}/lib/recap/plugins-enabled/{{ item }}" src: "{{ prefix }}/lib/recap/plugins-available/{{ item }}" state: link with_items: "{{ plugin_list }}" when: enable_plugins - name: Enable systemd timers systemd: name: "{{ item }}" enabled: "yes" state: started daemon_reload: "yes" with_items: "{{ timers }}" when: ansible_service_mgr == 'systemd' - name: Run manually recap shell: recap - name: Get recap version shell: recap --version register: recap_version - name: Print recap version debug: var: recap_version.stdout_lines[0] when: uninstall is undefined - name: Uninstall block: - name: Look for the timer units stat: path: "{{ systemd_unit_dir }}/{{ item }}" register: timer_units with_items: "{{ timers }}" when: ansible_service_mgr == 'systemd' - name: Disable systemd timers systemd: name: "{{ item.item }}" state: stopped enabled: "no" with_items: "{{ timer_units.results }}" when: > ansible_service_mgr == 'systemd' and item.stat.exists - name: Uninstall recap make: chdir: "{{ tmp_install_dir }}" target: uninstall params: DESTDIR: "{{ destdir }}" PREFIX: "{{ prefix }}" notify: Reload systemd when: uninstall is defined handlers: - name: Reload systemd systemd: daemon_reload: "yes" ...