Skip to Content
Python Microservices Development
book

Python Microservices Development

by Tarek Ziadé
July 2017
Beginner to intermediate
340 pages
7h 43m
English
Packt Publishing
Content preview from Python Microservices Development

System metrics

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() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Microservices Development - Second Edition

Python Microservices Development - Second Edition

Simon Fraser, Tarek Ziadé
Python Web Development with Sanic

Python Web Development with Sanic

Stephen Sadowski, Adam Hopkins

Publisher Resources

ISBN: 9781785881114Supplemental Content