""" This example demonstrates what a reader that consumes guesstimator's data might look like. in the wild this might be a Ganglia or Munin plugin. """ import time from guesstimator import Guesstimator from redis import Redis guesstimator = Guesstimator(environment='example') sample_set_name = 'count-operations' redis = Redis('localhost') # Initialize a sample set, this should only be done once. if not sample_set_name in guesstimator.list_sample_sets(): guesstimator.create_sample_set( name=sample_set_name ) while True: time.sleep(10) operations = float( redis.get('guesstimator_example_actual_operation_count') ) timestamp, estimated_operations = guesstimator.read(sample_set_name) print "Metrics:\n\toperation count: \t\033[32m%s\033[m\n\testimated count:\t\033[31m%s\033[m\n\n\tOperations per-second:\t%s\n---------" % ( operations, estimated_operations, ( operations / (time.time() - timestamp) ) ) guesstimator.reset(sample_set_name)
def test_list_sample_set_lists_all_sample_sets_currently_being_written_to(self): guesstimator = Guesstimator(redis_host='localhost', environment='test') self.redis.lpush( guesstimator._sample_set_list_key, 'user-message-queue' ) self.redis.lpush( guesstimator._sample_set_list_key, 'user-background-jobs' ) self.assertTrue( 'user-background-jobs' in guesstimator.list_sample_sets() ) self.assertTrue( 'user-message-queue' in guesstimator.list_sample_sets() )
def test_create_sample_set_creates_populates_sample_set_list(self): guesstimator = Guesstimator(redis_host='localhost', environment='test') self.assertEqual( self.redis.type( guesstimator._sample_set_list_key ), 'none') guesstimator.create_sample_set('foobar-sample') self.assertTrue( 'foobar-sample' in guesstimator.list_sample_sets() )
def _delete_guesstimator_data(self): guesstimator = Guesstimator(redis_host='localhost', environment='test') self.redis.delete( guesstimator._sample_set_list_key ) for sample_set_name in guesstimator.list_sample_sets(): self.redis.delete(guesstimator._get_hash_key(sample_set_name))