Skip to main content

mongo databases and collections statistics fdw for postgresql

Project description

Mongo database and collection statistics foreign data wrapper for PostgreSQL written in python.

dependencies

installation

  1. install python module

  • from sources (bitbucket)

    $ git clone https://bitbucket.org/olshevskiy87/mongostat_fdw.git
    $ cd mongostat_fdw
    $ python setup.py install
  • using pip

    $ pip install mongostat_fdw
  1. create extension “multicorn” in postgresql (e.g. using psql)

    $$ create extension multicorn;
  2. create foreign servers

    $$ CREATE SERVER mongostat_fdw_db
       FOREIGN DATA WRAPPER multicorn
       OPTIONS (
           wrapper 'mongostat_fdw.MongoDBStatFDW'
       );
    $$ CREATE SERVER mongostat_fdw_coll
       FOREIGN DATA WRAPPER multicorn
       OPTIONS (
           wrapper 'mongostat_fdw.MongoCollStatFDW'
       );
  3. create foreign tables

    $$ CREATE FOREIGN TABLE mongo_db_stat (
        "avgObjSize" NUMERIC,
        collections INT,
        "dataFileVersion" JSONB, -- for Postgres 9.4+ or JSON, or (at least) TEXT
        "extentFreeList" JSONB,  -- Mongo 3.0.0+
        "dataSize" NUMERIC,
        db TEXT,
        "fileSize" NUMERIC,
        "indexSize" NUMERIC,
        indexes INT,
        "nsSizeMB" BIGINT,
        "numExtents" INT,
        objects INT,
        ok NUMERIC,
        "storageSize" NUMERIC,
        "extentFreeList" JSONB   -- for Postgres 9.4+ or JSON, or (at least) TEXT
    ) SERVER mongostat_fdw_db OPTIONS (
        -- uri 'mongodb://127.0.0.1:27017',
        host '127.0.0.1',
        port '27017',
        db 'test'
    );
    $$ CREATE FOREIGN TABLE mongo_coll_stat (
        "avgObjSize" NUMERIC,
        count INT,
        "indexSize" JSONB,
        "lastExtentSize" NUMERIC,
        nindexes INT,
        ns TEXT,
        "numExtents" INT,
        ok NUMERIC,
        "paddingFactor" NUMERIC,
        size NUMERIC,
        "storageSize" NUMERIC,
        "systemFlags" INT,
        "totalIndexSize" NUMERIC,
        "userFlags" INT
    ) SERVER mongostat_fdw_coll OPTIONS (
        db 'test'
    );

usage

  • get “test” database statistics

$$ select db, "fileSize", "dataSize", "avgObjSize", indexes, "dataFileVersion"
   from mongo_db_stat;

  db   | fileSize | dataSize |  avgObjSize   | indexes |     dataFileVersion
-------+----------+----------+---------------+---------+--------------------------
 local | 67108864 |     2840 | 405.714285714 |       1 | {"major": 4, "minor": 5}
 admin |        0 |        0 |           0.0 |       0 | {}
(2 rows)
  • get “test” database collections statistics

$$ select ns as tbl_name, size, "storageSize", count
   from mongo_coll_stat;

      tbl_name       | size | storageSize | count
---------------------+------+-------------+-------
 test.system.indexes |   72 |        4096 |     1
 test.test_coll      |  344 |        4096 |     7
(2 rows)

license

Copyright (c) 2016 Dmitriy Olshevskiy. MIT LICENSE.

See LICENSE.txt for details.

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

mongostat_fdw-0.0.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

mongostat_fdw-0.0.1-py2-none-any.whl (6.0 kB view hashes)

Uploaded Python 2

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