July 2017
Beginner to intermediate
340 pages
7h 43m
English
A Linux-based system makes it simple to monitor the CPU, memory, and disk. There are system files that get continuously updated with this information and numerous tools to read them. Commands such as ;top will let you follow all the running processes and sort them by RAM or CPU usage.
In Python, the psutil (https://pythonhosted.org/psutil) ;project is a cross-platform library you can use to get all this info programmatically.
Combined with the graypy package, you can write a small script to send system metrics to Graylog continuously.
In the following example, an asyncio loop sends the CPU usage in percent every second to Graylog:
import psutil import asyncio import signal import graypy import logging import json loop = asyncio.get_event_loop() ...