How to add Riak_Control to a custom Riak _Core application

Riak_Core is Erlang based implementation of Amazon Dynamo model written and open-sourced by Basho.  As everything written by Basho this framework is super awesome and hugely beneficial for anyone who is interested in writing distributed applications. It abstracts away tons of complicated issues which are typical for any distributed system.

In my opinion Riak_Core provides a next level of abstraction on top of Erlang OTP and makes it relatively straightforward to  build a project if you have a task fitting nicely into masterless, distributed model, which is what Dynamo model gives you.

Riak_Control is an application which provides a Web GUI dashboard for Riak.  It allows to monitor the health of Riak Ring, add / remove nodes and is basic and useful management tool for Riak.

Riak_Control is a generic app and could be used for any Riak_Core based system. To integrate it with your own app you just need to change few configuration settings:

First add riak_control and riak_api into your rebar.config:

{riak_control, ".*", {git, "https://github.com/basho/riak_control.git", {tag, "2.1"}}},
{riak_api, ".*", {git, "https://github.com/basho/riak_api.git", {tag, "2.1"}}}

riak_control uses mochiweb and webmachine so these dependencies will be pulled automatically. It would be very nice if Basho allowed the users to choose what webserver to use (I would much rather prefer to use Cowboy because it also gives you websockets which are missing in mochiweb) but currently it is not an option.

Add these apps to your application manifest so they could be auto-started before your app starts:

{applications, [
 kernel,
 stdlib,
 lager,
 mochiweb,
 webmachine,
 riak_api,
 riak_core,
 riak_control
 ]},

Add entries for riak_api and riak_control into your app config file:

 {riak_api,
  [
   %% Other configs
   {http,[{"127.0.0.1", 8199}]}
  ]},

 {riak_control, [
                 {enabled, true}
                ]},

and this is it.

When you build a release for your app and start it (either on a single node or multiple nodes) you should be able to go to the link http://localhost:8199/admin#/cluster and see something like this:

Screen Shot 2015-08-21 at 21.29.34

You now can use this dashboard to add / remove nodes for your app, which is very convenient.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to How to add Riak_Control to a custom Riak _Core application

  1. Pingback: How does Riak_Core ring distributes vnodes | R.Shestakov

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s