Permalink
Browse files

Finally bite the bullet and rename to statsd-server to solve the mill…

…ion namespace conflicts that occur
  • Loading branch information...
1 parent 4fb6abc commit ad20880976cc32b1b1551305d91c333e52454984 @noahhl committed Nov 30, 2011
View
@@ -0,0 +1 @@
+1.9.2-p290
View
@@ -54,9 +54,9 @@ begin
if !options[:config]
puts parser.help
else
- require 'statsd'
- require 'statsd/server'
- Statsd::Server::Daemon.new.run(options)
+ require 'statsd_server'
+ require 'statsd_server/server'
+ StatsdServer::Server::Daemon.new.run(options)
end
rescue Exception => e
if e.instance_of?(SystemExit)
@@ -1,6 +1,6 @@
require 'socket'
# encoding: utf-8
-module Statsd
+module StatsdServer
#
# Statsd::Client by Rein Henrichs -- github.com/reinh/statsd
File renamed without changes.
@@ -1,7 +1,7 @@
require 'benchmark'
gem 'eventmachine'
require 'eventmachine'
-module Statsd
+module StatsdServer
class Graphite < EM::Connection
attr_accessor :counters, :timers, :flush_interval
@@ -1,6 +1,6 @@
require 'benchmark'
require 'mongo'
-module Statsd
+module StatsdServer
class Mongo
class << self
attr_accessor :database, :hostname, :retentions, :flush_interval
@@ -1,8 +1,8 @@
require 'benchmark'
require 'redis'
-require 'statsd/redis-timeseries'
+require 'statsd_server/redis-timeseries'
-module Statsd
+module StatsdServer
class RedisStore
class << self
attr_accessor :redis, :host, :port, :flush_interval, :retentions
@@ -2,8 +2,8 @@
require 'eventmachine'
require 'yaml'
require 'erb'
-require 'statsd/graphite'
-module Statsd
+require 'statsd_server/graphite'
+module StatsdServer
module Server #< EM::Connection
FLUSH_INTERVAL = 10
@@ -49,7 +49,7 @@ def run(options)
config = YAML::load(ERB.new(IO.read(options[:config])).result)
if options[:mongo]
- require 'statsd/mongo'
+ require 'statsd_server/mongo'
# Setup retention store
db = ::Mongo::Connection.new(config['mongo_host']).db(config['mongo_database'])
config['retentions'].each do |retention|
@@ -59,27 +59,27 @@ def run(options)
end
db.collection(collection_name).ensure_index([['ts', ::Mongo::ASCENDING]])
end
- Statsd::Mongo.hostname = config['mongo_host']
- Statsd::Mongo.database = config['mongo_database']
- Statsd::Mongo.retentions = config['retentions']
- Statsd::Mongo.flush_interval = config['flush_interval']
+ StatsdServer::Mongo.hostname = config['mongo_host']
+ StatsdServer::Mongo.database = config['mongo_database']
+ StatsdServer::Mongo.retentions = config['retentions']
+ StatsdServer::Mongo.flush_interval = config['flush_interval']
end
if options[:graphite]
- require 'statsd/graphite'
+ require 'statsd_server/graphite'
end
if options[:redis]
- require 'statsd/redis_store'
+ require 'statsd_server/redis_store'
ENV["coalmine_data_path"] = config['coalmine_data_path']
- Statsd::RedisStore.host = config["redis_host"]
- Statsd::RedisStore.port = config["redis_port"]
- Statsd::RedisStore.flush_interval = config['flush_interval']
- Statsd::RedisStore.retentions = config['redis_retention'].split(',')
+ StatsdServer::RedisStore.host = config["redis_host"]
+ StatsdServer::RedisStore.port = config["redis_port"]
+ StatsdServer::RedisStore.flush_interval = config['flush_interval']
+ StatsdServer::RedisStore.retentions = config['redis_retention'].split(',')
end
if options[:simpledb]
- require 'statsd/simpledb_store'
+ require 'statsd_server/simpledb_store'
Statsd::SimpleDBStore.timestep = config["key_size"].to_i
ENV['AMAZON_ACCESS_KEY_ID'] = config["aws_access_key"] if ENV["AMAZON_ACCESS_KEY_ID"].nil?
ENV['AMAZON_SECRET_ACCESS_KEY'] = config["aws_access_key_secret"] if ENV["AMAZON_SECRET_ACCESS_KEY"].nil?
@@ -88,28 +88,28 @@ def run(options)
# Start the server
EventMachine::run do
- EventMachine::open_datagram_socket(config['bind'], config['port'], Statsd::Server)
+ EventMachine::open_datagram_socket(config['bind'], config['port'], StatsdServer::Server)
# Periodically Flush
EventMachine::add_periodic_timer(config['flush_interval']) do
- counters,timers = Statsd::Server.get_and_clear_stats!
+ counters,timers = StatsdServer::Server.get_and_clear_stats!
# Flush Adapters
if options[:mongo]
- EM.defer { Statsd::Mongo.flush_stats(counters,timers) }
+ EM.defer { StatsdServer::Mongo.flush_stats(counters,timers) }
end
if options[:redis]
- EM.defer { Statsd::RedisStore.flush_stats(counters,timers) }
+ EM.defer { StatsdServer::RedisStore.flush_stats(counters,timers) }
end
if options[:simpledb]
- EM.defer { Statsd::SimpleDBStore.flush_stats(counters,timers) rescue nil }
+ EM.defer { StatsdServer::SimpleDBStore.flush_stats(counters,timers) rescue nil }
end
if options[:graphite]
- EventMachine.connect config['graphite_host'], config['graphite_port'], Statsd::Graphite do |conn|
+ EventMachine.connect config['graphite_host'], config['graphite_port'], StatsdServer::Graphite do |conn|
conn.counters = counters
conn.timers = timers
conn.flush_interval = config['flush_interval']
@@ -121,12 +121,12 @@ def run(options)
#Clean up redis zsets
if options[:redis]
EventMachine::add_periodic_timer(config['flush_interval'] * 100) do
- EM.defer {Statsd::RedisStore.cleanup }
+ EM.defer {StatsdServer::RedisStore.cleanup }
end
- Statsd::RedisStore.retentions.each_with_index do |retention, index|
+ StatsdServer::RedisStore.retentions.each_with_index do |retention, index|
unless index.zero?
EventMachine::add_periodic_timer(retention.split(":")[0].to_i) do
- EM.defer {Statsd::RedisStore.aggregate(retention)}
+ EM.defer {StatsdServer::RedisStore.aggregate(retention)}
end
end
end
@@ -1,6 +1,6 @@
require 'simpledb-timeseries'
-module Statsd
+module StatsdServer
class SimpleDBStore
class << self
File renamed without changes.
View
@@ -0,0 +1,67 @@
+#!/usr/bin/ruby
+require 'rubygems'
+require 'redis'
+require 'digest'
+require 'fileutils'
+require 'optparse'
+require 'yaml'
+require 'erb'
+
+ORIGINAL_ARGV = ARGV.dup
+options = {}
+parser = OptionParser.new do |opts|
+ opts.banner = "Usage: migrate_key [options]"
+
+ opts.separator ""
+ opts.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x|
+ options[:config] = x
+ end
+end
+
+parser.parse!
+oldname = ARGV[0]
+newname = ARGV[1]
+
+config = YAML::load(ERB.new(IO.read(options[:config])).result)
+ENV["coalmine_data_path"] = config['coalmine_data_path']
+@redis = Redis.new({:host => config["redis_host"], :port => config["redis_port"]})
+
+def calc_filename(statistic)
+ file_hash = Digest::MD5.hexdigest(statistic)
+ FileUtils.mkdir_p File.join(ENV["coalmine_data_path"], file_hash[0,2], file_hash[2,2])
+ File.join(ENV["coalmine_data_path"], file_hash[0,2], file_hash[2,2], file_hash)
+end
+
+def move_key(oldname, newname, config, redis)
+ config['redis_retention'].split(',').each_with_index do |retention, index|
+ if index.zero?
+ redis.rename oldname, newname
+ redis.srem "datapoints", oldname
+ redis.sadd "datapoints", newname
+ else
+ suffix = retention.split(":")[0]
+ FileUtils.mv(calc_filename("#{oldname}:#{suffix}"), calc_filename("#{newname}:#{suffix}"))
+ end
+ end
+end
+
+
+move_key(oldname, newname, config, @redis)
+
+keys.each do |key|
+ newname = key.gsub("BCX.", "BCX.Usage.")
+ begin
+ move_key(key, newname, config, @redis)
+ rescue Exception => e
+ puts e
+ end
+end
+
+resque_keys.each do |key|
+ newname = key.gsub("BCX.", "BCX.Performance.")
+ begin
+ move_key(key, newname, config, @redis)
+ rescue Exception => e
+ puts e
+ end
+end
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
-require File.expand_path("../lib/statsd/server", __FILE__) # for version info
+require File.expand_path("../lib/statsd_server/server", __FILE__) # for version info
Gem::Specification.new do |s|
- s.name = "statsd"
+ s.name = "statsd-server"
s.version = "0.6.4"
s.platform = Gem::Platform::RUBY
s.authors = ['Andrew Coldham', 'Ben VandenBos']

0 comments on commit ad20880

Please sign in to comment.