|
16 | 16 | from smtplib import SMTP |
17 | 17 | from smtplib import SMTPException |
18 | 18 | from socket import error |
| 19 | +import statsd |
| 20 | + |
19 | 21 |
|
20 | 22 | import dateutil.tz |
21 | 23 | import pytz |
@@ -172,6 +174,12 @@ def __init__(self, args): |
172 | 174 | self.thread_data.num_dupes = 0 |
173 | 175 | self.scheduler = BackgroundScheduler() |
174 | 176 | self.string_multi_field_name = self.conf.get('string_multi_field_name', False) |
| 177 | + self.statsd_instance_tag = self.conf.get('statsd_instance_tag', '') |
| 178 | + self.statsd_host = self.conf.get('statsd_host', '') |
| 179 | + if self.statsd_host and len(self.statsd_host) > 0: |
| 180 | + self.statsd = statsd.StatsClient(host=self.statsd_host, port=8125) |
| 181 | + else: |
| 182 | + self.statsd = None |
175 | 183 | self.add_metadata_alert = self.conf.get('add_metadata_alert', False) |
176 | 184 | self.prometheus_port = self.args.prometheus_port |
177 | 185 | self.show_disabled_rules = self.conf.get('show_disabled_rules', True) |
@@ -1306,6 +1314,25 @@ def handle_rule_execution(self, rule): |
1306 | 1314 | " %s alerts sent" % (rule['name'], old_starttime, pretty_ts(endtime, rule.get('use_local_time')), |
1307 | 1315 | self.thread_data.num_hits, self.thread_data.num_dupes, num_matches, |
1308 | 1316 | self.thread_data.alerts_sent)) |
| 1317 | + rule_duration = seconds(endtime - rule.get('original_starttime')) |
| 1318 | + elastalert_logger.info("%s range %s" % (rule['name'], rule_duration)) |
| 1319 | + if self.statsd: |
| 1320 | + try: |
| 1321 | + self.statsd.gauge( |
| 1322 | + 'query.hits', self.thread_data.num_hits, |
| 1323 | + tags={"elastalert_instance": self.statsd_instance_tag, "rule_name": rule['name']}) |
| 1324 | + self.statsd.gauge( |
| 1325 | + 'already_seen.hits', self.thread_data.num_dupes, |
| 1326 | + tags={"elastalert_instance": self.statsd_instance_tag, "rule_name": rule['name']}) |
| 1327 | + self.statsd.gauge( |
| 1328 | + 'query.matches', num_matches, |
| 1329 | + tags={"elastalert_instance": self.statsd_instance_tag, "rule_name": rule['name']}) |
| 1330 | + self.statsd.gauge( |
| 1331 | + 'query.alerts_sent', self.thread_data.alerts_sent, |
| 1332 | + tags={"elastalert_instance": self.statsd_instance_tag, "rule_name": rule['name']}) |
| 1333 | + except BaseException as e: |
| 1334 | + elastalert_logger.error("unable to send metrics:\n%s" % str(e)) |
| 1335 | + |
1309 | 1336 | self.thread_data.alerts_sent = 0 |
1310 | 1337 |
|
1311 | 1338 | if next_run < datetime.datetime.utcnow(): |
|
0 commit comments