Skip to main content

Write sparkline graphs of CPU and memory usage to your logs.

Project description

sparkle_log

Write a spark line graph of CPU, Memory, etc to the python log

❯ sparkle_log
Demo of Sparkle Monitoring system metrics during operations...
INFO     CPU   :   % |                              ▄ | min, mean, max (4, 4, 4)
INFO     Memory:   % |                              ▄ | min, mean, max (46, 46, 46)
Maybe CPU intensive work done here...
INFO     CPU   :   % |                           ▆▁█▄ | min, mean, max (1, 3.2, 5)
INFO     Memory:   % |                           ▄▄▄▄ | min, mean, max (46, 46, 46)
Maybe Memory intensive work done here...
INFO     Memory:   % |                         ▄▄▄▄▄▄ | min, mean, max (46, 46, 46)
INFO     CPU   :   % |                        ▆▁█▄▃▃▁ | min, mean, max (1, 2.6, 5)
INFO     Memory:   % |                        ▄▄▄▄▄▄▄ | min, mean, max (46, 46, 46)

Install

pip install sparkle_log

Usage

This will write up to log entries to your AWS Lambda log, at a frequency you specify, e.g. every 60 seconds. Light-weight, cheap, immediately correlates to your other print statements and log entries.

If logging is less than INFO, then no data is collected.

As a decorator

import sparkle_log
import logging

logging.basicConfig(level=logging.INFO)


@sparkle_log.monitor_metrics_on_call(("cpu", "memory"), 60)
def handler_name(event, context) -> str:
    return "Hello world!"

As a context manager:

import time
import sparkle_log
import logging

logging.basicConfig(level=logging.INFO)


def handler_name(event, context) -> str:
    with sparkle_log.MetricsLoggingContext(metrics=("cpu", "memory"), interval=5):
        time.sleep(20)
        return "Hello world!"

Prior art

You could also use container insights or htop. This tool should provide the most value when the server is headless and you only have logging or no easy way to correlate log entries to graphs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sparkle_log-0.2.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

sparkle_log-0.2.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file sparkle_log-0.2.0.tar.gz.

File metadata

  • Download URL: sparkle_log-0.2.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sparkle_log-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e6612ddb95be106b47947ba81a6eafc74154383e2750bafe4cce41336180b8e8
MD5 017eb4a3d5613483cb3850846ea41c42
BLAKE2b-256 051dbcb94faccbc2202d9ac241ffc568b4f0d3518f6b4b143490dccc0679f43e

See more details on using hashes here.

File details

Details for the file sparkle_log-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sparkle_log-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sparkle_log-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7de52d84d92cbcfc99b8b525041dcb1f53196f369eca963167cf051f51f4847a
MD5 4a02d1ce3b1034d464819cbe04f05f0f
BLAKE2b-256 8f6c220465c50b5b8b6863388663bb3b3b79ee1b6c15f77e64f48d1f7c260f7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page