Skip to content

Instantly share code, notes, and snippets.

View cdahlqvist's full-sized avatar

Christian Dahlqvist cdahlqvist

  • Independent
  • Valencia, Spain
View GitHub Profile

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} ->
#!/usr/bin/env perl
use LWP;
use HTTP::Request::Common;
my $url = "localhost:9200";
my $protocol = "http";
my $index_name_prefix = "shardtest";
my $counter = 0;
my $indexspec = '{"settings":{"index":{"number_of_shards":"100","number_of_replicas":"0"}}}';
@cdahlqvist
cdahlqvist / sample_event.json
Created August 2, 2016 15:01
sample_event_and_mapping
{
"@timestamp": "2016-01-29T16:18:30.574Z",
"referrer": "https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html",
"verb": "GET",
"request": "/assets/blt6892ef667f7c28d7/icon-elasticsearch2.svg",
"geoip": {
"location": [87.3333, 22.3333],
"country_name": "India"
},
"agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36",
@cdahlqvist
cdahlqvist / error_message.txt
Last active September 6, 2016 02:01
Issue loading index template in ES 5.0.0-alpha5
The provided index template loading script works fine on ES 5.0.0-alpha4 but fails on ES 5.0.0-alpha5 with the following error message.
[2016-09-06 02:52:45,093][WARN ][http.netty4 ] [ECKV_Vw] caught exception while handling client http traffic, closing connection [id: 0x1ecebe60, L:/127.0.0.1:9200 - R:/127.0.0.1:64769]
java.lang.UnsupportedOperationException: unsupported message type: DefaultFullHttpResponse (expected: ByteBuf, FileRegion)
at io.netty.channel.nio.AbstractNioByteChannel.filterOutboundMessage(AbstractNioByteChannel.java:260)
at io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:799)
at io.netty.channel.DefaultChannelPipeline$HeadContext.write(DefaultChannelPipeline.java:1291)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:748)
at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:811)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractCh

Code samples for X-Pack enablement

Watcher, Step 3-1

PUT _watcher/watch/manage_history
{
    "metadata": {
        "keep_history_days": 2
    },
@cdahlqvist
cdahlqvist / bulk.txt
Created September 26, 2016 12:49
ES 5.0.0-beta1 issue?
{ "index" : { "_index" : "test", "_type" : "type1" } }
{ "field1" : "value1" }
{ "create" : { "_index" : "test", "_type" : "type1" } }
{ "field1" : "value3" }
@cdahlqvist
cdahlqvist / rally_out.log
Created December 5, 2016 19:00
Rally error with custom track
[elastic@localhost rally]$ rally --pipeline=benchmark-only --target-hosts=localhost:9200 --track=elasticlogs --challenge=test
Auto-updating Rally
____ ____
/ __ \____ _/ / /_ __
/ /_/ / __ `/ / / / / /
/ _, _/ /_/ / / / /_/ /
/_/ |_|\__,_/_/_/\__, /
/____/
def triggered_time = ctx.trigger.triggered_time;
def failure_counts = new HashMap();
ctx.payload.failed_auth_users.aggregations.users.buckets.stream().map(p -> failure_counts.put(p.key,p.doc_count));
def successful_users = ctx.payload.success_auth_users.aggregations.users.buckets.stream().map(p -> p.key).collect(Collectors.toList());
def failure_only_records = ctx.payload.failed_auth_users.aggregations.users.buckets.stream().filter(p -> !successful_users.contains(p.key)).map(e -> ['@timestamp':triggered_time,'user':e.key,'severity':'MEDIUM','failed_auths':e.doc_count]).collect(Collectors.toList());