|
| 1 | +# Using the prom-client express middleware wrapper express-prom-bundle |
| 2 | + |
| 3 | + |
| 4 | +See the content of [./metrics.js](./metrics.js) |
| 5 | +```js |
| 6 | +const promBundle = require("express-prom-bundle"); |
| 7 | + |
| 8 | +const metricsMiddleware = promBundle({ |
| 9 | + includeMethod: true, |
| 10 | + includePath: true, |
| 11 | + includeUp: false, |
| 12 | + metricType: 'histogram', |
| 13 | + buckets: [0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.6, 0.75, 1, 2.5, 10], |
| 14 | + promClient: { |
| 15 | + collectDefaultMetrics: { |
| 16 | + timestamps: false |
| 17 | + } |
| 18 | + } |
| 19 | +}); |
| 20 | + |
| 21 | +module.exports = (app) => { |
| 22 | + app.use(metricsMiddleware) |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +Start the application |
| 27 | +```bash |
| 28 | +npm install |
| 29 | +``` |
| 30 | + |
| 31 | +```bash |
| 32 | +npm start |
| 33 | +``` |
| 34 | + |
| 35 | +Use the app |
| 36 | +```bash |
| 37 | +open http://localhost:8080/ |
| 38 | +``` |
| 39 | + |
| 40 | +Get the metrics via `/metrics` |
| 41 | +```bash |
| 42 | +curl http://localhost:8080/metrics |
| 43 | +``` |
| 44 | + |
| 45 | +Here is an example of the output: |
| 46 | +``` |
| 47 | +# HELP process_cpu_user_seconds_total Total user CPU time spent in seconds. |
| 48 | +# TYPE process_cpu_user_seconds_total counter |
| 49 | +process_cpu_user_seconds_total 0.050724 1580409960992 |
| 50 | +
|
| 51 | +# HELP process_cpu_system_seconds_total Total system CPU time spent in seconds. |
| 52 | +# TYPE process_cpu_system_seconds_total counter |
| 53 | +process_cpu_system_seconds_total 0.00534 1580409960992 |
| 54 | +
|
| 55 | +# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. |
| 56 | +# TYPE process_cpu_seconds_total counter |
| 57 | +process_cpu_seconds_total 0.056064 1580409960992 |
| 58 | +
|
| 59 | +# HELP process_start_time_seconds Start time of the process since unix epoch in seconds. |
| 60 | +# TYPE process_start_time_seconds gauge |
| 61 | +process_start_time_seconds 1580409821 |
| 62 | +
|
| 63 | +# HELP process_resident_memory_bytes Resident memory size in bytes. |
| 64 | +# TYPE process_resident_memory_bytes gauge |
| 65 | +process_resident_memory_bytes 27602944 1580409960992 |
| 66 | +
|
| 67 | +# HELP nodejs_eventloop_lag_seconds Lag of event loop in seconds. |
| 68 | +# TYPE nodejs_eventloop_lag_seconds gauge |
| 69 | +nodejs_eventloop_lag_seconds 0.000334835 1580409960992 |
| 70 | +
|
| 71 | +# HELP nodejs_active_handles Number of active libuv handles grouped by handle type. Every handle type is C++ class name. |
| 72 | +# TYPE nodejs_active_handles gauge |
| 73 | +nodejs_active_handles{type="WriteStream"} 2 |
| 74 | +nodejs_active_handles{type="ReadStream"} 1 |
| 75 | +nodejs_active_handles{type="Server"} 1 |
| 76 | +nodejs_active_handles{type="Socket"} 2 |
| 77 | +
|
| 78 | +# HELP nodejs_active_handles_total Total number of active handles. |
| 79 | +# TYPE nodejs_active_handles_total gauge |
| 80 | +nodejs_active_handles_total 6 |
| 81 | +
|
| 82 | +# HELP nodejs_active_requests Number of active libuv requests grouped by request type. Every request type is C++ class name. |
| 83 | +# TYPE nodejs_active_requests gauge |
| 84 | +
|
| 85 | +# HELP nodejs_active_requests_total Total number of active requests. |
| 86 | +# TYPE nodejs_active_requests_total gauge |
| 87 | +nodejs_active_requests_total 0 1580409960992 |
| 88 | +
|
| 89 | +# HELP nodejs_heap_size_total_bytes Process heap size from node.js in bytes. |
| 90 | +# TYPE nodejs_heap_size_total_bytes gauge |
| 91 | +nodejs_heap_size_total_bytes 7970816 |
| 92 | +
|
| 93 | +# HELP nodejs_heap_size_used_bytes Process heap size used from node.js in bytes. |
| 94 | +# TYPE nodejs_heap_size_used_bytes gauge |
| 95 | +nodejs_heap_size_used_bytes 6371536 |
| 96 | +
|
| 97 | +# HELP nodejs_external_memory_bytes Nodejs external memory size in bytes. |
| 98 | +# TYPE nodejs_external_memory_bytes gauge |
| 99 | +nodejs_external_memory_bytes 1346123 |
| 100 | +
|
| 101 | +# HELP nodejs_heap_space_size_total_bytes Process heap space size total from node.js in bytes. |
| 102 | +# TYPE nodejs_heap_space_size_total_bytes gauge |
| 103 | +nodejs_heap_space_size_total_bytes{space="read_only"} 262144 1580409960992 |
| 104 | +nodejs_heap_space_size_total_bytes{space="new"} 1048576 1580409960992 |
| 105 | +nodejs_heap_space_size_total_bytes{space="old"} 4857856 1580409960992 |
| 106 | +nodejs_heap_space_size_total_bytes{space="code"} 430080 1580409960992 |
| 107 | +nodejs_heap_space_size_total_bytes{space="map"} 790528 1580409960992 |
| 108 | +nodejs_heap_space_size_total_bytes{space="large_object"} 532480 1580409960992 |
| 109 | +nodejs_heap_space_size_total_bytes{space="code_large_object"} 49152 1580409960992 |
| 110 | +nodejs_heap_space_size_total_bytes{space="new_large_object"} 0 1580409960992 |
| 111 | +
|
| 112 | +# HELP nodejs_heap_space_size_used_bytes Process heap space size used from node.js in bytes. |
| 113 | +# TYPE nodejs_heap_space_size_used_bytes gauge |
| 114 | +nodejs_heap_space_size_used_bytes{space="read_only"} 33040 1580409960992 |
| 115 | +nodejs_heap_space_size_used_bytes{space="new"} 1005984 1580409960992 |
| 116 | +nodejs_heap_space_size_used_bytes{space="old"} 4272040 1580409960992 |
| 117 | +nodejs_heap_space_size_used_bytes{space="code"} 181120 1580409960992 |
| 118 | +nodejs_heap_space_size_used_bytes{space="map"} 354240 1580409960992 |
| 119 | +nodejs_heap_space_size_used_bytes{space="large_object"} 524344 1580409960992 |
| 120 | +nodejs_heap_space_size_used_bytes{space="code_large_object"} 2784 1580409960992 |
| 121 | +nodejs_heap_space_size_used_bytes{space="new_large_object"} 0 1580409960992 |
| 122 | +
|
| 123 | +# HELP nodejs_heap_space_size_available_bytes Process heap space size available from node.js in bytes. |
| 124 | +# TYPE nodejs_heap_space_size_available_bytes gauge |
| 125 | +nodejs_heap_space_size_available_bytes{space="read_only"} 0 1580409960992 |
| 126 | +nodejs_heap_space_size_available_bytes{space="new"} 41440 1580409960992 |
| 127 | +nodejs_heap_space_size_available_bytes{space="old"} 570664 1580409960992 |
| 128 | +nodejs_heap_space_size_available_bytes{space="code"} 12000 1580409960992 |
| 129 | +nodejs_heap_space_size_available_bytes{space="map"} 434640 1580409960992 |
| 130 | +nodejs_heap_space_size_available_bytes{space="large_object"} 0 1580409960992 |
| 131 | +nodejs_heap_space_size_available_bytes{space="code_large_object"} 0 1580409960992 |
| 132 | +nodejs_heap_space_size_available_bytes{space="new_large_object"} 1047424 1580409960992 |
| 133 | +
|
| 134 | +# HELP nodejs_version_info Node.js version info. |
| 135 | +# TYPE nodejs_version_info gauge |
| 136 | +nodejs_version_info{version="v13.7.0",major="13",minor="7",patch="0"} 1 |
| 137 | +
|
| 138 | +# HELP http_request_duration_seconds duration histogram of http responses labeled with: status_code, method, path |
| 139 | +# TYPE http_request_duration_seconds histogram |
| 140 | +http_request_duration_seconds_bucket{le="0.025",status_code="200",method="GET",path="/"} 12 |
| 141 | +http_request_duration_seconds_bucket{le="0.05",status_code="200",method="GET",path="/"} 12 |
| 142 | +http_request_duration_seconds_bucket{le="0.1",status_code="200",method="GET",path="/"} 12 |
| 143 | +http_request_duration_seconds_bucket{le="0.15",status_code="200",method="GET",path="/"} 17 |
| 144 | +http_request_duration_seconds_bucket{le="0.2",status_code="200",method="GET",path="/"} 17 |
| 145 | +http_request_duration_seconds_bucket{le="0.25",status_code="200",method="GET",path="/"} 17 |
| 146 | +http_request_duration_seconds_bucket{le="0.3",status_code="200",method="GET",path="/"} 17 |
| 147 | +http_request_duration_seconds_bucket{le="0.35",status_code="200",method="GET",path="/"} 17 |
| 148 | +http_request_duration_seconds_bucket{le="0.45",status_code="200",method="GET",path="/"} 17 |
| 149 | +http_request_duration_seconds_bucket{le="0.5",status_code="200",method="GET",path="/"} 17 |
| 150 | +http_request_duration_seconds_bucket{le="0.55",status_code="200",method="GET",path="/"} 17 |
| 151 | +http_request_duration_seconds_bucket{le="0.6",status_code="200",method="GET",path="/"} 17 |
| 152 | +http_request_duration_seconds_bucket{le="0.75",status_code="200",method="GET",path="/"} 17 |
| 153 | +http_request_duration_seconds_bucket{le="1",status_code="200",method="GET",path="/"} 17 |
| 154 | +http_request_duration_seconds_bucket{le="2.5",status_code="200",method="GET",path="/"} 17 |
| 155 | +http_request_duration_seconds_bucket{le="10",status_code="200",method="GET",path="/"} 17 |
| 156 | +http_request_duration_seconds_bucket{le="+Inf",status_code="200",method="GET",path="/"} 17 |
| 157 | +http_request_duration_seconds_sum{status_code="200",method="GET",path="/"} 0.5371957699999999 |
| 158 | +http_request_duration_seconds_count{status_code="200",method="GET",path="/"} 17 |
| 159 | +``` |
| 160 | + |
0 commit comments