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 / 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
Christians-MacBook-Air:nyc_traffic_accidents acd$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'puppetlabs/ubuntu-14.04-64-puppet' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'puppetlabs/ubuntu-14.04-64-puppet'
default: URL: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-puppet
==> default: Adding box 'puppetlabs/ubuntu-14.04-64-puppet' (v0.3.0) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-puppet/version/3/provider/virtualbox.box
==> default: Successfully added box 'puppetlabs/ubuntu-14.04-64-puppet' (v0.3.0) for 'virtualbox'!
@cdahlqvist
cdahlqvist / gist:96d0d132c5586229345e
Last active August 29, 2015 14:19
GeoShape example
# Add mapping
curl -XPUT localhost:9200/restaurants -d '{
"mappings": {
"areas": {
"properties": {
"name": {
"type": "string"
},
"area": {
"type": "string"
var http = require('http');
var fs = require('fs');
var optimist = require('optimist')
.usage('Simple web server to log incoming requests.\n\nUsage: $0 [options]')
.options({
file: {
alias: 'f',
describe: 'Path of file to log to. Server will log to stdout if no file specified.'
},
curl -XPOST http://localhost:9200/test/test -d'{
"title": "one",
"total": 10
}'
curl -XPOST http://localhost:9200/test/test -d'{
"title": "one",
"total": 10
}'
@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