PyNinja¶
Lightweight OS-agnostic service monitoring API
Platform Supported
Deployments
Kick off¶
Recommendations
Install
python
3.11 or aboveUse a dedicated virtual environment
Install PyNinja
python -m pip install pyninja
Initiate - IDE
import pyninja
if __name__ == '__main__':
pyninja.start()
Initiate - CLI
pyninja start
Use
pyninja --help
for usage instructions.
Environment Variables¶
Sourcing environment variables from an env file
By default,
PyNinja
will look for a.env
file in the current working directory.
Basic API
APIKEY - API Key for authentication.
SWAGGER_UI_PARAMETERS - Dictionary of parameters to be included in the Swagger UI.
NINJA_HOST - Hostname for the API server.
NINJA_PORT - Port number for the API server.
Functional improvements
RATE_LIMIT - List of dictionaries with
max_requests
andseconds
to apply as rate limit.LOG_CONFIG - Logging configuration file path.
Remote execution and FileIO
REMOTE_EXECUTION - Boolean flag to enable remote execution.
API_SECRET - Secret access key for running commands on server remotely.
DATABASE - FilePath to store the auth database that handles the authentication errors.
⚠️ Warning: Enabling remote execution carries significant security risks. To enhance security, it’s strongly recommended to use multifactor authentication (MFA) via your Gmail account. If you don’t have a Gmail account and instead rely on an API_SECRET, please proceed with caution and ensure that the API_SECRET is set to a strong and secure value.
Multifactor Authentication (MFA)
GMAIL_USER - Gmail username for MFA.
GMAIL_PASS - Gmail password for MFA.
RECIPIENT - Recipient email address for MFA.
MFA_TIMEOUT - Timeout duration for MFA in seconds.
Monitoring UI
MONITOR_USERNAME - Username to authenticate the monitoring page.
MONITOR_PASSWORD - Password to authenticate the monitoring page.
MONITOR_SESSION - Session timeout for the monitoring page.
DISK_REPORT - Boolean flag to enable disk report feature using PyUdisk.
MAX_CONNECTIONS - Maximum number of monitoring sessions allowed in parallel.
NO_AUTH - Boolean flag to disable authentication for monitoring page.
PROCESSES - List of process names to include in the monitor page.
SERVICES - List of service names to include in the monitor page.
SERVICE_LIB - Library path to retrieve service info.
SMART_LIB - Library path for S.M.A.R.T metrics using PyUdisk.
GPU_LIB - Library path to retrieve GPU names using PyArchitecture.
DISK_LIB - Library path to retrieve disk info using PyArchitecture.
PROCESSOR_LIB - Library path to retrieve processor name using PyArchitecture.
macOS Specific Binaries
OSASCRIPT - Path to the
osascript
binary for macOS. Defaults to/usr/bin/osascript
MDLS - Path to the
mdls
binary for macOS. Defaults to/usr/bin/mdls
OPEN - Path to the
open
binary for macOS. Defaults to/usr/bin/open
Certain environment variables like
SERVICES
andPROCESSS
are case-sensitive
Refer samples directory for examples.
Coding Standards¶
Docstring format: Google
Styling conventions: PEP 8
and isort
Release Notes¶
Requirement
python -m pip install gitverse
Usage
gitverse-release reverse -f release_notes.rst -t 'Release Notes'
Linting¶
pre-commit
will ensure linting, run pytest, generate runbook & release notes, and validate hyperlinks in ALL
markdown files (including Wiki pages)
Requirement
python -m pip install sphinx==5.1.1 pre-commit recommonmark
Usage
pre-commit run --all-files
Pypi Package¶
Runbook¶
License & copyright¶
© Vignesh Rao
Licensed under the MIT License