Monitor PostgreSQL queries, indexes, memory, connections and more

While working on enterprise applications, many times it happen that queries that seem to be working normally on Staging environment turn out to be slower on production.

Monitoring slow performing queries and optimising them is a continues process in case of growing enterprise applications.

If you are using PostgreSQL in your Rails application, you can use pghero gem to monitor query performance & health of the database server by integrating its interactive Dashboard.


It uses pg_stat_statements module of PostgreSQL to fetch query stats directly from database source & shares insights on the… REST API Integration to push data to salesforce

This article is the first part of Salesforce Integration series and it focuses on Salesforce’s REST API integration, to push data from application to salesforce, with Rails (4.2) application.

In this article, we’re going to cover below topics -

  • Setup Developer edition account
  • Get Salesforce application credentials
  • Create Rails application
  • REST API Integration using restforce gem

Sample App

Setup Developer edition account

Use link to get your developer edition account. Developer edition account comes with only one environment — production. It does not feature Sandbox or Test environment.

To use REST API to integrate…

It’s good to keep your code maintainable & optimized, especially while working with large enterprise applications.

Growing application codebase demands continuous refactoring in terms of making it more efficient.

Here is a quick guide on the usage of a couple of gems that can help to automate process of identifying instances in codebase where database queries can be optimized. It’s advisable to use them in development environment.

Gem: lol_dba

This gem can be used to find list of database columns that can be Indexed.

Add gem in Gemfile

group :development do  
gem 'lol_dba'

Install bundle

$ bundle install

Run below rake…

Monitor Disk Space & Memory usage for Linux based EC2 instances

AWS CloudWatch is a resource & application monitoring service for AWS resources. It allows you to have visibility in the resource utilization, performance and traffic load demand patterns as it collects and tracks metrics. Also CloudWatch alarms send notifications when specific metric thresholds are breached.

CloudWatch default metrics collection includes CPU Utilization, Network traffic, and disk read/writes. It does not include metrics to monitor Disk space & Memory usage.

AWS provides CloudWatch monitoring scripts that can be configured on the Linux based EC2 instances to send Custom Metrics to CloudWatch.

These monitoring scripts are intended for use with Amazon EC2…

exception_notification gem provides support to send notifications to development team when an exception occurs in Rails application.

The built-in notifiers can deliver notifications by email, Campfire, HipChat, Slack, Mattermost, IRC or via custom WebHooks.

This tutorial explains how user can use Slack with exception_notification as a notifier.

Sample Application


  • Create a channel named “exceptions”(or other relevant name) in your Slack account
  • Get Web Hook URL for your Slack account — click here

Add below listed gems in your Gemfile

gem ‘exception_notification’gem ‘slack-notifier’

Install bundle

bundle install

Integrate notifier in your app

  • Add below code in file /config/environments/staging.rb
config.middleware.use ExceptionNotification::Rack,  
slack: {
webhook_url: "https://YOUR-SLACK-WEB-HOOK-URL",
channel: "#exceptions"…

This tutorial covers how you can launch EC2 & RDS instances on AWS, setup environment on EC2 & deploy your rails application (manually) from your GitHub repository.


  • A sample Rails 4 app
  • GitHub account
  • AWS (free tier) account

Technology stack

Ruby 2.1.2, Rails 4.1, RVM, Phusion Passenger, Nginx, Ubuntu 14.04, MySql, GitHub, AWS(EC2, RDS, ElasticIP, AMI)

Configure Staging environment in your Rails application

In this tutorial, we’ll deploy Rails app on AWS and will run inStaging environment. Hence, we need to do below listed changes in our rails app to enable Staging environment.

  • Update database.yml
  • Add section “staging
  • We’ll update it with valid details later in this tutorial
  • Add…

Rutvij Pandya

Full-stack Ruby on Rails Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store