Skip to content

Commit ddfc21d

Browse files
committed
address review comments
1 parent 3e990f1 commit ddfc21d

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

hazelcast/metrics.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ProbeUnit(object):
9393
ENUM = 6
9494
"""0..n, ordinal of an enum."""
9595

96-
# New enum values should be should be converted to a tag to ensure backward
96+
# New enum values should be converted to a tag to ensure backward
9797
# compatibility during compressing the metrics. see ProbeUnit#newUnit
9898
# handling in Java for that. We don't implement this functionality yet in
9999
# the Python client, as we don't use such enum members.
@@ -112,29 +112,29 @@ class ValueType(object):
112112
class MetricsCompressor(object):
113113
"""Compresses metrics into a ``bytearray`` blob.
114114
115-
The compressor uses dictionary based delta compression and deflates
116-
the resulting ``bytearray`` by using ``zlib.compress()``. This
117-
compressor doesn't use the textual representation of the
118-
:class:`MetricDescriptor` hence it is agnostic to the order of the
119-
tags in that representation.
120-
121-
Adding metrics by calling :func:`add_long` or :func:`add_double`
122-
builds a dictionary by mapping all words found in the passed
123-
:class:`MetricDescriptor`s to ``int``s and these ``int``s will be
124-
written to the resulting ``bytearray`` blob. Before these ``int``s
125-
are written, the current :class:`MetricDescriptor` is compared to the
126-
previous one and only the fields of the descriptor that are different
127-
from the previous will be written to the metrics blob.
128-
129-
When the blob is retrieved from this compressor (when the metrics
130-
collection cycle finishes) the dictionary is stored in the dictionary
131-
blob. The compressor iterates over the words stored in the dictionary
132-
in ascending order and writes them to the blob by skipping the first
133-
N characters that are equal to the first N character of the previously
134-
written word, hence using delta compression here too.
135-
136-
After both the metrics and the dictionary blob is constructed, they
137-
are copied into a final blob in the following structure:
115+
The compressor uses dictionary based delta compression and deflates
116+
the resulting ``bytearray`` by using ``zlib.compress()``. This
117+
compressor doesn't use the textual representation of the
118+
:class:`MetricDescriptor` hence it is agnostic to the order of the
119+
tags in that representation.
120+
121+
Adding metrics by calling :func:`add_long` or :func:`add_double`
122+
builds a dictionary by mapping all words found in the passed
123+
:class:`MetricDescriptor`s to ``int``s and these ``int``s will be
124+
written to the resulting ``bytearray`` blob. Before these ``int``s
125+
are written, the current :class:`MetricDescriptor` is compared to the
126+
previous one and only the fields of the descriptor that are different
127+
from the previous will be written to the metrics blob.
128+
129+
When the blob is retrieved from this compressor (when the metrics
130+
collection cycle finishes) the dictionary is stored in the dictionary
131+
blob. The compressor iterates over the words stored in the dictionary
132+
in ascending order and writes them to the blob by skipping the first
133+
N characters that are equal to the first N character of the previously
134+
written word, hence using delta compression here too.
135+
136+
After both the metrics and the dictionary blob is constructed, they
137+
are copied into a final blob in the following structure:
138138
139139
+--------------------------------+--------------------+
140140
| Compressor version | 2 bytes (short) |
@@ -245,7 +245,7 @@ def _calculate_descriptor_mask(self, descriptor):
245245
if descriptor.unit == last_descriptor.unit:
246246
mask |= _MASK_UNIT
247247

248-
# include excludedTargets and tags bytes for compatibility purposes
248+
# include excludedTargets and tags bits for compatibility purposes
249249
mask |= _MASK_EXCLUDED_TARGETS
250250
mask |= _MASK_TAG_COUNT
251251

hazelcast/statistics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23

34
from hazelcast.core import CLIENT_TYPE
45
from hazelcast.invocation import Invocation
@@ -21,7 +22,6 @@
2122
_KEY_VALUE_SEPARATOR = "="
2223
_EMPTY_ATTRIBUTE_VALUE = ""
2324

24-
_DEFAULT_PROBE_VALUE = 0
2525
_NEAR_CACHE_DESCRIPTOR_PREFIX = "nearcache"
2626
_NEAR_CACHE_DESCRIPTOR_DISCRIMINATOR = "name"
2727

@@ -94,7 +94,7 @@ def _register_gauges(self):
9494
)
9595
self._register_system_gauge(
9696
"os.systemLoadAverage",
97-
lambda: psutil.cpu_percent(),
97+
lambda: os.getloadavg()[0],
9898
ValueType.DOUBLE,
9999
)
100100
self._register_system_gauge(
@@ -124,6 +124,7 @@ def _register_gauges(self):
124124
)
125125

126126
def _register_system_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LONG):
127+
# Try a gauge function read, we will register it if it succeeds.
127128
try:
128129
gauge_fn()
129130
self._registered_system_gauges[gauge_name] = (gauge_fn, value_type)
@@ -133,6 +134,7 @@ def _register_system_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LONG
133134
)
134135

135136
def _register_process_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LONG):
137+
# Try a gauge function read, we will register it if it succeeds.
136138
try:
137139
process = psutil.Process()
138140
gauge_fn(process)

0 commit comments

Comments
 (0)