Skip to main content

Swappy

Fast tools for checking swap memory and remove it in gnu/linux system

Installation

$ pip install swappy

Usage for programming

# create automatic procedure
from swappy.swappy import swapcheck_main
config_pathname = "/path/to/config.yml"
swapcheck_main(config_pathname,
               simulation=False,
               display_stdout=True)

# personnal usage
from swappy.swappy import SwapInfo
swap = SwapInfo()
print(swap.swap_memory().percent) # percentage of swap
print(swap.swap_total)            # total swap taken by system
print(swap.count())               # total process found
print(swap.swap_info_text("pid")) # display text/plain output ordering by pid
print(swap.can_reset())           # can we reset swap with left memories?

Usage for scripting

$ swappy-check --help
Python script to check linux swap pressure
By Mickael Badet (prog at mickbad dot com)
https://github.com/mickbad/swappy

Usage: swappy-check [options] /path/to/config.yml

Options:
  -h, --help  show this help message and exit
  --info      show in stdout swap files if alert [default=False]
  --simulate  simulate resetting swap [default=False]
  
$ sudo swappy-check /path/to/swappy.yml
Swap Checker v1.0.0
swap pressure: 0.00%

Configuration

# -------------------------------------------------------
# - YaML configuration for swappy checker
# -------------------------------------------------------

# configuration for swap alerting
swap:
  # percent alerting (float) **default = 50.0**
  alert-limit: 20.0

  # ordering for array in template (name, pid or swap)
  order-by: swap

  # reset swap if alert
  reset-swap: True

  # post process after alert
  pre-process-alert:
    enable: True
    commands:
      # command list to before resetting
      - apt update
      - ls -lF /tmp

  # post process after alert
  post-process-alert:
    enable: True
    commands:
      # command list to after resetting
      - apt update
      - ls -la /tmp

  # send email to adminsys
  email:
    enable: True
    from: Alert Swap <my@email.com>
    subject: Alert swap on this server for {dd}/{mm}/{yyyy} - {H}:{M}:{S}
    to: my@email.com, my_another@email.com
    template: |
      <b>Alert swap detected:</b></br />
      ➡️ <u>percent info</u>: {swap_percent} %<br />
      ➡️ <u>list of pressure</u>:<br />
      {swap_list}<br />
      <br />
      AdminSys<br />

# SMTP Configuraiton
smtp:
  host: localhost
  port: 25
  tls: False
  login:
  password:

Release files for swappy 1.2.0.post1

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

Source distribution (sdist)

Source distribution for swappy 1.2.0.post1
File Size Uploaded
swappy-1.2.0.post1.tar.gz 7.5 kB Details

Release files / swappy-1.2.0.post1.tar.gz

Download URL swappy-1.2.0.post1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6a5b8b0087dbf6e71e85703035c6751cbf50efc867ad2724a235379440687e1d
BLAKE2b-256 checksum
How to use checksums
99dd11a870504f8f382e1788312bbf50d2262e87895d71ffe4c8d0a3fd7f5de2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.7

Release history Release notifications | RSS feed

This release

1.2.0.post1 This release

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

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