Skip to main content

A small example package

Project description

pyftdc

Gitter

CI status
pip builds Pip Actions Status

A MongoDB FTDC files parser written in C++ that provides Python bindings using pybind11 and scikit-build.

Requisites

To build the source distribution, you will need Python 3.8 or newer, git, python3-dev/python3-devel installed.

Please read the build document for more details.

Installation

Building on Unix (Ubuntu, Centos, macOS)

  1. clone this repository and change to the top level directory.

    git clone git@gitlab.com:jimper/mongo_ftdc.git 
    cd mongo_ftdc
    
  2. Install Python libraries to build binaries. Create a virtual environment to make your life easier.

    python3 -m venv venv
    source venv/bin/activate
    pip3 install --user-pep517 .
    

    You will now have built and installed in your virtual environment.

Alternatively, you can use setup.py directly, but for that you will need to manually install the required libraries into your virtual environment by running

 cd mongo_ftdc
 pip install -r requirements.txt

After which you can create a source distribution or a binary wheel:

 python3 setup.py sdist
 python3 setup.py bdist_wheel

These will reside in the dist directory.

Building on Windows

Not tested yet, but 'It should work'(TM)

License

Apache V2

Test call

import pyftdc


def get_prefixed_metrics_names(param, ds):
    ops_counters = []
    for name in ds.metrics_names:
        if name.startswith(param):
            ops = ds.get_metric(name)
            ops_counters.append((name, ops))

    return ops_counters


def open_files_in_dir(dir_path, prefix):
    from os import listdir

    files_read = []
    try:
        dir_list = listdir(dir_path)
        for file_name in dir_list:
            if file_name.startswith(prefix):
                parser = pyftdc.FTDCParser()
                ds = parser.parse_file(dir_path + '/' + file_name)
                if ds:
                    print(f'File: {ds.file}')
                    print(f'{ds.metadata}')
                    ts = ds.get_metric("start")
                    if ts:
                        ts_size = len(ts)

                        print(f'Timestamp count {ts_size}. Start:{ts[0]}  Last: {ts[-1]}')

                        op_counter_names = get_prefixed_metrics_names('serverStatus.opcounters', ds)
                        cpu = get_prefixed_metrics_names('systemMetrics.cpu', ds)
                        disk = get_prefixed_metrics_names('systemMetrics.disks.nvme1n1', ds)

                        xxx = ds.get_metric_list_numpy(['systemMetrics.cpu.iowait_ms', 'xxx', 'systemMetrics.cpu.num_cpus'])
                        disk_n = ds.get_metric_numpy('systemMetrics.disks.nvme1n1.writes')

                        files_read.append(file_name)
                    else:
                        print(f'No timestamps on this dataset.')
    except FileNotFoundError as not_found:
        print('Path not found.')

    return files_read


def open_dir(dir_path):
    multi_parser = pyftdc.FTDCParser()
    datasets = multi_parser.parse_dir(dir_path)
    ds_count = len(datasets)
    print(f'There are {ds_count} datasets from {dir_path}')
    if ds_count > 0:
        for ds in datasets:
            if ds:
                print(f'File: {ds.file}')
                print(f'{ds.metadata}')
                ts = ds.get_metrics("start")
                if ts:
                    ts_size = len(ts)

                    print(f'Timestamp count {ts_size}. Start:{ts[0]}  Last: {ts[-1]}')

                    op_counter_names = get_prefixed_metrics_names('serverStatus.opcounters', ds)
                    cpu = get_prefixed_metrics_names('systemMetrics.cpu', ds)
                    disk = get_prefixed_metrics_names('systemMetrics.disks.nvme1n1', ds)

                    print('')
                else:
                    print(f'No timestamps on this dataset.')
            else:
                print(f'Bad dataset from file {ds}')


if __name__ == "__main__":
    files = open_files_in_dir('/somepath/diagnostic.data/',
                              'metrics.2022-11-13T21')
    print(files)

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

pyftdc-0.3.0.tar.gz (727.6 kB view details)

Uploaded Source

Built Distribution

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

pyftdc-0.3.0-cp39-cp39-macosx_12_0_universal2.whl (472.6 kB view details)

Uploaded CPython 3.9macOS 12.0+ universal2 (ARM64, x86-64)

File details

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

File metadata

  • Download URL: pyftdc-0.3.0.tar.gz
  • Upload date:
  • Size: 727.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.6

File hashes

Hashes for pyftdc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8bf76a7dad0c15c6728d5575457f40f5f7f49f90b49138da3a207f1169edf78b
MD5 5b0faafa83e7e8f5d960730bdbabc74d
BLAKE2b-256 7e0280669d0bad6aa430d58304b779db547205be800ab5ebcd5743052819aedf

See more details on using hashes here.

File details

Details for the file pyftdc-0.3.0-cp39-cp39-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for pyftdc-0.3.0-cp39-cp39-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 c26f669274bc633b385464b86615179e4bd5e69cf77ff266472bf8643dabf202
MD5 9e42724655cf55209a40e404b2d9e5f8
BLAKE2b-256 24860783e7e4860251eeaf3f2e65a61a998ddbf2ae67d24c9a044cc49e233b97

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