Skip to main content

No project description provided

Project description

mylutils V 0.3.0

This is a collection of file utilities. It is currently under active development and not quite ready for prime-time.

The following are instructions to help you use the package:

Functions now available in mylutils

  • read_txt : Returns a list of strings, one line each.
  • read_csv : Returns a list of lists of strings, one string on each column.
  • read_proc_stat_cpu : Returns a dictionary with data from the first line from /proc/stat, which corresponds to the consolidated CPU data.
  • read_proc_meminfo : Returns a list of dictionaries with data from /proc/meminfo.
  • read_proc_vmstat : Returns a dictionary with data from the first line from /proc/vmstat.
  • read_proc_pid_stat : Returns a list of dictionaries with the data from /proc/<PID>/stat file. One dictionary per pid. Please read man 5 proc for more information.

How to pip install and run

In the Linux shell command line

1. Pip install

pip install mylutils

2. run the examples/example.py

import mylutils

for line in mylutils.read_txt("test.txt"):
    print(line)

3. on Python's REPL, do a dir(mylutils)

$ python
> import mylutils
> dir(mylutils)

In virtual environment

1. clone the repo

$ git clone git@github.com:mayelespino/pyrust.git
$ cd pyrust/mylutils/

2. create a virtual environment

$ sudo python3 -m venv .env
$ source .env/bin/activate

3. install maturin

$ pip install maturin

4. build mylutils in virtual env

$ maturin dev

5. run the examples/example.py

import mylutils

for line in mylutils.read_txt("test.txt"):
    print(line)

Possible uses of mylutils

Write Python various functions or a class that calls mylutils functions. For example:

def is_cpu_idle(threshold=50):
    cpu_stats = mylutils.read_proc_stat_cpu()
    total_time = cpu_stats['total_time']
    idle  _time = cpu_stats['idle_time']
    return((idle_time/total_time)*100 < threshold)

When called on Pythons REPL:

> print(f"\nis_cpu_idle(99): {is_cpu_idle(99)}", )
> is_cpu_idle(99): True

Next write a salt diagnostics module or stand-alone script based on the functions above. For example:

checks_to_perform = []
def add_check(check, list):
    if check not in list:
        list.append(check)
    return


if !is_cpu_idle(50):
    if is_cpu_user(50):
        print("CPU is busy processing User processes.")
        add_check("check_pids_state", checks_to_perform)
    if is_cpu_system(50):
        print("CPU is busy processing System processes.")
        add_check("check_system_errors", checks_to_perform)
    if is_cpu_iowait(25):
        print("CPU is busy in IOWAIT.")
        add_check("check_network_usage", checks_to_perform)
        add_check("check_disk_usage", checks_to_perform)
    if is_memory_swap(20):
        print("Memmory swap space usage is high.")
        add_check("check_system_errors", checks_to_perform)

examples/*.py

In the examples folder there are a few Python programs to ilustrate and test the functions in the mylutils package.

TODO

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

mylutils-0.3.0.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mylutils-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl (284.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file mylutils-0.3.0.tar.gz.

File metadata

  • Download URL: mylutils-0.3.0.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for mylutils-0.3.0.tar.gz
Algorithm Hash digest
SHA256 73079215aa0cef34e799d5ce3d9c45c12b54824c012dc8e68458643b0ec7cdcc
MD5 51437ff2e9b7474397c2f2f7a5b6fce2
BLAKE2b-256 503d5292e0c26a650b32edb7c8de8d97ca89fdd996208e02f7a34d35c2953a72

See more details on using hashes here.

File details

Details for the file mylutils-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mylutils-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 36ce282c30628d2f661be173d26563296b9cf315ec81e6d4b7e8c4ff53bbace6
MD5 849eee3791d31f5ef4b90cfddc387b2a
BLAKE2b-256 d97a51517ddf0b6282c598ce4c3527134fccfa9ff6d689b70cfa3d90989f61f4

See more details on using hashes here.

Supported by

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