Meteor - Kadira


What is Kadira?

Kadira is a performance monitoring service. It allows us to see performance bottlenecks.

How can we use Kadira?

meteor add kadira:debug

How can we use kadira:debug?

First, add it to our application:

meteor add kadira:debug

Then, visit and connect to the app by entering your app's URL. Now interact with your app. While you are using your app, you can see all the stuff happening inside your app. In the "Activities" section you can see all the events, including method call, subscriptions, and UI activities. In the "Timeline" sections you can see all the interactions with the server as a timeline. You can learn more about Kadira Debug from here.

Now it's time for a simple task:

  1. Add a todo to the list.
  2. Find out the method that created your todo item.
  3. Then find out the collection where your todo item lands.

You can see the methods on the EventStream—click on the method call to see the traces. In the traces, you can find the information you're looking for.

You can click on the bars on the timeline and look at the trace.

What is Kadira APM?

Kadira Debug is very useful while you are developing your app. As you play around with your app, you can see potential issues and fix them. But when your app is running in production, it's a different story. You have a lot of people using your app and you need to monitor it differently and summarize all the activities. That's where Kadira APM will help you. With Kadira APM you can both see an overview of your app and drill down to specific areas to find out what's happening with a particular issue.

How can we use Kadira APM?

  1. First, create an app on Kadira: visit
  2. Then you'll get an AppId and AppSecret.
  3. meteor add meteorhacks:kadira
  4. Then add the following content to a file called server/kadira.js:
Kadira.connect("<appId>", "<appSecret>");

You'll have to wait about a minute to see the data on the Kadira UI because of the way Kadira aggregates. Once the data is visible, try answering the following question (Click "Dashboards" and then click "Pub/Sub”):

"meteor_autoupdate_clientVersions" is an internal publication used in every Meteor app. That's why Kadira shows it, even if you haven't created it explicitly.

You can learn more about Kadira from Kadira Academy

How can we analyze CPU usage?

meteor add meteorhacks:kadira-profiler

To take a CPU profile locally, you need to run your Meteor app with the KADIRA_PROFILE_LOCALLY environment variable. Apply the following code in your terminal:

// Mac/Linux

// Windows

Then load your app on the browser and open the browser console. Now apply the following code:

// Mac / Linux
Kadira.profileCpu(10, '/tmp/myapp.cpuprofile');

// Windows
Kadira.profileCpu(10, 'C:\\myapp.cpuprofile');

Kadira will start profiling the CPU for 10 seconds and save it to the path we've specified. You can change the arguments of Kadira.profileCpu as needed, but it's not a good idea to profile for longer than five minutes.

Goto to Kadira Debug and load the CPU profile.

You should be able to see the CPU usage spent on major actions like “initial DB querying” and CPU usage by different packages. You can also look at the CPU usage breakdown using "Costly Functions" and "Costly Entrypoints" by changing the "Sorted By" dropdown.

Learn more about CPU profiling:

If you have a paid Kadira account, you can also profile your production apps remotely.

Now click the first item in the breakdown. In this case, it is "Initial DB Quering (with oplog)." You'll get a new graph on the right, a flamegraph.

We'll learn more about flamegraphs when we are talking about advanced CPU profiling. For now, you can learn more about flamegraphs here.

Refer to the following articles as well:


How can we debug a slow production application using Kadira?

If your users are complaining about slowness in your app, that's your worst day. Most of the time, you can reproduce these slowdowns if you have access to the production data locally. At Kadira, we have some ways to run the app locally with the production database. We use this technique in some extreme cases to find issues that are hard to replicate with the local data.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License