Giter Club home page Giter Club logo

py-mdstat's Introduction

mdstat for python

This short library is used to convert your /proc/mdstat file into an object usable in Python. It comes with a short mdjson script that dumps your file in a JSON format.

Requirements

  • Linux (or at least get mdstat files from a Linux machine)
  • Python 2.7+ (or 3.2+)

Example usage

For most use cases, you can simple run mdstat.parse() to get nested dictionaries repesenting your local /proc/mdstat file. If you fetch the file remotely or need to run the parser on a stream, use parse_stream.

$ mdjson
{
    "personalities": [
        "raid10"
    ],
    "unused_devices": [],
    "devices": {
        "md127": {
            "read_only": true,
            "status": {
                "near_copies": 2,
                "blocks": 34359475200,
                "raid_disks": 4,
                "offset_copies": 0,
                "far_copies": 1,
                "synced": [
                    true,
                    true,
                    true,
                    true
                ],
                "chunks": "512K",
                "super": "1.2",
                "non_degraded_disks": 4
            },
            "bitmap": null,
            "resync": null,
            "active": true,
            "disks": {
                "xvdf": {
                    "spare": true,
                    "faulty": false,
                    "write_mostly": false,
                    "number": 4,
                    "replacement": false
                },
                "xvdd": {
                    "spare": false,
                    "faulty": false,
                    "write_mostly": false,
                    "number": 2,
                    "replacement": false
                },
                "xvde": {
                    "spare": false,
                    "faulty": false,
                    "write_mostly": false,
                    "number": 3,
                    "replacement": false
                },
                "xvdb": {
                    "spare": false,
                    "faulty": false,
                    "write_mostly": false,
                    "number": 0,
                    "replacement": false
                },
                "xvdc": {
                    "spare": false,
                    "faulty": false,
                    "write_mostly": false,
                    "number": 1,
                    "replacement": false
                }
            },
            "personality": "raid10"
        }
    }
}

You can also use the python interface to generate a nested dictionary:

>>> import mdstat
>>> mdstat.parse()
{
    "personalities": [
        "raid1",
        "raid5",
        "raid10",
    ],
    "devices": {
        "md0": {
            "active": True,
            [... snip ...]
        }
    }
    "unused_devices": []
}

py-mdstat's People

Contributors

tamentis avatar shurl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.