Skip to main content

Monitor and control Apache web server workers from Python

Project description

https://travis-ci.org/xolox/python-apache-manager.svg?branch=master https://coveralls.io/repos/xolox/python-apache-manager/badge.svg?branch=master

The apache-manager package helps to collect monitoring metrics about the Apache web server and kill worker processes that exceed resource thresholds. It works by parsing the plain text and HTML status pages generated by Apache’s mod_status module. It’s currently tested on cPython 2.7, 3.5, 3.6, 3.7, 3.8 and PyPy. It was developed for and expects to be run on Linux systems.

Status

On the one hand the apache-manager package was developed based on quite a few years of experience interfacing with (and monitoring) the Apache web server using the interfaces provided by Apache itself (mod_status) as well as the Linux operating system interfaces (/proc).

On the other hand the Python package itself is quite new: it was developed between June and September of 2015.

Then again, I’m religious about test coverage, so there’s that :-).

Despite the complete package being covered by automated tests I’m not (yet) committing to backwards compatibility because I first want to run this package in a production (like) environment for some time, to get a feeling for how robust it is. I also need to evaluate how easy it is to integrate the current solution into monitoring systems (that was a goal, but I don’t always achieve my goals on the first attempt :-).

Installation

The apache-manager package is available on PyPI which means installation should be as simple as:

$ pip install apache-manager

There’s actually a multitude of ways to install Python packages (e.g. the per user site-packages directory, virtual environments or just installing system wide) and I have no intention of getting into that discussion here, so if this intimidates you then read up on your options before returning to these instructions ;-).

Usage

There are two ways to use the apache-manager package: As the command line program apache-manager and as a Python API. For details about the Python API please refer to the API documentation available on Read the Docs. The command line interface is described below.

Command line

Usage: apache-manager [OPTIONS]

Command line interface to monitor the Apache web server and kill worker processes that exceed resource thresholds. When no options are given the server metrics and memory usage of workers are printed to the terminal.

Supported options:

Option

Description

-c, --collect-metrics

Collect monitoring metrics and store them in a text file to be read by a monitoring system like Zabbix. See also the --data-file option.

-k, --kill-workers

Kill Apache workers exceeding the thresholds given by --max-memory-active, --max-memory-idle and --max-time. These thresholds can also be defined in configuration files, please refer to the online documentation for details. See also the --dry-run option.

-w, --watch

This option causes the Apache manager to redraw the collected metrics once every 10 seconds in a “top” like interface until interrupted using “q” (for quite) or Control-C.

-a, --max-memory-active=SIZE

Kill active Apache workers that are using more memory than specified by the SIZE argument. SIZE is expected to be a human readable memory size like 50K (50 kilobytes), 42M (42 megabytes), 2G (2 gigabytes), etc.

-i, --max-memory-idle=SIZE

Kill Apache workers that are using more memory than specified by the SIZE argument (see --max-memory-active for acceptable values of SIZE).

-t, --max-ss, --max-time=TIMESPAN

Kill Apache workers whose “time since the beginning of the most recent request” is greater than specified by the TIMESPAN argument. TIMESPAN is expected to be a human readable timespan like 2s (2 seconds), 3m (3 minutes), 5h (5 hours), 2d (2 days), etc.

-T, --hanging-worker-threshold=TIMESPAN

Change the number of seconds before an active worker is considered hanging to TIMESPAN (see --max-time for acceptable values of TIMESPAN).

-f, --data-file=PATH

Change the pathname of the file where the Apache manager stores monitoring metrics after every run. Defaults to “/tmp/apache-manager.txt”.

-z, --zabbix-discovery

Generate a JSON fragment that’s compatible with the low-level discovery support in the Zabbix monitoring system. With the right template in place this enables the Zabbix server to discover the names of the WSGI process groups that are active on any given server. This makes it possible to collect and analyze the memory usage of specific WSGI process groups.

-n, --dry-run, --simulate

Don’t actually kill any Apache workers.

-v, --verbose

Increase verbosity (can be repeated).

-q, --quiet

Decrease verbosity (can be repeated).

-h, --help

Show this message and exit.

Contact

The latest version of apache-manager is available on PyPI and GitHub. The documentation is hosted on Read the Docs and includes a changelog. For bug reports please create an issue on GitHub. If you have questions, suggestions, etc. feel free to send me an e-mail at peter@peterodding.com.

License

This software is licensed under the MIT license.

© 2020 Peter Odding.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apache-manager-2.2.tar.gz (39.8 kB view details)

Uploaded Source

Built Distribution

apache_manager-2.2-py2.py3-none-any.whl (30.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file apache-manager-2.2.tar.gz.

File metadata

  • Download URL: apache-manager-2.2.tar.gz
  • Upload date:
  • Size: 39.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for apache-manager-2.2.tar.gz
Algorithm Hash digest
SHA256 eeeddf882704814b3eb70def6ed6081e77e33c85ccb45d9f0336ca6d7c53cdcc
MD5 e62d35ddee61ba15e25916bce54633d5
BLAKE2b-256 194a35950445e4a7566572f39a4e7280cc7c2be9947da45f0cbb1bc41e397806

See more details on using hashes here.

File details

Details for the file apache_manager-2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: apache_manager-2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for apache_manager-2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c8b0215534c83a9afc2cf9f42408169d1f43dcbc5301a75acfe2c28d0912e842
MD5 3957c48e7f559555a36995666a7fbce5
BLAKE2b-256 bb5d783a89a88acd1bad1bc1ec97dd257eb348f7e345b24331b855fe3952e548

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page