Skip to content

Instantly share code, notes, and snippets.

@markshust
Last active June 11, 2020 02:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markshust/f62971af00abf513012e016083909c1e to your computer and use it in GitHub Desktop.
Save markshust/f62971af00abf513012e016083909c1e to your computer and use it in GitHub Desktop.
Kadira APM Setup

Kadira APM Setup

Short guide on how to get Kadira APM setup with Docker.

  1. Setup at least on instance with 1.7GB RAM.
  2. Open up firewall ports for inbound TCP port 443. Also open up 11011 & 4000 for debugging. Port 11011 is kadira-engine, port 4000 is the kadira-ui.
  3. Setup a Mongo database, and have the connection string ready (with username and password).
  4. Install Docker https://docs.docker.com/engine/installation/linux/docker-ce/debian/ , run sudo usermod -aG docker your-user, then install Docker Compose https://docs.docker.com/compose/install/ on the instance.
  5. Verify that you have docker and docker compose installed correctly and can use it.
  6. Setup A-records to point your kadira-ip to kadira-engine.domain.com and kadira-ui.domain.com.
  7. Setup a new file named .env with the contents:
MONGO_URL=mongodb://user:pass@host:27017/db
NGINX_FILES_PATH=/home/your-username/nginx
  1. Download this file to use as a template: curl https://gist.githubusercontent.com/markoshust/46a0acad8f828328786b3a6396de0617/raw/68c8232a1b80885b151c5bfb82d4e126d32a2f9c/docker-compose.yml > docker-compose.yml
  2. Download the nginx template file:
curl https://raw.githubusercontent.com/jwilder/nginx-proxy/master/nginx.tmpl > nginx.tmpl
  1. Run docker-compose run nginx-letsencrypt to generate an SSL secret. This step may take a few minutes to complete.
  2. Run docker-compose up to start. This will also generate any needed SSL certs at runtime.
  3. Check for errors in the console output, there shouldn't be any. It may take a little bit to initially startup the containers. When complete you can access your kadira-ui at https://kadira-ui.domain.com.
  4. Login with username admin@gmail.com and password admin. Change your admin password. Setup a new project for the domain you want to monitor to get your API keys.
  5. To connect your meteor app with a custom endpoint, set these env vars (change kadira-engine.domain.com to your kadira instance url):
KADIRA_APP_ID=your-app-id
KADIRA_APP_SECRET=your-app-secret
KADIRA_OPTIONS_ENDPOINT=https://kadira-engine.domain.com

or with Meteor settings:

{
  "kadira": { 
    "appId": "your-app-id", 
    "appSecret": "your-app-secret",
    "options": {
      "endpoint": "https://kadira-engine.domain.com"
    }
  }
}
  1. Connect to the database and open the apps table. Update your app account to "plan": "business" to unlock all features for that account. Also add "plan": "business" to your record in the users table.
  2. Kadira uses quite a bit of disk space, so it's a good idea to have a pruning script to remove stale records. For example, prune out everything before August 15, 2017, use the following queries:
db.getCollection('prodStats').remove({"time": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('pubMetrics').remove({"_id.time": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('pubTraces').remove({"startTime": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('rawErrorMetrics').remove({"value.startTime": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('rawMethodsMetrics').remove({"value.startTime": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('rawPubMetrics').remove({"value.startTime": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('rawSystemMetrics').remove({"value.startTime": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('rmaLogs').remove({"startedAt": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
db.getCollection('systemMetrics').remove({"_id.time": {"$lte": new ISODate("2017-08-15T00:00:00.000Z")}})
@jasongrishkoff
Copy link

I've been encountering the disk issue you reference in #15 -- causing my instance to basically choke up. Any tips on how to implement that as a cronjob script on linux?

@crapthings
Copy link

crapthings commented Aug 28, 2017

how long it takes to finish 10 ?

i stuck here

2017/08/28 06:30:44 Contents of /app/letsencrypt_service_data did not change. Skipping notification '/app/update_certs'

compose log

kadira-rma_1         | [run:system-3hour ] Error: TIMEOUTED_WAIT_FOR_MONGO
kadira-rma_1         | [run:system-3hour ]     at Timeout._onTimeout (/app/node_modules/pick-mongo-primary/lib/pickMongoPrimary.js:18:14)
kadira-rma_1         | [run:system-3hour ]     at ontimeout (timers.js:386:14)
kadira-rma_1         | [run:system-3hour ]     at tryOnTimeout (timers.js:250:5)
kadira-rma_1         | [run:system-3hour ]     at Timer.listOnTimeout (timers.js:214:5)
kadira-rma_1         | [run:system-3hour ] + [ -z ]
kadira-rma_1         | [run:system-3hour ] + pick-mongo-primary mongodb://localhost:27017/db

@crapthings
Copy link

can't connect to db too

MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED]
kadira-engine_1      |     at null.<anonymous> (/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:328:35)
kadira-engine_1      |     at emit (events.js:107:17)
kadira-engine_1      |     at null.<anonymous> (/app/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:274:12)
kadira-engine_1      |     at g (events.js:199:16)
kadira-engine_1      |     at emit (events.js:110:17)
kadira-engine_1      |     at Socket.<anonymous> (/app/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:177:49)
kadira-engine_1      |     at Socket.g (events.js:199:16)
kadira-engine_1      |     at Socket.emit (events.js:107:17)
kadira-engine_1      |     at net.js:459:14
kadira-engine_1      |     at process._tickCallback (node.js:355:11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment