Skip to content

Instantly share code, notes, and snippets.

@saintc0d3r
saintc0d3r / index.html
Created August 5, 2014 13:38
[Zurb] Basic HTML Template
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{mainTitle}}</title>
<link rel="stylesheet" href="assets/css/foundation.css" />
<script src="assets/js/vendor/modernizr.js"></script>
</head>
<body>
@saintc0d3r
saintc0d3r / mms_recommended_alerts.txt
Last active August 29, 2015 14:04
[MongoDb][MMS] Recommended Alerts in MMS
@saintc0d3r
saintc0d3r / mms_ retlated_stats.txt
Created July 19, 2014 07:14
[MongoDb][MMS] Stats that related one to another
1. opcounter, locks% (e.g. Bulk operations would results in high Locks % but low opcounter)
2. Lock%, journal stats%, flush average
3. Non-mapped virtual memory, connections
4. Cursors, connection.
@saintc0d3r
saintc0d3r / remove_warnings_host_open_files_limit.txt
Created July 19, 2014 04:54
[MongoDb][MMS] HOW TO - Remove warning 'Host has low open files limit' on MMS->Hosts page
1. Display the list of ports used by running mongod through running this command:
ps aux | grep mongod
2. Make notes the port number of mongod process for each replica set's node.
3. Open the mongod's process limits file using text editor like cat or vim as shown in this following command:
vim /proc/<the mongod's port number noted in pror step>/limits
4. Notice 'Max processes' & 'Max open files' entries in the file. Their values should like 1024. At next step, we are going to increase those values. We could also check current limits settings through running this comand: ulimit -a
5. Open /etc/security/limits.conf file using text editor apps as root and add these following entries in the file then save the changes:
* hard nofile 64000
* soft nofile 64000
6. Logout from current session then relogin.
@saintc0d3r
saintc0d3r / 01_insert.js
Last active August 29, 2015 14:03
[MongoDb][Node.js] Create-Retrieve-Update-Delete (CRUD) in mongodb
/**
* A Simple demonstration of documents inserts against mongodb replica set
*/
var MongoClient = require('mongodb').MongoClient,
assert=require('assert');
var connection_string = "mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/pcshop";
console.log("[INFO] - Connecting to "+connection_string+" ...");
MongoClient.connect(connection_string, function(err, db){
if (err) throw err;
@saintc0d3r
saintc0d3r / 01_init_sharded_env.sh
Last active August 29, 2015 14:03
[MongoDb][Bash] Create & Initialise MongoDb Shardings
# NOTES: Adjust replSet, dbpath, port parameters as you see them fit on your system environments.
# Supposed, by default, we want to create a shardings environment where it made up from 2 replica set & each replica set is made up form 3 nodes.
# Step #1: Create & Configure replica set for shard 0
# Creates data directories for 3 mongod servers (rs_01, rs_02, rs_03)
rm -rf *.log
rm -rf ~/MongoDatabase/shard_0/rs_01 ~/MongoDatabase/shard_0/rs_02 ~/MongoDatabase/shard_0/rs_03
mkdir -p ~/MongoDatabase/shard_0/rs_01 ~/MongoDatabase/shard_0/rs_02 ~/MongoDatabase/shard_0/rs_03
@saintc0d3r
saintc0d3r / read_preference.js
Created July 13, 2014 06:54
[MongoDb][Node.js] A simple demo of read preference settings when reading documents from a replica set
/**
* A sample demo to demonstrate Read Preference settings when reading data from a replica set.
* Instructions:
* 1. Run your replica set servers.
* 2. Run this app (note: adjust the replica set's hosts & ports as you see them fit in your environments.)
* 3. Shutdown your replica set's primary node.
* 4. Watch the outputs of this running app. Confirm that the findOne were defered ( no errors being throws) when the primary node is downed and
* then come up again after a new primary node is elected in the replica set.
*/
@saintc0d3r
saintc0d3r / write_concerns.js
Created July 13, 2014 04:07
[MongoDb][Node.js] A simple demo of write concern settings when inserting documents on a replica set
/**
* Simple code to demonstrate write concerns setting when inserting documents into replica set.
* Run this command to install required dependency, in this source code's directory: npm install mongodb
*/
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
// Notice the url query string in the below connection string to replica set. We define write concern = 1 as the default write concern setting.
// w=1 means, the driver would returns success once a document has been successfully inserted into the Primary Node.
@saintc0d3r
saintc0d3r / failover_insert_demo.js
Last active August 29, 2015 14:03
[MongoDb][Node.js] A simple demo to demonstrate Mongodb Replica Set's failover capability.
/**
* A sample demo to demonstrate Mongodb Replica Set's failover capability.
* Instructions:
* 1. Run your replica set servers.
* 2. Run this app (note: adjust the replica set's hosts & ports as you see them fit in your environments.)
* 3. Shutdown your replica set's primary node.
* 4. Watch the outputs of this running app. Confirm that the inserts are defered ( no errors being throws) when the primary node is downed and
* then come up again after a new primary node is elected in the replica set.
*/
@saintc0d3r
saintc0d3r / crud_replica_set.js
Last active August 29, 2015 14:03
[MongoDb][Node.js] Simple CRUD Demo against a Replica sets ( Raid-1, master-slaves cluster)
/**
* Simple code to demonstrate CRUD function on a document against an replica set.
* Run this command in this source code's directory to install required dependency: npm install mongodb
*/
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
// Notice that the difference of connection string for connecting to a replica set and a single mongodb server,
var connection_string = "mongodb://127.0.0.1:27018, 127.0.0.1:27019, 127.0.0.1:27020/restaurant";