Skip to content

Instantly share code, notes, and snippets.

View abtreece's full-sized avatar

Britt Treece abtreece

View GitHub Profile
@bryanhuntesl
bryanhuntesl / Riak and Erlang - execute a command upon a node and print to console.md
Last active June 13, 2022 16:00
Riak and Erlang - execute a command upon a node and print to console

verify distributed Erlang working

Ping the riak node, print the response and halt the system.

erl -setcookie riak -name "${USER}-"@127.0.0.1 -noshell \
-eval "Res = net:ping('dev1@127.0.0.1'), io:put_chars(standard_error,io_lib:format(\"~p\",[Res]))." \
-eval "erlang:halt()."

As a result, pong is printed to the console, the response from the remote node, we're ready to start executing Erlang.

#!/usr/bin/env escript
%% -*- coding: utf-8 -*-
%%! -pa /usr/lib64/riak-cs/lib/riakc-1.3.1.1/ebin /usr/lib64/riak-cs/lib/riak_pb-1.3.0/ebin /usr/lib64/riak-cs/lib/protobuffs-0.8.0/ebin /usr/lib/riak-cs/lib/riakc-1.3.1.1/ebin /usr/lib/riak-cs/lib/riak_pb-1.3.0/ebin /usr/lib/riak-cs/lib/protobuffs-0.8.0/ebin /usr/lib/riak-cs/ebin
-include_lib("riak_cs/include/riak_cs.hrl").
-define(USERS_BUCKET, <<"moss.users">>).
-define(DEFAULT_RIAK_IP, "127.0.0.1").
-define(DEFAULT_RIAK_PORT, 8087).
@kellymclaughlin
kellymclaughlin / ring_examples.erl
Created September 20, 2011 16:50
Examining the Riak ring
%% Get the state for the local node
%% The get_my_ring function really returns the ring
%% plus other state information about the cluster.
{ok, State} = riak_core_ring_manager:get_my_ring().
%% Get number of partitions
riak_core_ring:num_partitions(State).
%% Get the names of custom buckets
riak_core_ring:get_buckets(State).
@jtuple
jtuple / riak_ring.erl
Created August 25, 2011 19:08
Script to print Riak ring ownership information
%% Script to print out Riak ring ownership.
%% Copy/paste into Erlang shell attached to a riak cluster (riak-admin attach).
%% Remember to use: CTRL-D to dettach from the shell once done.
fun() ->
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
Owners = riak_core_ring:all_members(Ring),
Indices = riak_core_ring:all_owners(Ring),
RingSize = length(Indices),
Names = lists:zip(Owners, lists:seq(1, length(Owners))),