https://github.com/amandasaurus/systemautopsy
Take a quick system snapshot for later debugging
https://github.com/amandasaurus/systemautopsy
Last synced: 5 months ago
JSON representation
Take a quick system snapshot for later debugging
- Host: GitHub
- URL: https://github.com/amandasaurus/systemautopsy
- Owner: amandasaurus
- License: gpl-3.0
- Created: 2012-01-04T11:52:43.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2014-02-08T18:00:08.000Z (almost 12 years ago)
- Last Synced: 2025-04-11T06:29:19.416Z (8 months ago)
- Language: Python
- Homepage:
- Size: 179 KB
- Stars: 14
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SystemAutopsy is a programme to take a quick snapshot of what your Linux system
is doing and save that to a file for later examination.
If a server has a problem, one often has to try to figure out what's going on
*and* also also get it back running. Sometimes one don't have the time to figure
out what's wrong, you have to get things works **now**. Sometimes there are easy
solutions you can do (like restart a server/service), but that means you can no
longer diagnose the problem. Additionally some problems might be intermittant
and go away soon, meaning the problem goes away.
SystemAutopsy is designed for these cases. It saves the output from various
commands to files, allowing you to pour over it later.
Quick Start Guide
-----------------
SystemAutopsy is installable with pip:
pip install SystemAutopsy
To get an autopsy of your system just run:
autopsy
This command will run and collect the default system statistics and save it in
a file in your home directory, called ``autopsy.$DATE_TIME_WHEN_RUN.tar.gz``
Configuration
-------------
What things to save is used via ``Components``. It includes some good defaults
for a LAMP server in ``system_autopsy.default_components``. You can define your
own Components in a python module file. By default SystemAutopsy will look for
a file ``system_autopsy_components.py`` in the current directory, failing that,
your home directory, or failing both of them, it'll use the default components
included with SystemAutopsy.
A simple Component looks like this:
from system_autopsy.utils import Component, bash_command
class Basics(Component):
@bash_command
def disk_usage(self):
return "df"
This defines a Component called ``Basics`` which has one output (called
``disk_usage``). The archive file will have one directory called ``basics``,
which has one file called ``disk_usage``, which will be the output from running
``df``.
Every ``bash_command`` will have its output in it's own file, with filename
based on the function name. Some tools can save output themselves (e.g.
``strace``), so you can skip the default saving, by using the
``@takes_own_filename``. Your function should take a ``filename`` argument
which will be the filename.
from system_autopsy.utils import Component, bash_command
class Basics(Component):
@bash_command
@takes_own_filename
def strace_something(self, filename):
return "strace -o %s -p 1000" % filename
Producing more than one output file
===================================
By default one function will produce one file, however sometimes you want to
run on command on many things (e.g. for each pid that matches something), this
can be done with the ``@iterate_on`` decorator. It takes one argument, a
function that will return a list of ``(arg, kwargs)`` to pass into the
function. Every element in the list will produce a new file
SystemAutopsy comes with one utility function for this ``pids_matching``, which
will return all the PIDs that match this ``pgrep`` argument. So
``pids_matching('-u mysql')`` returns all PIDS that are from the ``mysql``
user.
For example to strace (for 10 seconds) all ``mysql`` processes, you can use
this command:
from system_autopsy.utils import Component, iterate_on, pids_matching
class Basics(Component):
@iterate_on(pids_matching('-u mysql'))
def strace_mysqld(self, pid):
return "timeout 10s strace -f -p {pid}".format(pid=pid)
*(Note: since strace puts output on stderr, not stdout, you should use
@takes_own_filename here)*
Extending SystemAutopsy's default components
============================================
If you want to add some custom components that are private to you, you can just
import the ``default_components``
Put this file in ``~/system_autopsy_components.py``
from system_autopsy.default_components import *
class MySQLStatus(Component):
@bash_command
def process_list(self):
return "mysql -u root -h localhost -pMYSQLROOTPASSSWORD -e \"SHOW PROCESSLIST;\""
This allows you thave components that have sensitive data.
STDERR, exit codes & time outs
==============================
Any command that prints to stderr will be echod to you terminal and not caught.
``strace`` can be annoying and noisey like this.
The exit status of any command is irrelevant and ignored.
A command is allowed to run as long as wants, SystemAutopsy does not try to
stop them. You can use ``timeout(1)`` from ``coreutils`` to control how long
something runs for. (See the ``strace_mysqld`` example above).
Licence
-------
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 3 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, see .
It was written by Rory McCann .
[](https://bitdeli.com/free "Bitdeli Badge")