Skip to main content
GitHub release GitHub code size in bytes MHTML License PyPI supported Python versions Code style: black

A simple python Discord bot that observes a local machine and sends notifications on resource exhaustion. It allows additionally to query the machine status via Discord.

It registers the following command:

  • dbot-observe - a blocking script, that runs periodic system checks and notifies about shortages (may require extra dependencies to be installed for more information)

Requirements

  • Python >= 3.6 (see badges above)

  • discord.py

  • psutil (for cpu/ram/disk information querying)

  • Extra:

    • gpu: GPUtil

    • plot: matplotlib, for generating plots

Installation

python3 -m pip install discord-system-observer-bot

Optionally, install it locally with --user.

For GPU infos, you have to install extra dependencies: gpu (nvidia-smi information):

python3 -m pip install discord-system-observer-bot[gpu]

Configuration

Configuration is done by placing a .dbot.conf file in one of the following directories:

  • $HOME/.dbot.conf

  • $HOME/dbot.conf

  • ./.dbot.conf

  • ./dbot.conf

  • /etc/dbot.conf

Alternatively a configuration file can be provided via -c/--config CLI options.

The configuration file should be a standard INI file. A template can be found in the templates folder. All configurations are placed under the discord-bot section.

Example:

[discord-bot]
# the bot token (used for login)
token = abc
# the numeric id of a channel, can be found when activating the developer options in appearances
channel = 123

Usage

dbot-observe is the main entry-point.

Print help and available options:

dbot-observe -h

Output:

usage: dbot-observe [-h] [-c CONFIG] [-d] [-n NAME]

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Config file
  -d, --debug           Enable debug logging
  -n NAME, --name NAME  Local machine name (id)

Starting the observer bot (without actually starting the background observation, just waiting for a Discord message to start/stop etc.):

dbot-observe

You are always able to specify the configuration file like this:

dbot-observe -c /path/to/dbot.conf [...]

To display debugging information (api calls, log messages etc.):

dbot-observe -d [...]

You may also run the bot with the python module notation. But it will only run the same entry-point like dbot-observe.

python -m discord_system_observer_bot [...]

System Observer Bot

The dbot-observe command runs a looping Discord task that checks every 5 min some predefined system conditions, and sends a notification if a badness value is over a threshold. This badness value serves to either immediatly notify a channel if a system resource is exhausted or after some repeated limit exceedances.

The code (checks and limits) can be found in discord_system_observer_bot.sysinfo. The current limits are some less-than educated guesses, and are subject to change. Dynamic configuration is currently not an main issue, so users may need to clone the repo, change values and install the python package from source:

git clone https://github.com/Querela/discord-system-observer-bot.git
cd discord-system-observer-bot/
# [do the modifications in discord_system_observer_bot/sysinfo.py]
python3 -m pip install --user --upgrade --editable .[gpu,plot]

The system information gathering may require the extra dependencies to be installed, like gpu for GPU information, or plot for series charts.

I suggest that you provide a different Discord channel for those notifications and create an extra .dbot-observer.conf configuration file that can then be used like this:

dbot-observe [-d] -c ~/.dbot-observer.conf

Embedded in other scripts

Sending messages is rather straightforward. More complex examples can be found in the CLI entrypoints, see file discord_system_observer_bot.cli. Below are some rather basic examples (extracted from the CLI code).

Basic setup (logging + config loading):

from discord_system_observer_bot.cli import setup_logging, load_config

# logging (rather basic, if needed)
setup_logging(True)

# load configuration file (provide filename or None)
configs = load_config(filename=None)

Sending a message:

from discord_system_observer_bot.bot import run_observer

# bot token and channel_id (loaded from configs or hard-coded)
bot_token, channel_id = configs["token"], configs["channel"]
# start the observer running (blocks forever)
run_observer(bot_token, channel_id, message)

Bot Creation etc.

See information provided by:

Short description

You have to own a Discord server! Or know someone with administrator/moderation(?) privileges.

  1. Visit and login to the Discord developer page.

  2. Create a new application. The given name is also the visible name of the bot. (default, can be changed later?)

  3. Create a bot (on the Bot page). You should disable the Public Bot option.

    • The bot login token (credentials) can be found on the Bot page.

  4. Change to the OAuth2 page and check

    • Scopes: Bot

    • Bot Permissions: Send Messages, Attach Files (in the Text Permissions column)

  5. Copy the URL in the Scopes section and paste it in a new browser tab.

    • Now you can choose one (?) of your own Discord servers to add the bot to. (For this you need server administration permissions, or be the owner..?)

To get the channel id, send the following message on your server \#channelname, or enable developer options. You may want to visit the following pages for more information:

Metadata

Release files for discord-system-observer-bot 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord-system-observer-bot 0.0.5
File Size Uploaded Provenance Actions
discord-system-observer-bot-0.0.5.tar.gz 17.3 kB Without provenance Details for discord-system-observer-bot-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for discord-system-observer-bot 0.0.5
File Interpreter ABI Platform Actions
discord_system_observer_bot-0.0.5-py3-none-any.whl Python 3 none any Details for discord_system_observer_bot-0.0.5-py3-none-any.whl

Total release size: 37.9 kB

Release files / discord-system-observer-bot-0.0.5.tar.gz

Download URL discord-system-observer-bot-0.0.5.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
abec5c4fd462be07924f9f1c4085004dde48473eb3096173f12f75e399f13dac
BLAKE2b-256 checksum
How to use checksums
b061f2d2e183f3ccc24e9b2e1d061e017cdb592d55124792f93a9f6e093d7fce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

Release files / discord_system_observer_bot-0.0.5-py3-none-any.whl

Download URL discord_system_observer_bot-0.0.5-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc7b9922f6083d604ef1e413fa08861df8b2af4a01c0bdefd1f463b69e08cfab
BLAKE2b-256 checksum
How to use checksums
a9bc9905bc0403121f099d79742c80859caf17fc465410eaee3f189c6b4e9507
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

Security for discord-system-observer-bot 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page