Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metric for service backend counts #305

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lymph/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def join(self):
def lookup(self, address, version=None):
if '://' not in address:
service = self.service_registry.get(address)
if not self.metrics.has_metric('known_instances', tags={'address': address}):
self.metrics.add(metrics.Callable('known_instances',
lambda: len(self.service_registry.get(address)),
tags={'address': address}))
else:
instance = ServiceInstance(address)
service = Service(address, instances=[instance])
Expand Down
8 changes: 8 additions & 0 deletions lymph/core/monitoring/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def add(self, metric):
self._metrics.append(metric)
return metric

def has_metric(self, name, tags=None):
for metric in self._metrics:
for i_name, i_value, i_tags in metric:
if (name == i_name and
all([tags[tag] == i_tags[tag] for tag in tags.keys()])):
return True
return False

def add_tags(self, **tags):
self._tags.update(tags)

Expand Down