|
| 1 | +# Prometheus metric event handlers |
| 2 | + |
| 3 | + |
| 4 | +Metric updates are generally carried out inside event handlers. By overwriting these handlers, users can update metric values in response to various triggers ranging from HTTP requests to timer events. |
| 5 | + |
| 6 | +The functions outlined below can be modified to allow a user to monitor events outside those exposed in `exporter.q` |
| 7 | + |
| 8 | +`.prom.` **event handlers**<br> |
| 9 | +[`on_poll`](#promon_poll) Prometheus poll request<br> |
| 10 | +[`on_pc`](#promon_pc) IPC socket connection closing<br> |
| 11 | +[`on_po`](#promon_po) IPC socket connection opening<br> |
| 12 | +[`on_wc`](#promon_wc) Websocket connection closing<br> |
| 13 | +[`on_wo`](#promon_wo) Websocket connection opening<br> |
| 14 | +[`after_pg`](#promafer_pg) Synchronous IPC socket request handler, call after execution<br> |
| 15 | +[`before_pg`](#prombefore_pg) Synchronous IPC socket request handler, call before execution<br> |
| 16 | +[`after_ps`](#promafter_ps) Asynchronous IPC socket request handler, call after execution<br> |
| 17 | +[`before_ps`](#prombefore_ps) Asynchronous IPC socket request handler, call before execution<br> |
| 18 | +[`after_ph`](#promafter_ph) HTTP GET request handler, call after execution<br> |
| 19 | +[`before_ph`](#prombefore_ph) HTTP GET request handler, call before execution<br> |
| 20 | +[`after_pp`](#promafter_pp) HTTP POST request handler, call after execution<br> |
| 21 | +[`before_pp`](#prombefore_pp) HTTP POST request handler, call before execution<br> |
| 22 | +[`after_ws`](#promafter_ws) Websocket request handler, call after execution<br> |
| 23 | +[`before_ws`](#prombefore_ws) Websocket request handler, call before execution<br> |
| 24 | +[`after_ts`](#promafter_ts) Timer event handler, call after execution<br> |
| 25 | +[`before_ts`](#prombefore_ts) Timer event handler, call after execution |
| 26 | + |
| 27 | +:point_right: |
| 28 | +[Example invocations of these event handlers](../examples/kdb_user_example.q) |
| 29 | + |
| 30 | +Once the relevant event handlers have been defined to update the metric values, initialize the library with a call to [`.prom.init`](reference.md#initialize-library) |
| 31 | + |
| 32 | +:warning: |
| 33 | +Updating `.z.*` handlers after the call to `.prom.init` will overwrite the Prometheus logic. |
| 34 | +Correct usage is to load all process logic before loading the Prometheus library. |
| 35 | + |
| 36 | + |
| 37 | +## `.prom.after_pg` |
| 38 | + |
| 39 | +_Synchronous IPC socket request handler, called after execution_ |
| 40 | + |
| 41 | +```txt |
| 42 | +.prom.after_pg[tmp;msg;res] |
| 43 | +``` |
| 44 | + |
| 45 | + |
| 46 | +Where |
| 47 | + |
| 48 | +- `tmp` is the object returned by `.prom.before_pg` |
| 49 | +- `msg` is the object that was executed |
| 50 | +- `res` is the object returned by the execution of `msg` |
| 51 | + |
| 52 | + |
| 53 | +## `.prom.after_ph` |
| 54 | + |
| 55 | +_HTTP GET request handler, called after execution_ |
| 56 | + |
| 57 | +```txt |
| 58 | +.prom.after_ph[tmp;(requestText;requestHeaderAsDictionary);res] |
| 59 | +``` |
| 60 | + |
| 61 | + |
| 62 | +Where |
| 63 | + |
| 64 | +- `tmp` is the object returned by `.prom.before_ph` |
| 65 | +- `(requestText;requestHeaderAsDictionary)` is a HTTP GET request |
| 66 | +- `res` is the object returned by the execution of `msg` |
| 67 | + |
| 68 | + |
| 69 | +## `.prom.after_pp` |
| 70 | + |
| 71 | +_HTTP POST request handler, called after execution_ |
| 72 | + |
| 73 | +```txt |
| 74 | +.prom.after_pp[tmp;(requestText;requestHeaderAsDictionary);res] |
| 75 | +``` |
| 76 | + |
| 77 | + |
| 78 | +Where |
| 79 | + |
| 80 | +- `tmp` is the object returned by `.prom.before_pp` |
| 81 | +- `(requestText;requestHeaderAsDictionary)` is a HTTP POST request |
| 82 | +- `res` is the object returned by the execution of `msg` |
| 83 | + |
| 84 | + |
| 85 | +## `.prom.after_ps` |
| 86 | + |
| 87 | +_Asynchronous IPC socket request handler, called after execution_ |
| 88 | + |
| 89 | +```txt |
| 90 | +.prom.after_ps[tmp;msg;res] |
| 91 | +``` |
| 92 | + |
| 93 | + |
| 94 | +Where |
| 95 | + |
| 96 | +- `tmp` is the object returned by `.prom.before_ps` |
| 97 | +- `msg` is the object that was executed |
| 98 | +- `res` is the object returned by the execution of `msg` |
| 99 | + |
| 100 | + |
| 101 | +## `.prom.after_ts` |
| 102 | + |
| 103 | +_Timer event handler, called after execution_ |
| 104 | + |
| 105 | +```txt |
| 106 | +.prom.after_ts[tmp;dtm;res] |
| 107 | +``` |
| 108 | + |
| 109 | + |
| 110 | +Where |
| 111 | + |
| 112 | +- `tmp` is the object returned by `.prom.before_ts` |
| 113 | +- `dtm` is the timestamp at the start of execution |
| 114 | +- `res` is the object returned by the execution of `dtm` |
| 115 | + |
| 116 | + |
| 117 | +## `.prom.after_ws` |
| 118 | + |
| 119 | +_Websocket request handler, called after execution_ |
| 120 | + |
| 121 | +```txt |
| 122 | +.prom.after_ws[tmp;msg;res] |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | +Where |
| 127 | + |
| 128 | +- `tmp` is the object returned by `.prom.before_ws` |
| 129 | +- `msg` is the object that was executed |
| 130 | +- `res` is the object returned by the execution of `msg` |
| 131 | + |
| 132 | + |
| 133 | +## `.prom.before_pg` |
| 134 | + |
| 135 | +_Synchronous IPC socket request handler, called before execution_ |
| 136 | + |
| 137 | +```txt |
| 138 | +.prom.before_pg msg |
| 139 | +``` |
| 140 | + |
| 141 | + |
| 142 | +Where `msg` is the object to be executed, returns a `tmp` object to be passed to the _after_ handler. |
| 143 | + |
| 144 | + |
| 145 | +## `.prom.before_ph` |
| 146 | + |
| 147 | +_HTTP GET request handler, called before execution_ |
| 148 | + |
| 149 | +```txt |
| 150 | +.prom.before_ph(requestText;requestHeaderAsDictionary) |
| 151 | +``` |
| 152 | + |
| 153 | + |
| 154 | +Where `(requestText;requestHeaderAsDictionary)` is an HTTP GET request, returns a `tmp` object to be passed to the _after_ handler. |
| 155 | + |
| 156 | + |
| 157 | +## `.prom.before_pp` |
| 158 | + |
| 159 | +_HTTP POST request handler, called before execution_ |
| 160 | + |
| 161 | +```txt |
| 162 | +.prom.before_pp(requestText;requestHeaderAsDictionary) |
| 163 | +``` |
| 164 | + |
| 165 | + |
| 166 | +Where `(requestText;requestHeaderAsDictionary)` is an HTTP POST request, returns a `tmp` object to be passed to the _after_ handler. |
| 167 | + |
| 168 | + |
| 169 | +## `.prom.before_ps` |
| 170 | + |
| 171 | +_Asynchronous IPC socket request handler, called before execution_ |
| 172 | + |
| 173 | +```txt |
| 174 | +.prom.before_ps msg |
| 175 | +``` |
| 176 | + |
| 177 | + |
| 178 | +Where `msg` is the object to be executed, returns a `tmp` object to be passed to the _after_ handler. |
| 179 | + |
| 180 | + |
| 181 | +## `.prom.before_ts` |
| 182 | + |
| 183 | +_Timer event handler, called before execution_ |
| 184 | + |
| 185 | +```txt |
| 186 | +.prom.before_ts dtm |
| 187 | +``` |
| 188 | + |
| 189 | + |
| 190 | +Where `dtm` is the timestamp at the start of execution, returns a `tmp` object to be passed to the _after_ handler. |
| 191 | + |
| 192 | + |
| 193 | +## `.prom.before_ws` |
| 194 | + |
| 195 | +_Websocket request handler, called before execution_ |
| 196 | + |
| 197 | +```txt |
| 198 | +.prom.before_ws msg |
| 199 | +``` |
| 200 | + |
| 201 | + |
| 202 | +Where `msg` is the object to be executed, returns a `tmp` object to be passed to the _after_ handler. |
| 203 | + |
| 204 | + |
| 205 | +## `.prom.on_pc` |
| 206 | + |
| 207 | +_Socket close handler_ |
| 208 | + |
| 209 | +```txt |
| 210 | +.prom.on_pc hdl |
| 211 | +``` |
| 212 | + |
| 213 | + |
| 214 | +Where `hdl` is the handle of a socket connection, closes the socket. |
| 215 | + |
| 216 | + |
| 217 | +## `.prom.on_po` |
| 218 | + |
| 219 | +_Socket open handler_ |
| 220 | + |
| 221 | +```txt |
| 222 | +.prom.on_po hdl |
| 223 | +``` |
| 224 | + |
| 225 | + |
| 226 | +Where `hdl` is the handle of a socket connection, opens the socket. |
| 227 | + |
| 228 | + |
| 229 | +## `.prom.on_poll` |
| 230 | + |
| 231 | +_Prometheus poll request handler_ |
| 232 | + |
| 233 | +```txt |
| 234 | +.prom.on_poll(requestText;requestHeaderAsDictionary) |
| 235 | +``` |
| 236 | + |
| 237 | +Where `(requestText;requestHeaderAsDictionary)` is an HTTP request |
| 238 | + |
0 commit comments