Monitoring Your Meteor Apps with Kadira

Anton Martynenko
delodi
Published in
3 min readNov 16, 2017

--

There once was a nice tool called Kadira APM to monitor you Meteor apps, which unfortunately was bought, but fortunately it’s been opensourced, so now everyone can set it up locally or on a separate server to still have an ability to monitor their apps.

As you might already know, there’s a detailed step-by-step guide (part1, part2, part3), so this article will be about my own experience with setting it up, and the problems I’ve experienced and eventually solved.

Before you start, please ensure you’re using the right repo. If you need to deploy on AWS, then you should use the one that’s stated in the article. But if you intend to deploy on a regular server, you can use the default one.

In our case we had a Linux server (Ubuntu 16.04) with 2Gb of RAM (I used DigitalOcean $20 instance), or you can have a 1Gb one with a swap file (which is, in fact, discouraged by DigitalOcean). Because I was receiving out-of-memory errors with 1Gb instance. And then, when everything is up and running, 1.3–1.5Gb of memory is consumed.

  1. First thing you would need to adjust additionally, before executing rs.initiate()`, is adding a replica set config to /etc/mongod.conf`:
replication:    oplogSizeMB: 1024    replSetName: rs0

2. Second thing that is omitted is the SSL certificate for nginx. In the config it has the path `/etc/nginx/ssl/kadira.pem`, which is not there, of course. For our setup, I’ve configured a subdomain and received a Letsencrypt certificate for it with Certbot. If you set up the default way, your SSL paths will look like this:

ssl_certificate /etc/letsencrypt/live/kadira.your.site/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/kadira.your.site/privkey.pem;

3. Third thing I’ve experienced a problem with, was connecting to the oplog database (/local). My mistake was putting the credentials in the connect URL. The article explicitly says you to use mongodb://localhost:27017/local, but I accidentally added the credentials, so beware.

4. If you’re using the default repo, and not the modified for AWS, you’d also need to adjust the systemd init scripts. Of course you have to replace the USERNAME, but additionally to fix the directory with a cloned git repo:

ExecStart=/bin/bash -c "source kadira-server/init-shell.sh; cd kadira-server/kadira-engine; ./run.sh"

5. Next problem was kadira-rma — I had an issue with executing the start.sh shell script, the interpreter didn’t recognize the double bracket, so I had to modify the package.json file, replacing the start scripts, so it’s explicitly using the bash interpreter:

{  "scripts": {    "start": "run-p -l run:**",    "run:errors-1min": "PROFILE=1min PROVIDER=errors /bin/bash start.sh",    "run:errors-30min": "PROFILE=30min PROVIDER=errors /bin/bash start.sh",    "run:errors-3hour": "PROFILE=3hour PROVIDER=errors /bin/bash start.sh",    "run:methods-1min": "PROFILE=1min PROVIDER=methods /bin/bash start.sh",    "run:methods-30min": "PROFILE=30min PROVIDER=methods /bin/bash start.sh",    "run:methods-3hour": "PROFILE=3hour PROVIDER=methods /bin/bash start.sh",    "run:pubsub-1min": "PROFILE=1min PROVIDER=pubsub /bin/bash start.sh",    "run:pubsub-30min": "PROFILE=30min PROVIDER=pubsub /bin/bash start.sh",    "run:pubsub-3hour": "PROFILE=3hour PROVIDER=pubsub /bin/bash start.sh",    "run:system-1min": "PROFILE=1min PROVIDER=system /bin/bash start.sh",    "run:system-30min": "PROFILE=30min PROVIDER=system /bin/bash start.sh",    "run:system-3hour": "PROFILE=3hour PROVIDER=system /bin/bash start.sh"  }}

6. And finally, a query for upgrading to the business plan:

db.apps.update({_id:'TheIdYouCanSeeInTheUrlInKadiraUI'},{$set:{plan:'business', pricingType: 'paid'}})

UPD 01.02.2018:

7. Recently we were updating and rebooting our servers, so after running all the required services I found out that the data is being sent, but not shown on the dashboard. The problem was in kadira-rma: its command for executing mongo aggregation scripts was missing mongodb:// so the lines from #52 would look like this:

if [ -z ${START_TIME+x} ] || [ -z ${END_TIME+x} ]; thenmongo mongodb://$(pick-mongo-primary $MONGO_METRICS_URL) profiles/$PROFILE.js providers/$PROVIDER.js $ENV_FILE_NAME lib.js mapreduce.js incremental-aggregation.js;elsemongo mongodb://$(pick-mongo-primary $MONGO_METRICS_URL) profiles/$PROFILE.js providers/$PROVIDER.js $ENV_FILE_NAME lib.js mapreduce.js batch-aggregation.js;fi

And that’s pretty much it, you should have a working installation by now. If you experience any more problems — please let us know in the comments. The article will be extended.

--

--