This demo shows you how to build an infrastructure monitoring tool, similar to a mini-datadog, that keeps track of some stats from all of the computers running this included script. Using this data, we can plot time series and build something based on "real" data being captured in the moment.
This script essentially is a Python script that gathers some information (what's your OS - e.g: Windows, macOS or Ubuntu), how many CPUs you have, available memory and available disk and sends an event every second with it.
This is how the messages look:
{
'timestamp': '2023-02-21 03:11:31.709',
'nickname': 'Sancha',
'team': 'Tinybird',
'text': 'Good luck!',
'os': 'Darwin',
'cpus': 8,
'mem_size': 34359738368,
'mem_free': 15164309504,
'disk_size': 494384795648,
'disk_free': 112696381440
}
I'll build a time series in Tinybird that plots free memory over time per OS and/or number of CPUS, and a couple of endpoints that expose the data.
-
Save in a local folder
-
Go that folder in the terminal and run the following:
python3 -m venv .venv
source .venv/bin/activate
pip install pytz kafka-python psutil confluent-kafka
- Configure the script
Open the index.py
and customize lines 22 and 24:
your_nickname = 'Joe' #enter a nickname
message_to_tinybird = 'Good luck!' #Or say something funny, but keep it tidy... 8)
- Run the script
In a terminal, run the following:
python3 index.py
Note: If you are running this on macOS, be sure to run the following to prevent the computer from sleeping:
caffeinate -s python3 index.py
If you are in Ubuntu, you probably know better than me how to prevent the computer from sleeping. If you are in Windows, your guess is as good as mine.
The script will sleep until an hour before the start of the demo. Just leave it running. Once the time of the event has past, the script will stop automatically.
Need help?: Community Slack • Tinybird Docs • Email