@@ -643,56 +643,78 @@ def _pre_aggregate_events(self, api_events, containers_by_id):
643643 def _format_events (self , aggregated_events , containers_by_id ):
644644 events = []
645645 for image_name , event_group in aggregated_events .iteritems ():
646- max_timestamp = 0
647- status = defaultdict (int )
648- status_change = []
649646 container_tags = set ()
647+ low_prio_events = []
648+ normal_prio_events = []
649+
650650 for event in event_group :
651- max_timestamp = max (max_timestamp , int (event ['time' ]))
652- status [event ['status' ]] += 1
653651 container_name = event ['id' ][:11 ]
652+
654653 if event ['id' ] in containers_by_id :
655654 cont = containers_by_id [event ['id' ]]
656655 container_name = DockerUtil .container_name_extractor (cont )[0 ]
657656 container_tags .update (self ._get_tags (cont , PERFORMANCE ))
658657 container_tags .add ('container_name:%s' % container_name )
659658
660- status_change .append ([container_name , event ['status' ]])
661-
662- status_text = ", " .join (["%d %s" % (count , st ) for st , count in status .iteritems ()])
663- msg_title = "%s %s on %s" % (image_name , status_text , self .hostname )
664- msg_body = (
665- "%%%\n "
666- "{image_name} {status} on {hostname}\n "
667- "```\n {status_changes}\n ```\n "
668- "%%%"
669- ).format (
670- image_name = image_name ,
671- status = status_text ,
672- hostname = self .hostname ,
673- status_changes = "\n " .join (
674- ["%s \t %s" % (change [1 ].upper (), change [0 ]) for change in status_change ])
675- )
676-
677- if any (error in status_text for error in ERROR_ALERT_TYPE ):
678- alert_type = "error"
679- else :
680- alert_type = None
681-
682- events .append ({
683- 'timestamp' : max_timestamp ,
684- 'host' : self .hostname ,
685- 'event_type' : EVENT_TYPE ,
686- 'msg_title' : msg_title ,
687- 'msg_text' : msg_body ,
688- 'source_type_name' : EVENT_TYPE ,
689- 'event_object' : 'docker:%s' % image_name ,
690- 'tags' : list (container_tags ),
691- 'alert_type' : alert_type
692- })
659+ # health checks generate tons of these so we treat them separately and lower their priority
660+ if event ['status' ].startswith ('exec_create:' ) or event ['status' ].startswith ('exec_start:' ):
661+ low_prio_events .append ((event , container_name ))
662+ else :
663+ normal_prio_events .append ((event , container_name ))
664+
665+ exec_event = self ._create_dd_event (low_prio_events , image_name , container_tags , priority = 'Low' )
666+ events .append (exec_event )
667+
668+ normal_event = self ._create_dd_event (normal_prio_events , image_name , container_tags , priority = 'Normal' )
669+ events .append (normal_event )
693670
694671 return events
695672
673+ def _create_dd_event (self , events , image , c_tags , priority = 'Normal' ):
674+ """Create the actual event to submit from a list of similar docker events"""
675+ max_timestamp = 0
676+ status = defaultdict (int )
677+ status_change = []
678+
679+ for ev , c_name in events :
680+ max_timestamp = max (max_timestamp , int (ev ['time' ]))
681+ status [ev ['status' ]] += 1
682+ status_change .append ([c_name , ev ['status' ]])
683+
684+ status_text = ", " .join (["%d %s" % (count , st ) for st , count in status .iteritems ()])
685+ msg_title = "%s %s on %s" % (image , status_text , self .hostname )
686+ msg_body = (
687+ "%%%\n "
688+ "{image_name} {status} on {hostname}\n "
689+ "```\n {status_changes}\n ```\n "
690+ "%%%"
691+ ).format (
692+ image_name = image ,
693+ status = status_text ,
694+ hostname = self .hostname ,
695+ status_changes = "\n " .join (
696+ ["%s \t %s" % (change [1 ].upper (), change [0 ]) for change in status_change ])
697+ )
698+
699+ if any (error in status_text for error in ERROR_ALERT_TYPE ):
700+ alert_type = "error"
701+ else :
702+ alert_type = None
703+
704+ return {
705+ 'timestamp' : max_timestamp ,
706+ 'host' : self .hostname ,
707+ 'event_type' : EVENT_TYPE ,
708+ 'msg_title' : msg_title ,
709+ 'msg_text' : msg_body ,
710+ 'source_type_name' : EVENT_TYPE ,
711+ 'event_object' : 'docker:%s' % image ,
712+ 'tags' : list (c_tags ),
713+ 'alert_type' : alert_type ,
714+ 'priority' : priority
715+ }
716+
717+
696718 def _report_disk_stats (self ):
697719 """Report metrics about the volume space usage"""
698720 stats = {
0 commit comments