Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Add prometheus metrics for number of badge update pushes. (#4709)
Browse files Browse the repository at this point in the history
We're counting the number of push notifications, but not the number of badges;
I'd like to see if they are significant.
  • Loading branch information
richvdh committed Feb 22, 2019
1 parent e1666af commit e07384c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/4709.misc
@@ -0,0 +1 @@
Add prometheus metrics for number of badge update pushes.
33 changes: 25 additions & 8 deletions synapse/push/httppusher.py
Expand Up @@ -32,9 +32,25 @@

logger = logging.getLogger(__name__)

http_push_processed_counter = Counter("synapse_http_httppusher_http_pushes_processed", "")
http_push_processed_counter = Counter(
"synapse_http_httppusher_http_pushes_processed",
"Number of push notifications successfully sent",
)

http_push_failed_counter = Counter("synapse_http_httppusher_http_pushes_failed", "")
http_push_failed_counter = Counter(
"synapse_http_httppusher_http_pushes_failed",
"Number of push notifications which failed",
)

http_badges_processed_counter = Counter(
"synapse_http_httppusher_badge_updates_processed",
"Number of badge updates successfully sent",
)

http_badges_failed_counter = Counter(
"synapse_http_httppusher_badge_updates_failed",
"Number of badge updates which failed",
)


class HttpPusher(object):
Expand Down Expand Up @@ -346,6 +362,10 @@ def dispatch_push(self, event, tweaks, badge):

@defer.inlineCallbacks
def _send_badge(self, badge):
"""
Args:
badge (int): number of unread messages
"""
logger.info("Sending updated badge count %d to %s", badge, self.name)
d = {
'notification': {
Expand All @@ -366,14 +386,11 @@ def _send_badge(self, badge):
}
}
try:
resp = yield self.http_client.post_json_get_json(self.url, d)
yield self.http_client.post_json_get_json(self.url, d)
http_badges_processed_counter.inc()
except Exception as e:
logger.warning(
"Failed to send badge count to %s: %s %s",
self.name, type(e), e,
)
defer.returnValue(False)
rejected = []
if 'rejected' in resp:
rejected = resp['rejected']
defer.returnValue(rejected)
http_badges_failed_counter.inc()

0 comments on commit e07384c

Please sign in to comment.