Jelajahi Sumber

Adds new fields to worker events: sw_ident, sw_ver, sw_sys

Ask Solem 14 tahun lalu
induk
melakukan
3ef71fce7d
3 mengubah file dengan 23 tambahan dan 4 penghapusan
  1. 6 0
      Changelog
  2. 12 3
      celery/worker/heartbeat.py
  3. 5 1
      docs/userguide/monitoring.rst

+ 6 - 0
Changelog

@@ -369,6 +369,12 @@ News
 * The PID of the child worker process accepting a task is now sent as a field
   with the `task-started` event.
 
+* The following fields have been added to all events in the worker class:
+
+    * `sw_ident`: Name of worker software (e.g. celeryd).
+    * `sw_ver`: Software version (e.g. 2.2.0).
+    * `sw_sys`: Operating System (e.g. Linux, Windows, Darwin).
+
 * For better accuracy the start time reported by the multiprocessing worker
   process is used when calculating task duration.
 

+ 12 - 3
celery/worker/heartbeat.py

@@ -1,7 +1,10 @@
+import platform
 import threading
 
 from time import time, sleep
 
+from celery import __version__
+
 
 class Heart(threading.Thread):
     """Thread sending heartbeats at regular intervals.
@@ -11,6 +14,9 @@ class Heart(threading.Thread):
                        Default is 2 minutes.
 
     """
+    software_info = {"sw_ident": "celeryd",
+                     "sw_ver": __version__,
+                     "sw_sys": platform.system()}
 
     #: Beats per minute.
     bpm = 0.5
@@ -28,8 +34,11 @@ class Heart(threading.Thread):
         self._state = "RUN"
         bpm = self.bpm
         dispatch = self.eventer.send
+        software_info = self.software_info
+
+        dispatch("worker-online", **software_info)
 
-        dispatch("worker-online")
+        sw_ident, sw_ver, sw_sys = self.software_info
 
         # We can't sleep all of the interval, because then
         # it takes 60 seconds (or value of interval) to shutdown
@@ -46,12 +55,12 @@ class Heart(threading.Thread):
 
             if not last_beat or now > last_beat + (60.0 / bpm):
                 last_beat = now
-                dispatch("worker-heartbeat")
+                dispatch("worker-heartbeat", **software_info)
             if self._shutdown.isSet():
                 break
             sleep(1)
 
-        dispatch("worker-offline")
+        dispatch("worker-offline", **software_info)
 
     def stop(self):
         """Gracefully shutdown the thread."""

+ 5 - 1
docs/userguide/monitoring.rst

@@ -525,10 +525,14 @@ Task Events
 Worker Events
 ~~~~~~~~~~~~~
 
-* `worker-online(hostname, timestamp)`
+* `worker-online(hostname, timestamp, sw_ident, sw_ver, sw_sys)`
 
     The worker has connected to the broker and is online.
 
+    * `sw_ident`: Name of worker software (e.g. celeryd).
+    * `sw_ver`: Software version (e.g. 2.2.0).
+    * `sw_sys`: Operating System (e.g. Linux, Windows, Darwin).
+
 * `worker-heartbeat(hostname, timestamp)`
 
     Sent every minute, if the worker has not sent a heartbeat in 2 minutes,