Connect Moskito-Central to MongoDB


Andrii Skrypnyk - April 22, 2015 - 2 comments

Today we are going to connect MoSKito-Central to MongoDB database.

In a few words, MoSKito-Central is a service (remote or embedded) that receives your MoSKito statistics and stores it in the place of your choice (Filesystem, Database, …).

Our choice for now is MongoDB and MoSKito-Central in embedded mode.

Before we start, you need to have our test-application the burgershop locally in a proper state, so just perform following steps:

1
2
3
cd burgershop
git checkout moskito-integration-guide-step3

I. Adding dependencies

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<properties>
    ...
    <moskito-central.version>1.1.2</moskito-central.version>
</properties>
...
<dependency>
    <groupId>org.moskito</groupId>
    <artifactId>moskito-central-embedded-connector</artifactId>
    <version>${moskito-central.version}</version>
</dependency>
<dependency>
    <groupId>org.moskito</groupId>
    <artifactId>moskito-central-storages</artifactId>
    <version>${moskito-central.version}</version>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver</artifactId>
    <version>3.0.0</version>
</dependency>

In this step we’re adding the dependencies for embedded-connector and storages.

II. Adding configurations

First of all we need to create resources directory and put some new config files there.

1
mkdir ./src/main/resources

moskito.json

1
2
3
4
5
6
7
8
9
10
11
{
    "@pluginsConfig": {
        "@plugins": [
            {
                "name": "EmbeddedCentralConnector",
                "configurationName": "none",
                "className": "org.moskito.central.connectors.embedded.EmbeddedConnector"
            }
        ]
    }
}

This config sets the embedded MoSKito-Central connector to the our burgershop.

moskito-central.json

1
2
3
4
5
6
7
8
9
{
    "@storages": [
                {
           "name": "mongo-db",
           "clazz": "org.moskito.central.storage.mongo.MongoDBStorage",
           "configName": "moskito-mongoDB"
        }
    ]
}

moskito-central.json configures the list of storages (config file name and implementation class), in our case we configure one MongoDB storage. For a full storages list, please check documentation or sources.

moskito-mongoDB.json

1
2
3
4
5
6
7
8
9
10
11
12
13
{
    "host": "localhost",
    "port": "27017",
    "dbName": "burgertest",
    "login": "user",
    "password": "111",
    "collectionName": "snapshot",
    "distributeProducers": "true",
    "includeIntervals": "*",
    "excludeIntervals": "1m",
    "includeProducers": "*",
    "excludeProducers": ""
}

With this, we configure our MongoDB storage. Set distributeProducers to “true” and every producer will be stored in it’s own collection, if not – collectionName will be used to store snapshots into one named collection of your Mongo database.

III. Run it!

Build the burgershop, deploy it and, of course, don’t forget to order some new burgers 🙂

After a couple of minutes, you’ll find a new stored data in your MongoDB database.

It’s looks like this:

Screen Shot 2015-04-22 at 10.27.57

Enjoy!

2 comments

  1. […] yet. thought of moskito central store info in tool of choice, illustration sql-database, mongo (http://blog.anotheria.net/msk/connect-moskito-central-to-mongodb-database/), elasticsearch or […]

  2. Santhosh

    Is there any builtin support available in moskito web apps for LDAP authentication and authorization.

Post a Reply to Santhosh Click here to cancel reply

Your email address will not be published.