This document helps you troubleshoot a Countly instance, especially when you have a problem with Linux instance, MongoDB, processes or Countly application service itself.

Countly memory management in general

  • As a general rule of thumb, you should do your planning based on 5M data points per core, and 4GB of RAM for each core for standalone (Countly + MongoDB) servers. Contact us if you want to use HA and replica sets and we'll be happy to provide you a server topology.

  • Countly forks a child process for each available core in the system so a 6 core system will run 6 Countly API nodes. Each will use around 2GB RAM max.

  • MongoDB engine uses a mix of in RAM storage and filesystem. RAM is preferable to MongoDB, and to achieve that, MongoDB will try to store the "working set" (documents that were accessed recently) in memory. If you don't see Countly server using all the RAM, this is why it won't always use the entire available RAM in the system, it'll use what it needs at that time.

  • If you have page fault monitoring in your instance, you'll see an increased number of page faults if RAM is not enough for MongoDB to store the working set in memory - which means MongoDB is doing file operations which will be drastically slow.

  • For Digital Ocean: Standard droplet types in DO are less performant compared to General Purpose (or CPU-Optimized or the new Memory Optimized) ones as stated in their web interface. Basically, a Standard 16GB/6-core instance will noticeably be less performant than a General Purpose 16GB/4-core one.

Checking disk space

df -kh

Checking resource usage

vmstat 1

free -m

#by process

Checking if process was killed by system

Sometimes you can't find in the logs why process was killed, as it just exited. You can check here if process was killed because, for example, server run out of memory

dmesg | tail


tail /var/log/kern.log -n 1000


tail /var/log/syslog -n 1000

Getting Countly version

countly version

Or if command line does not work

#run inside countly dir
cat package.json

Getting Countly installation directory

countly dir

or switching to Countly directory

cd `countly dir`

if Countly command line does not work

#if running on systemd
cat /etc/systemd/system/countly.service

#if running on upstart
cat /etc/init/countly-supervisor.conf

Enabling Countly command line if it's not available

#run inside countly dir
bash bin/scripts/

Checking if Countly is running

countly status

Checking Countly logs

#run inside countly dir

#get latest 500 lines of api log
tail log/countly-api.log -n 500

#get latest 500 lines of dashboard log
tail log/countly-dashboard.log -n 500

Restarting Countly

#simply restart process
countly restart

#regenerate production files, install mising dependencies and restart process
countly upgrade

Checking and removing ghost processes

In rare cases, if a Countly process is stuck and you may want to kill and restart Countly.

# check current processes (should contain node or nodejs processes for countly)

#stop countly
countly stop

#recheck if still has node or nodejs processes

#if has them, kill them
pkill node

#start countly
countly start

Checking Countly http access without nginx

#checking if dashboard process runs (should return webpage)
wget -O-

#checking if api process runs (should return 400 Bad request)
wget -O-

Checking port connections

#checking amount of connections to mongodb (assuming default port 27017)
sudo netstat -nputw | grep 27017 | wc -l

Checking connection to database

#connects to db, gets document with configurations and outputs them
countly config list values

Increasing Countly limits

Limits for the process are managed by init system, so you need to change values in their config files which are

#if running on systemd
cat /etc/systemd/system/countly.service

#if running on upstart
cat /etc/init/countly-supervisor.conf

Adding a user to dashboard

#adds global admin from command line
countly add_user <username> <password>

#and then when not needed anymore to remove
countly remove_user <username> <password>

Clearing failed login time

#connect to mongo

#or use required parameters based on your mongodb setup

use countly

Checking MongoDB version

mongod --version

Checking if mongod process is running

It should also reveal path to config file.

ps -ax | grep mongo

Starting mongod process

#starting MongoDB

systemctl start mongod

start mongod

#centos/rhel 6
service mongod start

Restarting MongoDB process

#restarting MongoDB on

systemctl restart mongod

restart mongod

#centos/rhel 6
service mongod restart

Checking MongoDB logs

#default log path is /var/log/mongodb/mongod.log or check in mongod.conf file for systemLog.path
#config file is usually at/etc/mongod.conf or check if process running to get path
tail /var/log/mongodb/mongod.log -n 500

Connecting to MongoDB

#In simple case if mongodb is on the same server its just
mongo `countly mongo`

#if port is changed to for example 111222
mongo --port 111222

#if it is on another server, for example
mongo --host

#if it is behind authentication
mongo --username <username> --password <password> --authenticationDatabase <dbname>

#if it is through ssl
mongo --ssl --sslAllowInvalidCertificates

#if it is replica set
mongo --host <replSetName>/<hostname1><:port>,<hostname2><:port>,<...>

Checking how Countly connects to MongoDB

#run on countly server inside countly directory
cat api/config.js

#or establish mongo shell connection (requires mongodb tools on Countly server) 
#using Countly connection data

mongo `countly mongo` 

Checking current/allowed connections

#connect to mongodb

#or some other connect approach depending on your mongodb configuration

#output connections info

 Check how many connections are listening to a specific port

ss -a | grep ESTAB | grep 65017 | sed 's/   / /g' | sed 's/   / /g' | cut -d' ' -f 11 | cut -d':' -f1 | sort | uniq -c

Checking current reads and writes


#or use correct params (from connecting to mongodb) based on your mongodb configuration
#press Ctrl+C to exit

If reads and writes are quite long (longer than 10 seconds), your MongoDB instance might be overutilized and need to be scaled.

To check which reads or writes exactly are the longest (adjust running seconds based on the longest time in mongotop)

db.currentOp({"secs_running": {$gte: 10}})

Checking currently used resources


#or use correct params (from connecting to mongodb) based on your mongodb configuration
#press Ctrl+C to exit

If, for example, there are lots of memory faults, it would mean the memory is being swapped and MongoDB would require more RAM to speed up queries.

Checking replica set status

#connect to mongodb

#or use some correct parameters depending on your mongodb configuration

#output replica set status

#check how much secondary is behind the primary

#check oplog window (in which secondary must catch up with primary)

Checking process limits

First you need to create script that checks the limits

if [ "$#" -ne "1" ]; then
   echo ""
   echo -e "\033[01;32mLimit checker\033[00m"
   echo -e "\033[01;37mUsage:\033[01;33m $0 process_name\033[00m"
   echo ""
   exit 0

   for process in $@; do
      process_pids=`ps -C $process -o pid --no-headers | cut -d " " -f 2`

      if [ -z $@ ]; then
         echo "[no $process running]"
         for pid in $process_pids; do
            echo "[$process #$pid -- limits]"
            cat /proc/$pid/limits

return-limits $1

Then you can use it as

mongoserver041 ~ $ ./ mongod
[mongod #43447 -- limits]
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            10485760             unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             32000                32000                processes
Max open files            1000000              1000000              files
Max locked memory         65536                unlimited            bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       125029               125029               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Increasing MongoDB limits

To maximize system limits for MongoDB, we suggest two-step configuration.

1. For system-wide limits, /etc/sysctl.conf

fs.file-max = 392000
kernel.pid_max = 256000
kernel.threads-max = 256000
vm.max_map_count = 512000

2. For the user of MongoDB service limits, /etc/security/limits.conf

{MONGODB_USER} soft nproc 256000
{MONGODB_USER} hard nproc 256000
{MONGODB_USER} soft nofile 392000
{MONGODB_USER} hard nofile 392000

To get MongoDB user's name:

grep mongod /etc/passwd | awk -F':' '{print $1}'

Re-indexing data

In some cases (due to data transfers or concurrency) some index may be missing. If you think this is a case, you can run reindexing scripts, which will add all missing indexes. It is completely safe to run and rerun it multiple times

#go to countly directory
cd `countly dir`

#run script to add missing core indexes
node bin/scripts/add_indexes.js

#if you are on enterprise edition, you should also reindex granualr data
node plugins/drill/update_index.js 

This script runs in serial with least effect on performance, but note that on large data, this process may take multiple hours. To check the progress of the index that is currently added you can run this command:

db.currentOp(true).inprog.forEach(function(op){ if(op.msg) print(op.msg) }) 

Debugging and troubleshooting incoming SDK requests

If you would like to understand why data is not arriving to Countly server, or why you see partial data, check this FAQ item to troubleshoot further.

Checking if 3rd party email service functions correctly

  1. Got to Management > Email reports and create a new report.
  2. Press preview button, to make sure there is data to report and all is showing correctly.
  3. Optionally, clear the logs in Countly, specifically the countly/log/countly-api.log file.
  4. Press send now to send report to your provided email address.
  5. If no error in the log, it usually means e-mail has left the server. It is not possible for us to track it further.
  6. Check if the e-mail has arrived. There may be cues in your 3rd party service about this particular transaction.
Was this article helpful?
0 out of 0 found this helpful

Looking for help?