Changed per-cluster metrics path and added ability to define an explicit stats name
This commit is contained in:
@@ -111,12 +111,14 @@ class Metrics(object):
|
|||||||
the driver currently has open.
|
the driver currently has open.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_stats_counter = 0
|
||||||
|
|
||||||
def __init__(self, cluster_proxy):
|
def __init__(self, cluster_proxy):
|
||||||
log.debug("Starting metric capture")
|
log.debug("Starting metric capture")
|
||||||
|
|
||||||
# TODO, modify the path to /cassandra/{clusterid} in 4.0
|
self.stats_name = 'cassandra-{0}'.format(str(self._stats_counter))
|
||||||
self.stats_id = str(id(cluster_proxy))
|
Metrics._stats_counter += 1
|
||||||
self.stats = scales.collection('/_cassandra/{0}'.format(self.stats_id),
|
self.stats = scales.collection(self.stats_name,
|
||||||
scales.PmfStat('request_timer'),
|
scales.PmfStat('request_timer'),
|
||||||
scales.IntStat('connection_errors'),
|
scales.IntStat('connection_errors'),
|
||||||
scales.IntStat('write_timeouts'),
|
scales.IntStat('write_timeouts'),
|
||||||
@@ -137,7 +139,7 @@ class Metrics(object):
|
|||||||
# TODO, to be removed in 4.0
|
# TODO, to be removed in 4.0
|
||||||
# /cassandra contains the metrics of the first cluster registered
|
# /cassandra contains the metrics of the first cluster registered
|
||||||
if 'cassandra' not in scales._Stats.stats:
|
if 'cassandra' not in scales._Stats.stats:
|
||||||
scales._Stats.stats['cassandra'] = scales._Stats.stats['_cassandra'][self.stats_id]
|
scales._Stats.stats['cassandra'] = scales._Stats.stats[self.stats_name]
|
||||||
|
|
||||||
self.request_timer = self.stats.request_timer
|
self.request_timer = self.stats.request_timer
|
||||||
self.connection_errors = self.stats.connection_errors
|
self.connection_errors = self.stats.connection_errors
|
||||||
@@ -176,4 +178,16 @@ class Metrics(object):
|
|||||||
"""
|
"""
|
||||||
Returns the metrics for the registered cluster instance.
|
Returns the metrics for the registered cluster instance.
|
||||||
"""
|
"""
|
||||||
return scales.getStats()['_cassandra'][self.stats_id]
|
return scales.getStats()[self.stats_name]
|
||||||
|
|
||||||
|
def set_stats_name(self, stats_name):
|
||||||
|
"""
|
||||||
|
Set the metrics stats name.
|
||||||
|
The stats_name is a string used to access the metris through scales: scales.getStats()[<stats_name>]
|
||||||
|
Default is 'cassandra-<num>'.
|
||||||
|
"""
|
||||||
|
|
||||||
|
stats = scales._Stats.stats[self.stats_name]
|
||||||
|
del scales._Stats.stats[self.stats_name]
|
||||||
|
self.stats_name = stats_name
|
||||||
|
scales._Stats.stats[self.stats_name] = stats
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from cassandra import ConsistencyLevel, WriteTimeout, Unavailable, ReadTimeout
|
|||||||
|
|
||||||
from cassandra.cluster import Cluster, NoHostAvailable
|
from cassandra.cluster import Cluster, NoHostAvailable
|
||||||
from tests.integration import get_cluster, get_node, use_singledc, PROTOCOL_VERSION, execute_until_pass
|
from tests.integration import get_cluster, get_node, use_singledc, PROTOCOL_VERSION, execute_until_pass
|
||||||
|
from greplin import scales
|
||||||
|
|
||||||
def setup_module():
|
def setup_module():
|
||||||
use_singledc()
|
use_singledc()
|
||||||
@@ -197,14 +197,23 @@ class MetricsTests(unittest.TestCase):
|
|||||||
finally:
|
finally:
|
||||||
get_node(1).resume()
|
get_node(1).resume()
|
||||||
|
|
||||||
|
# Change the scales stats_name of the cluster2
|
||||||
|
cluster2.metrics.set_stats_name('cluster2-metrics')
|
||||||
|
|
||||||
stats_cluster1 = self.cluster.metrics.get_stats()
|
stats_cluster1 = self.cluster.metrics.get_stats()
|
||||||
stats_cluster2 = cluster2.metrics.get_stats()
|
stats_cluster2 = cluster2.metrics.get_stats()
|
||||||
|
|
||||||
|
# Test direct access to stats
|
||||||
self.assertEqual(1, self.cluster.metrics.stats.write_timeouts)
|
self.assertEqual(1, self.cluster.metrics.stats.write_timeouts)
|
||||||
self.assertEqual(0, cluster2.metrics.stats.write_timeouts)
|
self.assertEqual(0, cluster2.metrics.stats.write_timeouts)
|
||||||
|
|
||||||
|
# Test direct access to a child stats
|
||||||
self.assertNotEqual(0.0, self.cluster.metrics.request_timer['mean'])
|
self.assertNotEqual(0.0, self.cluster.metrics.request_timer['mean'])
|
||||||
self.assertEqual(0.0, cluster2.metrics.request_timer['mean'])
|
self.assertEqual(0.0, cluster2.metrics.request_timer['mean'])
|
||||||
|
|
||||||
|
# Test access via metrics.get_stats()
|
||||||
self.assertNotEqual(0.0, stats_cluster1['request_timer']['mean'])
|
self.assertNotEqual(0.0, stats_cluster1['request_timer']['mean'])
|
||||||
self.assertEqual(0.0, stats_cluster2['request_timer']['mean'])
|
self.assertEqual(0.0, stats_cluster2['request_timer']['mean'])
|
||||||
|
|
||||||
|
# Test access by stats_name
|
||||||
|
self.assertEqual(0.0, scales.getStats()['cluster2-metrics']['request_timer']['mean'])
|
||||||
|
|||||||
Reference in New Issue
Block a user