Skip to main content

A simple and effective way to gather machine statistics (RAM, Storage, CPU, etc.) from server environment

Project description

Machine Stats for Unix-like systems

PyPI

A simple and effective way to gather machine statistics (RAM, Storage, CPU) from a server environment as a first layer of a Tidal Migrations discovery process.

Machine Stats for Linux/Unix leverages Ansible to gather facts in a cross-platform way.

Installation

Install locally in a Python 3 environment:

python3 -m pip install machine-stats

Need to install in an environment without internet access? Checkout how to do that below.

Data captured

For Linux/Unix based systems, by default, the following metrics are captured from the resources and sent and stored in Tidal Migrations:

  • Host Name
  • FQDN
  • IP Addresses
  • RAM Allocated (GB)
  • RAM Used (GB)
  • Storage Allocated (GB)
  • Storage Used (GB)
  • CPU Count
  • Operating System
  • Operating System Version
  • CPU name

Minimal example

  1. Create a hosts file in the current directory.

  2. Add connection strings in the form of ssh-user@ip-address or ssh-user@domain to the hosts file one per line If the ssh-user@ part is omitted, then the current user name is used.

  3. If you need to use a custom SSH identity file for some particular host, provide it as the following:

    my-user@example.com ansible_ssh_private_key_file=path/to/key-file.pem
    
  4. Make sure that Python 2.6+ is installed on the machines from hosts file.

  5. If python executable was installed into non-default location (not in /usr/bin/python), add the ansible_python_interpreter parameter to the hosts file after the host IP/domain, for example:

    freebsd.example.com ansible_python_interpreter=/usr/local/bin/python
    
  6. Execute machine-stats and pipe its output to Tidal Tools:

    $ machine-stats | tidal sync servers
    

Additional notes

By default Machine Stats looks for the hosts file in current working directory. If your inventory file has another name or is located on another path, then you should specify it explicitly:

$ machine-stats /path/to/myhosts | tidal sync servers

You can specify multiple inventory files as the following:

$ machine-stats hosts myhosts /path/to/myhosts

Configuration

Machine Stats uses Ansible under the hood. Most of the Ansible configuration options can be used with Machine Stats too. By default, Machine Stats will look for configuration files in the following locations:

  • $PWD/machine_stats.cfg
  • $PWD/machine-stats.cfg
  • $PWD/machinestats.cfg
  • $PWD/ansible.cfg
  • $HOME/.machine_stats.cfg
  • $HOME/.machine-stats.cfg
  • $HOME/.machinestats.cfg
  • $HOME/.ansible.cfg
  • /etc/ansible/ansible.cfg

Also, it is possible to specify the custom configuration file location by setting the ANSIBLE_CONFIG environment variable, for example:

$ ANSIBLE_CONFIG=/path/to/my/machine_stats.cfg machine_stats /path/to/my/hosts

Note: if ANSIBLE_CONFIG value points to a directory, then Machine Stats will look for ansible.cfg in that directory.

Getting information about RHEL 5 hosts

Red Hat Enterprise Linux 5 is shipped with Python 2.4 but machine_stats requires at least Python 2.6. To install Python 2.6 on your RHEL 5 machine follow these steps. NOTE: this doesn't update the existing Python packages, but installs Python 2.6 alongside with system Python packages.

  1. Download Python 2.6 package and its dependencies from EPEL repository:

    $ sudo curl -L -OOO -k \
        http://download.fedoraproject.org/pub/archive/epel/5/x86_64/{python26-libs-2.6.8-2.el5.x86_64.rpm,libffi-3.0.5-1.el5.x86_64.rpm,python26-2.6.8-2.el5.x86_64.rpm}
    
  2. Install the packages:

    $ sudo rpm -ivh python26*.rpm libffi*.rpm
    
  3. Use non-standard Python location in your hosts file:

    my-user@rhel5.example.com ansible_python_interpreter=/usr/bin/python2.6
    

Offline installation

NOTE: Creating the packages archive for offline installation and the actual offline installation process must be performed on machines with the same OS and Python versions.

  1. On the machine with internet connection create the packages archive using the following commands:

    $ python3 -m pip download -d machine-stats-offline machine-stats
    $ tar czf machine-stats-offline.tar.gz machine-stats-offline
    
  2. Transfer the archive to the machine where you need to perform the offline installation (replace <remote-host> and <remote-dir> with the appropriate values):

    $ scp machine-stats-offline.tar.gz <remote-host>:/<remote-dir>/
    
  3. On the remote host, extract the archive and switch to extracted directory:

    $ tar xf machine-stats-offline.tar.gz
    $ cd machine-stats-offline
    
  4. Install Machine Stats and its dependencies:

    $ python3 -m pip install --no-index --find-links . machine_stats-*.whl
    

Generating a hosts file from Tidal Migrations

Pro-Tip: If you already use Tidal Migrations Ansible Tower integration script you can use its output to generate the hosts file for machine_stats.

Requirements

Usage

cd ansible-tower-integration
./tidal_inventory.py | jq -r '.servers.hosts[]' > path/to/hosts

Troubleshooting

machine-stats: command not found

If running Machine Stats as a CLI failed, try running it as the following:

$ python3 -m machine_stats

How to permanently enable the Python 3.8 software collection on RHEL 7

You should always enable the Python software collection before using pipenv with the following command:

scl enable rh-python38 bash

To permanently add Python 3 to your $PATH, you can add an scl_source command to the “dot files” for your specific user. The benefit of this approach is that the collection is already enabled at every login.

Using your preferred text editor, add the following line to your ~/.bashrc:

# Add RHSCL Python 3 to my login environment
source scl_source enable rh-python38

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

machine_stats-1.0.1.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

machine_stats-1.0.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file machine_stats-1.0.1.tar.gz.

File metadata

  • Download URL: machine_stats-1.0.1.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for machine_stats-1.0.1.tar.gz
Algorithm Hash digest
SHA256 04906604926efca0e4d8624b78366298ff9f166042265b4680145e2cb044adf5
MD5 e619a450ab9a507984831874e5d83b19
BLAKE2b-256 a27f2aacce738fa0d63acad17d043d948293d170aadcc58d6966df71e8a40f91

See more details on using hashes here.

File details

Details for the file machine_stats-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: machine_stats-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for machine_stats-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8fbadca8de0e86538b08171e03cdc068d77c468bde2ff5776e7232c47de267ee
MD5 961675e2a9eeab6e10aa619459389bc2
BLAKE2b-256 21615c2b357719edfca5fe824b8aa7f11ac76f2dd8541dab5aaa52e4a2dd87f5

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