Skip to main content

Audit any running python process.

Project description

Nogi

Build PyPI PyPI - Python Version PyPI - Status Downloads Downloads Code style: black

Toogleable events auditor for Python apps.

Live monitor Python events and user defined custome events in running Python applications.

Nogi allow you to audit your code without adding debug tracing and invasive prints. Just instantiate Nogi in your code and then send a signal to your running app to start auditing it.

Nogi allow you to enable and disable audit without restarting your application and so without loosing the context that you want to observe, by example a occuring bug.

See the example below.

For further details please read the official documentation

Install

$ pip install nogi

Usages

Simply instanciate Nogi at the begining of your code:

Nogi()

Example

Here is a concret example (see examples/sample.py):

# sample.py
import requests
import time

from nogi import Nogi

Nogi()

def main():
    for i in range(1000):
        r = requests.get(
            "https://en.wikipedia.org/wiki/Python_(programming_language)")
        print(r.status_code)
        time.sleep(1)

if __name__ == "__main__":
    main()

Run the previous code:

$ python examples/sample.py
200
200
...
200
...

Then enable the audit by sending the SIGUSR1 to the process previously launched:

$ ps ax | grep python | grep sample # to retrieve the process id (pid)
$ kill -SIGUSR1 <pid>

We are now able to collect events by running the Nogi client:

$ nogi
Starting the audit listener
Audit client listening...
event: socket.getaddrinfo
data: ('en.wikipedia.org', 443, 0, 1, 0)
event: socket.__new__
data: (<socket.socket fd=-1, family=0, type=0, proto=0>, 2, 1, 6)
event: socket.connect
data: (<socket.socket fd=4, family=2, type=1, proto=6, laddr=('0.0.0.0', 0)>, ('185.15.58.224', 443))
event: http.client.connect
data: (<urllib3.connection.HTTPSConnection object at 0x7f0b48fafbf0>, 'en.wikipedia.org', 443)
event: socket.__new__
data: (<ssl.SSLSocket fd=-1, family=0, type=0, proto=0>, 2, 1, 6)
event: http.client.send
data: (<urllib3.connection.HTTPSConnection object at 0x7f0b48fafbf0>, b'GET /wiki/Python_(programming_language) HTTP/1.1\r\nHost: en.wikipedia.org\r\nUser-Agent: python-requests/2.31.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n')
...

When you want to terminate your audit, simply send the SIGUSR2 signal to the same process id (pid) to stop forwarding events.

$ kill -SIGUSR2 <pid>

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

nogi-0.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

nogi-0.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nogi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c040413415c6476701b54f3ac22c28dd8c00ab9506ef8956c502010ca49d24c6
MD5 ea3ac61ad84b44132788cf667aa3a1b9
BLAKE2b-256 1225b21b9cb47c33c2d9eefbc5cbbdb8bec0835b7ee3d9fc331b2e7a21aa2201

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nogi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d455f3f99c5656058dacaf071da6b8d50ae442bd98e97105dce07aaffe9d78c8
MD5 c1347ed941344bfe820112ed74bacf9e
BLAKE2b-256 66bc9c5d3d983cee613c0d368a3e3e47d4123f79469544e326cc2ddfad9fea77

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