The uWSGI Stats Server

In addition to SNMP, uWSGI also supports a Stats Server mechanism which exports the uWSGI state as a JSON object to a socket.

Simply use the stats option followed by a valid socket address. If you want the stats served over HTTP you will need to also add the stats-http option.

  1. --stats 127.0.0.1:1717
  2. --stats /tmp/statsock
  3. --stats :5050
  4. --stats @foobar
  5. # Any of the above socket types can also return stats using HTTP
  6. --stats 127.0.0.1:1717 --stats-http

If a client connects to the specified socket it will get a JSON object containing uWSGI internal statistics before the connection ends.

  1. uwsgi --socket :3031 --stats :1717 --module welcome --master --processes 8

then

  1. nc 127.0.0.1 1717
  2. # or for convenience...
  3. uwsgi --connect-and-read 127.0.0.1:1717

will return something like this:

  1. {
  2. "workers": [{
  3. "id": 1,
  4. "pid": 31759,
  5. "requests": 0,
  6. "exceptions": 0,
  7. "status": "idle",
  8. "rss": 0,
  9. "vsz": 0,
  10. "running_time": 0,
  11. "last_spawn": 1317235041,
  12. "respawn_count": 1,
  13. "tx": 0,
  14. "avg_rt": 0,
  15. "apps": [{
  16. "id": 0,
  17. "modifier1": 0,
  18. "mountpoint": "",
  19. "requests": 0,
  20. "exceptions": 0,
  21. "chdir": ""
  22. }]
  23. }, {
  24. "id": 2,
  25. "pid": 31760,
  26. "requests": 0,
  27. "exceptions": 0,
  28. "status": "idle",
  29. "rss": 0,
  30. "vsz": 0,
  31. "running_time": 0,
  32. "last_spawn": 1317235041,
  33. "respawn_count": 1,
  34. "tx": 0,
  35. "avg_rt": 0,
  36. "apps": [{
  37. "id": 0,
  38. "modifier1": 0,
  39. "mountpoint": "",
  40. "requests": 0,
  41. "exceptions": 0,
  42. "chdir": ""
  43. }]
  44. }, {
  45. "id": 3,
  46. "pid": 31761,
  47. "requests": 0,
  48. "exceptions": 0,
  49. "status": "idle",
  50. "rss": 0,
  51. "vsz": 0,
  52. "running_time": 0,
  53. "last_spawn": 1317235041,
  54. "respawn_count": 1,
  55. "tx": 0,
  56. "avg_rt": 0,
  57. "apps": [{
  58. "id": 0,
  59. "modifier1": 0,
  60. "mountpoint": "",
  61. "requests": 0,
  62. "exceptions": 0,
  63. "chdir": ""
  64. }]
  65. }, {
  66. "id": 4,
  67. "pid": 31762,
  68. "requests": 0,
  69. "exceptions": 0,
  70. "status": "idle",
  71. "rss": 0,
  72. "vsz": 0,
  73. "running_time": 0,
  74. "last_spawn": 1317235041,
  75. "respawn_count": 1,
  76. "tx": 0,
  77. "avg_rt": 0,
  78. "apps": [{
  79. "id": 0,
  80. "modifier1": 0,
  81. "mountpoint": "",
  82. "requests": 0,
  83. "exceptions": 0,
  84. "chdir": ""
  85. }]
  86. }, {
  87. "id": 5,
  88. "pid": 31763,
  89. "requests": 0,
  90. "exceptions": 0,
  91. "status": "idle",
  92. "rss": 0,
  93. "vsz": 0,
  94. "running_time": 0,
  95. "last_spawn": 1317235041,
  96. "respawn_count": 1,
  97. "tx": 0,
  98. "avg_rt": 0,
  99. "apps": [{
  100. "id": 0,
  101. "modifier1": 0,
  102. "mountpoint": "",
  103. "requests": 0,
  104. "exceptions": 0,
  105. "chdir": ""
  106. }]
  107. }, {
  108. "id": 6,
  109. "pid": 31764,
  110. "requests": 0,
  111. "exceptions": 0,
  112. "status": "idle",
  113. "rss": 0,
  114. "vsz": 0,
  115. "running_time": 0,
  116. "last_spawn": 1317235041,
  117. "respawn_count": 1,
  118. "tx": 0,
  119. "avg_rt": 0,
  120. "apps": [{
  121. "id": 0,
  122. "modifier1": 0,
  123. "mountpoint": "",
  124. "requests": 0,
  125. "exceptions": 0,
  126. "chdir": ""
  127. }]
  128. }, {
  129. "id": 7,
  130. "pid": 31765,
  131. "requests": 0,
  132. "exceptions": 0,
  133. "status": "idle",
  134. "rss": 0,
  135. "vsz": 0,
  136. "running_time": 0,
  137. "last_spawn": 1317235041,
  138. "respawn_count": 1,
  139. "tx": 0,
  140. "avg_rt": 0,
  141. "apps": [{
  142. "id": 0,
  143. "modifier1": 0,
  144. "mountpoint": "",
  145. "requests": 0,
  146. "exceptions": 0,
  147. "chdir": ""
  148. }]
  149. }, {
  150. "id": 8,
  151. "pid": 31766,
  152. "requests": 0,
  153. "exceptions": 0,
  154. "status": "idle",
  155. "rss": 0,
  156. "vsz": 0,
  157. "running_time": 0,
  158. "last_spawn": 1317235041,
  159. "respawn_count": 1,
  160. "tx": 0,
  161. "avg_rt": 0,
  162. "apps": [{
  163. "id": 0,
  164. "modifier1": 0,
  165. "mountpoint": "",
  166. "requests": 0,
  167. "exceptions": 0,
  168. "chdir": ""
  169. }]
  170. }]
  171. }

uwsgitop

uwsgitop is a top-like command that uses the stats server. It is available on PyPI, so use easy_install or pip to install it (package name uwsgitop, naturally).

The sources are available on Github. https://github.com/unbit/uwsgitop