<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MongoDB on dwmkerr.com</title><link>https://dwmkerr.com/categories/mongodb/</link><description>Recent content in MongoDB on dwmkerr.com</description><generator>Hugo -- gohugo.io</generator><language>en-uk</language><managingEditor>Dave Kerr</managingEditor><copyright>Copright &amp;copy; Dave Kerr</copyright><lastBuildDate>Wed, 16 May 2018 20:09:53 +0000</lastBuildDate><atom:link href="https://dwmkerr.com/categories/mongodb/index.xml" rel="self" type="application/rss+xml"/><item><title>mongo-monitor - a simple CLI to monitor your MongoDB cluster</title><link>https://dwmkerr.com/mongo-monitor-cli/</link><pubDate>Wed, 16 May 2018 20:09:53 +0000</pubDate><guid>https://dwmkerr.com/mongo-monitor-cli/</guid><description>&lt;p&gt;The &lt;code&gt;mongo-monitor&lt;/code&gt; CLI is a lean and simple tool to check the status of a MongoDB server or cluster. The code is on GitHub:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/dwmkerr/mongo-monitor"&gt;github.com/dwmkerr/mongo-monitor&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s how it looks in action:&lt;/p&gt;
&lt;p&gt;&lt;img src="images/overview.gif" alt="Screenshot: Using the mongo-monitor CLI to monitor a sharded cluster"&gt;&lt;/p&gt;
&lt;p&gt;In this animation I am monitoring a simple sharded cluster, and running some example maintenance operations, adding a node to a replicaset, stepping down a primary and shutting down a replicaset node.&lt;/p&gt;
&lt;p&gt;A simple CLI which shows the status in real-time can be very useful to keep open when performing admin, letting you see how your changes affect the cluster as you work on it.&lt;/p&gt;
&lt;h2 id="installing-the-cli"&gt;Installing the CLI&lt;/h2&gt;
&lt;p&gt;The CLI is installed with &lt;code&gt;npm&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;npm install -g mongo-monitor
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="connecting-to-a-cluster"&gt;Connecting to a Cluster&lt;/h2&gt;
&lt;p&gt;Connect to a cluster by providing a connection string. The tool uses &lt;a href="https://github.com/dwmkerr/mongo-connection-string"&gt;&lt;code&gt;mongo-connection-string&lt;/code&gt;&lt;/a&gt; to parse the connection string, so you can be flexible with the input:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Connect to a local instance&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;mongo-monitor localhost:27107
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Connect to a remote replicaset, authenticated&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;mongo-monitor admin:P@sswrd@mdbnode1,mdbnode2,mdbnode3?replicaSet&lt;span style="color:#f92672"&gt;=&lt;/span&gt;rs
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once a connection is established, the tool will periodically check the status of the cluster. If the cluster is sharded, it will also inspect each individual replicaset.&lt;/p&gt;
&lt;h2 id="replicaset-status"&gt;Replicaset Status&lt;/h2&gt;
&lt;p&gt;Here&amp;rsquo;s the kind of output you might get from a replicaset:&lt;/p&gt;
&lt;p&gt;&lt;img src="images/replicaset.jpg" alt="Screenshot: Replicaset Status"&gt;&lt;/p&gt;
&lt;p&gt;The name of the replicaset is shown, along with each member. The status of each member is also shown, updating automatically every second.&lt;/p&gt;
&lt;p&gt;This is convenient when administering replicasets, stepping down a master, adding or removing nodes and so on.&lt;/p&gt;
&lt;h2 id="sharded-cluster-status"&gt;Sharded Cluster Status&lt;/h2&gt;
&lt;p&gt;When connecting to a sharded cluster, you will get output like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="images/sharded-cluster.jpg" alt="Screenshot: Sharded Cluster Status"&gt;&lt;/p&gt;
&lt;p&gt;Each shard is shown, along with the details of the replicaset which make it up.&lt;/p&gt;
&lt;p&gt;Keeping a view like this open is useful when administering sharded clusters, adding or removing shards, desharding, updating the replicasets which make up shards and so on.&lt;/p&gt;
&lt;h2 id="get-involved"&gt;Get Involved!&lt;/h2&gt;
&lt;p&gt;If you like the tool, check out the code and feel free to make pull requests with additions! There are a few &lt;a href="https://github.com/dwmkerr/mongo-monitor/issues"&gt;issues&lt;/a&gt; on the project already, and there are all sorts of features I&amp;rsquo;d love to add but haven&amp;rsquo;t had the time, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Being able to see the lag for replicaset members, to see if secondaries are falling behind&lt;/li&gt;
&lt;li&gt;Being able to perform replicaset operations directly from the tool&lt;/li&gt;
&lt;li&gt;Showing the priorities of nodes if they are not the default&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All ideas are welcome, let me know in the comments or repo, and share the tool if you find it useful!&lt;/p&gt;</description><category>CodeProject</category></item><item><title>Failures Connecting from Elastic Beanstalk servers to MongoDB on EC?</title><link>https://dwmkerr.com/failures-connecting-from-elastic-beanstalk-servers-to-mongodb-on-ec/</link><pubDate>Mon, 16 Mar 2015 10:34:04 +0000</pubDate><guid>https://dwmkerr.com/failures-connecting-from-elastic-beanstalk-servers-to-mongodb-on-ec/</guid><description>&lt;p&gt;tl;dr?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Check your mongodb.conf &lt;code&gt;bind_ip&lt;/code&gt; settings to make sure that you&amp;rsquo;re not allowing connections only from localhost.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This may just end up being the first part of a wider troubleshooting guide, but this is one I&amp;rsquo;ve spent a few hours fixing, after assuming I was making terrible mistakes with my security groups.&lt;/p&gt;
&lt;p&gt;If you find you cannot connect to your MongoDB server from an EB app server (or anything for that matter), before you spend ages checking your Elastic IP, VPC and Security Group config, don&amp;rsquo;t forget that you may have simply used &lt;code&gt;bind_ip&lt;/code&gt; in your config file.&lt;/p&gt;
&lt;p&gt;Check for:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;bind_ip = 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Comment it out or remove it and restart:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;service mongod restart
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Don&amp;rsquo;t forget to make sure your firewall is still set up correctly - only allow connections from IPs or even better other security groups you trust.&lt;/p&gt;</description><category>CodeProject</category></item></channel></rss>