예제 #1
0
 def test_reset_resets_timestamp_and_samples_taken(self):
     mock_time = MockTime()
     new_time = 1345576088.71
     guesstimator = Guesstimator(redis_host='localhost', random=MockRandom(), time=mock_time, environment='test')
     
     guesstimator.create_sample_set(
         name='100-percent-sample',
         recording_frequency=1.0
     )
     guesstimator.record('100-percent-sample')
     guesstimator.record('100-percent-sample')
     
     timestamp, samples_taken = guesstimator.read('100-percent-sample')
     self.assertEqual( '2', self.redis.hget( guesstimator._get_hash_key('100-percent-sample'), 'samples_taken' ) )
     self.assertFalse( timestamp == new_time )
     
     mock_time.time = new_time
     guesstimator.reset('100-percent-sample')
     timestamp, samples_taken = guesstimator.read('100-percent-sample')
     
     self.assertEqual( '0', self.redis.hget( guesstimator._get_hash_key('100-percent-sample'), 'samples_taken' ) )
     self.assertEqual( new_time, timestamp )
예제 #2
0
파일: reader.py 프로젝트: bcoe/guesstimator
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)
    redis.set('guesstimator_example_actual_operation_count', 0)