Skip to content

Instantly share code, notes, and snippets.

View cdahlqvist's full-sized avatar

Christian Dahlqvist cdahlqvist

  • Independent
  • Valencia, Spain
View GitHub Profile
@cdahlqvist
cdahlqvist / keylister.erl
Last active December 15, 2015 14:48
Script to list all keys in a Riak bucket and spool to a file. To be run while attached to riak console.
%% -------------------------------------------------------------------
%%
%% keylister: Utility for listing all keys in a bucket
%%
%% Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
@cdahlqvist
cdahlqvist / riak_graphite.erl
Last active December 16, 2015 22:08
Server process for sending statistics to Graphite from Riak
%% -------------------------------------------------------------------
%%
%% riak_graphite: Server process to emit statistics to Graphite
%%
%% Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
PBStatusFun = fun() ->
VnodePids = [Pid || {_, Pid} <- riak_core_vnode_manager:all_index_pid(riak_kv_vnode)],
Links = [process_info(Pid, [links]) || Pid <- VnodePids],
WorkerPoolPids = [WPPid || [{links,[_, WPPid]}] <- Links],
WorkerPoolLinks = [process_info(Pid, [links]) || Pid <- WorkerPoolPids],
PoolboyPids = [PoolboyPid || [{links,[_, PoolboyPid]}] <- WorkerPoolLinks],
[poolboy:status(Pid) || Pid <- PoolboyPids]
end.
PBStatusCountFun = fun() ->
@cdahlqvist
cdahlqvist / pb_status_monitor.erl
Created May 24, 2013 13:27
Process that monitors the status of the poolboy worker pool used for coverage queries.
%% -------------------------------------------------------------------
%%
%% pb_status_monitor: PoolBoy pool monitor
%%
%% Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
#!/usr/bin/env escript
%% -*- erlang -*-
-include_lib("kernel/include/file.hrl").
-compile(export_all).
-define(LOG(S), io:format(S)).
-define(LOG(S,A), io:format(S,A)).
main(Dirs) ->
CodePath = case os:getenv("RIAK_LIB") of

This is an erlang snippet to be run from a riak attach session

After pasting the following into the attach session, to repair all riak_kv partitions, run

RepairProc = RepairAllKv(60).

or, to repair all riak_search partitions, run

RepairProc = RepairAllSearch(60).
-module(robin_handoff).
-export([start/0,start/1,start/2,stop/0]).
-export([step/0]).
%% see if a handoff is in progress
active_count(Node) when is_atom(Node) ->
Receivers=rpc:call(Node,supervisor,count_children,[riak_core_handoff_receiver_sup]),
#!/usr/bin/env escript
main(Args) ->
% - From nodetool ------------------------------------------------------- %
{_, TargetNode} = process_args(Args, [], undefined),
case {net_kernel:connect_node(TargetNode), net_adm:ping(TargetNode)} of
{true, pong} ->
Start a Riak 2.0 cluster. This has been tested against Riak 2.0.0pre11.
First set up bucket types (note you can name these as you like for your domain (and add other properties)
$ rel/riak/bin/riak-admin bucket-type create maps '{"props":{"datatype":"map"}}'
maps created
$ rel/riak/bin/riak-admin bucket-type create sets '{"props":{"datatype":"set"}}'
sets created
$ rel/riak/bin/riak-admin bucket-type create counters '{"props":{"datatype":"counter"}}'
counters created
@cdahlqvist
cdahlqvist / statslogger.py
Last active August 29, 2015 14:03
Simple script that logs a set of Riak statistics to a daily CSV file once a minute
#!/usr/bin/env python
import httplib
import json
from datetime import datetime, date, time
from time import sleep
import os.path
from multiprocessing import Process