Unknown macro: {style}

.ia-secondary-container

Unknown macro: { margin}
Unknown macro: {div}
Kaa releases
Unknown macro: {div}
Shortcuts

Page tree
Skip to end of metadata
Go to start of metadata

The MongoDB log appender is responsible for transferring logs from the Operations server to the MongoDB database. The logs are stored in the table named logs_$applicationToken, where $applicationToken matches the token of the current application.

Creating MongoDB log appender in Admin UI

The easiest way to create a MongoDB log appender for your application is by using Admin UI.

Creating MongoDB log appender with REST API

It is also possible to create a MongoDB log appender for your application by using REST API. The following example illustrates how to provision the MongoDB log appender for the Cell Monitor demo application available in Kaa Sandbox.

Configuration

The MongoDB log appender configuration should match the following Avro schema.

{  
    "namespace":"org.kaaproject.kaa.server.appenders.mongo.config.gen",
    "type":"record",
    "name":"MongoDbConfig",
    "fields":[  
        {  
            "name":"mongoServers",
            "displayName":"MongoDB nodes",
            "minRowCount":1,
            "type":{  
                "type":"array",
                "items":{  
                    "namespace":"org.kaaproject.kaa.server.appenders.mongo.config.gen",
                    "type":"record",
                    "name":"MongoDbServer",
                    "fields":[  
                        {  
                            "name":"host",
                            "displayName":"Host",
                            "weight":0.75,
                            "default":"localhost",
                            "type":"string"
                        },
                        {  
                            "name":"port",
                            "displayName":"Port",
                            "weight":0.25,
                            "default":27017,
                            "type":"int"
                        }
                    ]
                }
            }
        },
        {  
            "name":"mongoCredentials",
            "displayName":"Authentication credentials",
            "minRowCount":0,
            "type":{  
                "type":"array",
                "items":{  
                    "namespace":"org.kaaproject.kaa.server.appenders.mongo.config.gen",
                    "type":"record",
                    "name":"MongoDBCredential",
                    "fields":[  
                        {  
                            "name":"user",
                            "displayName":"User",
                            "weight":0.5,
                            "default":"user",
                            "type":"string"
                        },
                        {  
                            "name":"password",
                            "displayName":"Password",
                            "weight":0.5,
                            "default":"password",
                            "type":"string"
                        }
                    ]
                }
            }
        },
        {  
            "name":"dbName",
            "displayName":"MongoDB database name",
            "type":"string"
        },
        {  
            "name":"connectionsPerHost",
            "displayName":"Max connections per host",
            "default":30,
            "optional":true,
            "type":[  
                "int",
                "null"
            ]
        },
        {  
            "name":"maxWaitTime",
            "displayName":"Max wait time (ms)",
            "default":120000,
            "optional":true,
            "type":[  
                "int",
                "null"
            ]
        },
        {  
            "name":"connectionTimeout",
            "displayName":"Connection timeout (ms)",
            "default":5000,
            "optional":true,
            "type":[  
                "int",
                "null"
            ]
        },
        {  
            "name":"socketTimeout",
            "displayName":"Socket timeout (ms)",
            "default":0,
            "optional":true,
            "type":[  
                "int",
                "null"
            ]
        },
        {  
            "name":"socketKeepalive",
            "displayName":"Turn on socket keepalive",
            "default":false,
            "optional":true,
            "type":[  
                "boolean",
                "null"
            ]
        },
        {  
            "name":"autoConnectRetry",
            "displayName":"Automatic reconnect on errors",
            "default":true,
            "optional":true,
            "type":[  
                "boolean",
                "null"
            ]
        }
    ]
}

The following configuration taken from the Cell Monitor demo matches the previous schema.

{  
    "mongoServers":[  
        {  
            "host":"127.0.0.1",
            "port":27001
        }
    ],
    "mongoCredentials":[  
        {  
            "user":"your_user_name",
            "password":"your_password"
        }
    ],
    "dbName":"test_db",
    "connectionsPerHost":{"int":10},
    "maxWaitTime":{"int":120000},
    "connectionTimeout":{"int":5000},
    "socketTimeout":{"int":60},
    "socketKeepalive":{"boolean":true},
    "autoConnectRetry":{"boolean":true}
}


Administration

The following REST API call example illustrates how to create a new MongoDB log appender.

curl -v -S -u devuser:devuser123 -X POST -H 'Content-Type: application/json' -d'{"pluginClassName": "org.kaaproject.kaa.server.appenders.mongo.appender.MongoDbLogAppender", "applicationId": 119, "applicationToken": "91786338058670361194", "jsonConfiguration": "{\"mongoServers\":[{\"host\":\"127.0.0.1\",\"port\":27017}],\"mongoCredentials\":[{\"user\":\"your_user_name\",\"password\":\"your_user_password\"}],\"dbName\":\"test_db\",\"connectionsPerHost\":{\"int\":30},\"maxWaitTime\":{\"int\":120000},\"connectionTimeout\":{\"int\":5000},\"socketTimeout\":{\"int\":0},\"socketKeepalive\":{\"boolean\":false},\"autoConnectRetry\":{\"boolean\":true}}", "description": "New sample Mongo db log appender", "headerStructure": [ "KEYHASH","TIMESTAMP" ], "name": "New Mongo DB appender", "maxLogSchemaVersion": 2147483647, "minLogSchemaVersion": 1, "tenantId": "70"}' "http://localhost:8080/kaaAdmin/rest/api/logAppender" | python -mjson.tool
 Example result
{  
    "appenderClassName":"org.kaaproject.kaa.server.appenders.mongo.appender.MongoDbLogAppender",
    "applicationId":"70",
    "applicationToken":"946558468095768",
    "configuration":"{\"mongoServers\":[{\"host\":\"127.0.0.1\",\"port\":27017}],\"dbName\":\"test_db\",\"connectionsPerHost\":{\"int\":30},\"maxWaitTime\":{\"int\":120000},\"connectionTimeout\":{\"int\":5000},\"socketTimeout\":{\"int\":0},\"socketKeepalive\":{\"boolean\":false},\"autoConnectRetry\":{\"boolean\":true}}",
    "createdTime":1417105170741,
    "createdUsername":"devuser",
    "description":"Sample MongoDB log appender",
    "headerStructure":[  
        "KEYHASH",
        "TOKEN"
    ],
    "id":"164",
    "name":"MongoDB appender",
    "maxLogSchemaVersion": 2147483647, 
    "minLogSchemaVersion": 1,
    "status":"REGISTERED",
    "tenantId":"10",
    "typeName":"Mongo"
}

Copyright © 2014-2015, CyberVision, Inc.

  • No labels