@loopback/example-metrics-prometheus 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.prettierignore +2 -0
  2. package/.prettierrc +7 -0
  3. package/.vscode/settings.json +20 -0
  4. package/.vscode/tasks.json +29 -0
  5. package/CHANGELOG.md +378 -0
  6. package/LICENSE +25 -0
  7. package/README.md +45 -0
  8. package/bin/demo.sh +20 -0
  9. package/bin/prometheus.yml +29 -0
  10. package/dist/__tests__/integration/greeting-service.integration.d.ts +1 -0
  11. package/dist/__tests__/integration/greeting-service.integration.js +34 -0
  12. package/dist/__tests__/integration/greeting-service.integration.js.map +1 -0
  13. package/dist/application.d.ts +98 -0
  14. package/dist/application.js +23 -0
  15. package/dist/application.js.map +1 -0
  16. package/dist/controllers/greeting.controller.d.ts +6 -0
  17. package/dist/controllers/greeting.controller.js +37 -0
  18. package/dist/controllers/greeting.controller.js.map +1 -0
  19. package/dist/controllers/index.d.ts +1 -0
  20. package/dist/controllers/index.js +9 -0
  21. package/dist/controllers/index.js.map +1 -0
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.js +36 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/services/greeting.service.d.ts +3 -0
  26. package/dist/services/greeting.service.js +25 -0
  27. package/dist/services/greeting.service.js.map +1 -0
  28. package/dist/services/index.d.ts +1 -0
  29. package/dist/services/index.js +9 -0
  30. package/dist/services/index.js.map +1 -0
  31. package/package.json +65 -0
  32. package/prometheus-demo.png +0 -0
  33. package/src/__tests__/integration/greeting-service.integration.ts +46 -0
  34. package/src/application.ts +22 -0
  35. package/src/controllers/greeting.controller.ts +27 -0
  36. package/src/controllers/index.ts +6 -0
  37. package/src/index.ts +32 -0
  38. package/src/services/greeting.service.ts +19 -0
  39. package/src/services/index.ts +6 -0
  40. package/tsconfig.json +30 -0
@@ -0,0 +1,2 @@
1
+ dist
2
+ *.json
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "bracketSpacing": false,
3
+ "singleQuote": true,
4
+ "printWidth": 80,
5
+ "trailingComma": "all",
6
+ "arrowParens": "avoid"
7
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "editor.rulers": [80],
3
+ "editor.tabCompletion": "on",
4
+ "editor.tabSize": 2,
5
+ "editor.trimAutoWhitespace": true,
6
+ "editor.formatOnSave": true,
7
+
8
+ "files.exclude": {
9
+ "**/.DS_Store": true,
10
+ "**/.git": true,
11
+ "**/.hg": true,
12
+ "**/.svn": true,
13
+ "**/CVS": true,
14
+ "dist": true,
15
+ },
16
+ "files.insertFinalNewline": true,
17
+ "files.trimTrailingWhitespace": true,
18
+
19
+ "typescript.tsdk": "./node_modules/typescript/lib"
20
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
3
+ // for the documentation about the tasks.json format
4
+ "version": "2.0.0",
5
+ "tasks": [
6
+ {
7
+ "label": "Watch and Compile Project",
8
+ "type": "shell",
9
+ "command": "npm",
10
+ "args": ["--silent", "run", "build:watch"],
11
+ "group": {
12
+ "kind": "build",
13
+ "isDefault": true
14
+ },
15
+ "problemMatcher": "$tsc-watch"
16
+ },
17
+ {
18
+ "label": "Build, Test and Lint",
19
+ "type": "shell",
20
+ "command": "npm",
21
+ "args": ["--silent", "run", "test:dev"],
22
+ "group": {
23
+ "kind": "test",
24
+ "isDefault": true
25
+ },
26
+ "problemMatcher": ["$tsc", "$tslint5"]
27
+ }
28
+ ]
29
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,378 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [0.7.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.7.0...@loopback/example-metrics-prometheus@0.7.1) (2021-09-16)
7
+
8
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
9
+
10
+
11
+
12
+
13
+
14
+ # [0.7.0](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.6.1...@loopback/example-metrics-prometheus@0.7.0) (2021-07-15)
15
+
16
+
17
+ ### Features
18
+
19
+ * **rest:** upgrade to ajv@8.x ([d3b20ed](https://github.com/loopbackio/loopback-next/commit/d3b20edc142d5c014c17ffbfa69f74403793330f))
20
+
21
+
22
+ ### BREAKING CHANGES
23
+
24
+ * **rest:** We upgrade to ajv@8.x, which contains breaking changes
25
+ for validations. See https://github.com/ajv-validator/ajv/blob/master/docs/v6-to-v8-migration.md.
26
+
27
+ Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
28
+
29
+
30
+
31
+
32
+
33
+ ## [0.6.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.6.0...@loopback/example-metrics-prometheus@0.6.1) (2021-06-10)
34
+
35
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
36
+
37
+
38
+
39
+
40
+
41
+ # [0.6.0](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.5.1...@loopback/example-metrics-prometheus@0.6.0) (2021-05-03)
42
+
43
+
44
+ ### Features
45
+
46
+ * support node v16 ([ac99415](https://github.com/loopbackio/loopback-next/commit/ac994154543bde22b4482ba98813351656db1b55))
47
+
48
+
49
+
50
+
51
+
52
+ ## [0.5.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.5.0...@loopback/example-metrics-prometheus@0.5.1) (2021-04-06)
53
+
54
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
55
+
56
+
57
+
58
+
59
+
60
+ # [0.5.0](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.7...@loopback/example-metrics-prometheus@0.5.0) (2021-03-18)
61
+
62
+
63
+ ### Features
64
+
65
+ * update package-lock.json to v2 consistently ([dfc3fbd](https://github.com/loopbackio/loopback-next/commit/dfc3fbdae0c9ca9f34c64154a471bef22d5ac6b7))
66
+ * upgrade to TypeScript 4.2.x ([05930bc](https://github.com/loopbackio/loopback-next/commit/05930bc0cece3909dd66f75ad91eeaa2d365a480))
67
+
68
+
69
+
70
+
71
+
72
+ ## [0.4.7](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.6...@loopback/example-metrics-prometheus@0.4.7) (2021-02-09)
73
+
74
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
75
+
76
+
77
+
78
+
79
+
80
+ ## [0.4.6](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.5...@loopback/example-metrics-prometheus@0.4.6) (2021-01-21)
81
+
82
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
83
+
84
+
85
+
86
+
87
+
88
+ ## [0.4.5](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.4...@loopback/example-metrics-prometheus@0.4.5) (2020-12-07)
89
+
90
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
91
+
92
+
93
+
94
+
95
+
96
+ ## [0.4.4](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.3...@loopback/example-metrics-prometheus@0.4.4) (2020-11-18)
97
+
98
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
99
+
100
+
101
+
102
+
103
+
104
+ ## [0.4.3](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.2...@loopback/example-metrics-prometheus@0.4.3) (2020-11-05)
105
+
106
+
107
+ ### Bug Fixes
108
+
109
+ * **cli:** update affected example projects ([a4386e9](https://github.com/loopbackio/loopback-next/commit/a4386e921713739417de5d4795950209d2f14e22)), closes [#3259](https://github.com/loopbackio/loopback-next/issues/3259)
110
+
111
+
112
+
113
+
114
+
115
+ ## [0.4.2](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.1...@loopback/example-metrics-prometheus@0.4.2) (2020-10-07)
116
+
117
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
118
+
119
+
120
+
121
+
122
+
123
+ ## [0.4.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.4.0...@loopback/example-metrics-prometheus@0.4.1) (2020-09-17)
124
+
125
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
126
+
127
+
128
+
129
+
130
+
131
+ # [0.4.0](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.9...@loopback/example-metrics-prometheus@0.4.0) (2020-09-15)
132
+
133
+
134
+ ### Features
135
+
136
+ * update examples and docs to use `@loopback/*` instead of `@loopback/extension-*` ([a96b7cb](https://github.com/loopbackio/loopback-next/commit/a96b7cbb2e146f941b1fec0e7dd0b0829dcd0245))
137
+
138
+
139
+
140
+
141
+
142
+ ## [0.3.9](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.8...@loopback/example-metrics-prometheus@0.3.9) (2020-08-27)
143
+
144
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
145
+
146
+
147
+
148
+
149
+
150
+ ## [0.3.8](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.7...@loopback/example-metrics-prometheus@0.3.8) (2020-08-19)
151
+
152
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
153
+
154
+
155
+
156
+
157
+
158
+ ## [0.3.7](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.6...@loopback/example-metrics-prometheus@0.3.7) (2020-08-05)
159
+
160
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
161
+
162
+
163
+
164
+
165
+
166
+ ## [0.3.6](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.5...@loopback/example-metrics-prometheus@0.3.6) (2020-07-20)
167
+
168
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
169
+
170
+
171
+
172
+
173
+
174
+ ## [0.3.5](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.4...@loopback/example-metrics-prometheus@0.3.5) (2020-06-30)
175
+
176
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
177
+
178
+
179
+
180
+
181
+
182
+ ## [0.3.4](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.3...@loopback/example-metrics-prometheus@0.3.4) (2020-06-23)
183
+
184
+
185
+ ### Bug Fixes
186
+
187
+ * set node version to >=10.16 to support events.once ([e39da1c](https://github.com/loopbackio/loopback-next/commit/e39da1ca47728eafaf83c10ce35b09b03b6a4edc))
188
+
189
+
190
+
191
+
192
+
193
+ ## [0.3.3](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.2...@loopback/example-metrics-prometheus@0.3.3) (2020-06-11)
194
+
195
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
196
+
197
+
198
+
199
+
200
+
201
+ ## [0.3.2](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.1...@loopback/example-metrics-prometheus@0.3.2) (2020-05-28)
202
+
203
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
204
+
205
+
206
+
207
+
208
+
209
+ ## [0.3.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.3.0...@loopback/example-metrics-prometheus@0.3.1) (2020-05-20)
210
+
211
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
212
+
213
+
214
+
215
+
216
+
217
+ # [0.3.0](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.8...@loopback/example-metrics-prometheus@0.3.0) (2020-05-19)
218
+
219
+
220
+ ### Features
221
+
222
+ * upgrade to TypeScript 3.9.x ([3300e45](https://github.com/loopbackio/loopback-next/commit/3300e4569ab8410bb1285f7a54d326e9d976476d))
223
+
224
+
225
+
226
+
227
+
228
+ ## [0.2.8](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.7...@loopback/example-metrics-prometheus@0.2.8) (2020-05-07)
229
+
230
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
231
+
232
+
233
+
234
+
235
+
236
+ ## [0.2.7](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.6...@loopback/example-metrics-prometheus@0.2.7) (2020-04-29)
237
+
238
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
239
+
240
+
241
+
242
+
243
+
244
+ ## [0.2.6](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.5...@loopback/example-metrics-prometheus@0.2.6) (2020-04-23)
245
+
246
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
247
+
248
+
249
+
250
+
251
+
252
+ ## [0.2.5](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.4...@loopback/example-metrics-prometheus@0.2.5) (2020-04-22)
253
+
254
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
255
+
256
+
257
+
258
+
259
+
260
+ ## [0.2.4](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.3...@loopback/example-metrics-prometheus@0.2.4) (2020-04-11)
261
+
262
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
263
+
264
+
265
+
266
+
267
+
268
+ ## [0.2.3](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.2...@loopback/example-metrics-prometheus@0.2.3) (2020-04-08)
269
+
270
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
271
+
272
+
273
+
274
+
275
+
276
+ ## [0.2.2](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.1...@loopback/example-metrics-prometheus@0.2.2) (2020-03-24)
277
+
278
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
279
+
280
+
281
+
282
+
283
+
284
+ ## [0.2.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.2.0...@loopback/example-metrics-prometheus@0.2.1) (2020-03-17)
285
+
286
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
287
+
288
+
289
+
290
+
291
+
292
+ # [0.2.0](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.7...@loopback/example-metrics-prometheus@0.2.0) (2020-03-05)
293
+
294
+
295
+ ### chore
296
+
297
+ * remove support for Node.js v8.x ([4281d9d](https://github.com/loopbackio/loopback-next/commit/4281d9df50f0715d32879e1442a90b643ec8f542))
298
+
299
+
300
+ ### Features
301
+
302
+ * add `tslib` as dependency ([a6e0b4c](https://github.com/loopbackio/loopback-next/commit/a6e0b4ce7b862764167cefedee14c1115b25e0a4)), closes [#4676](https://github.com/loopbackio/loopback-next/issues/4676)
303
+
304
+
305
+ ### BREAKING CHANGES
306
+
307
+ * Node.js v8.x is now end of life. Please upgrade to version
308
+ 10 and above. See https://nodejs.org/en/about/releases.
309
+
310
+
311
+
312
+
313
+
314
+ ## [0.1.7](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.6...@loopback/example-metrics-prometheus@0.1.7) (2020-02-06)
315
+
316
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
317
+
318
+
319
+
320
+
321
+
322
+ ## [0.1.6](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.5...@loopback/example-metrics-prometheus@0.1.6) (2020-02-05)
323
+
324
+
325
+ ### Bug Fixes
326
+
327
+ * update clean script for examples to be compatible with `lb4 example` ([d9f5741](https://github.com/loopbackio/loopback-next/commit/d9f574160f6edbf73a8f728cd3695ca69297148a))
328
+
329
+
330
+
331
+
332
+
333
+ ## [0.1.5](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.4...@loopback/example-metrics-prometheus@0.1.5) (2020-01-27)
334
+
335
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
336
+
337
+
338
+
339
+
340
+
341
+ ## [0.1.4](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.3...@loopback/example-metrics-prometheus@0.1.4) (2020-01-07)
342
+
343
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
344
+
345
+
346
+
347
+
348
+
349
+ ## [0.1.3](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.2...@loopback/example-metrics-prometheus@0.1.3) (2020-01-07)
350
+
351
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
352
+
353
+
354
+
355
+
356
+
357
+ ## [0.1.2](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.1...@loopback/example-metrics-prometheus@0.1.2) (2019-12-09)
358
+
359
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
360
+
361
+
362
+
363
+
364
+
365
+ ## [0.1.1](https://github.com/loopbackio/loopback-next/compare/@loopback/example-metrics-prometheus@0.1.0...@loopback/example-metrics-prometheus@0.1.1) (2019-11-25)
366
+
367
+ **Note:** Version bump only for package @loopback/example-metrics-prometheus
368
+
369
+
370
+
371
+
372
+
373
+ # 0.1.0 (2019-11-12)
374
+
375
+
376
+ ### Features
377
+
378
+ * **example-metrics-prometheus:** add an example for prometheus metrics ([2c11c6d](https://github.com/loopbackio/loopback-next/commit/2c11c6da2d390335641d44244703e18f0c7599a3))
package/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) IBM Corp. 2019.
2
+ Node module: @loopback/example-metrics-prometheus
3
+ This project is licensed under the MIT License, full text below.
4
+
5
+ --------
6
+
7
+ MIT license
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @loopback/example-metrics-prometheus
2
+
3
+ This project contains an example to illustrate metrics provided by
4
+ [`@loopback/metrics`](https://github.com/loopbackio/loopback-next/blob/master/extensions/metrics)
5
+ and [Prometheus](https://prometheus.io/).
6
+
7
+ ## Use
8
+
9
+ ```sh
10
+ npm start
11
+ ```
12
+
13
+ To run full demo:
14
+
15
+ ```sh
16
+ npm run demo
17
+ ```
18
+
19
+ Now let's generate some traffic:
20
+
21
+ http://127.0.0.1:3000/greet/world?count=50
22
+
23
+ The metrics is reported at http://127.0.0.1:3000/metrics.
24
+
25
+ Open http://localhost:9090 for the Prometheus Web UI.
26
+
27
+ ![Prometheus Demo](prometheus-demo.png)
28
+
29
+ ## Contributions
30
+
31
+ - [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
32
+ - [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
33
+
34
+ ## Tests
35
+
36
+ Run `npm test` from the root folder.
37
+
38
+ ## Contributors
39
+
40
+ See
41
+ [all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
42
+
43
+ ## License
44
+
45
+ MIT
package/bin/demo.sh ADDED
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+
3
+ # This script runs prometheus to scape and visulize metrics collected for the
4
+ # example LoopBack 4 application.
5
+
6
+ DIR=`dirname $0`
7
+ CWD=`pwd`
8
+ CONFIG=$CWD/$DIR/prometheus.yml
9
+
10
+ PROM_CONTAINER_NAME="prometheus_lb4_demo"
11
+ docker rm -f $PROM_CONTAINER_NAME
12
+ docker pull prom/prometheus:latest
13
+ docker run --name $PROM_CONTAINER_NAME -p 9090:9090 -v $CONFIG:/etc/prometheus/prometheus.yml -d prom/prometheus
14
+
15
+ echo Prometheus is running at http://localhost:9090.
16
+
17
+ pushd $DIR/.. >/dev/null
18
+ npm run build
19
+ node .
20
+ popd
@@ -0,0 +1,29 @@
1
+ # my global config
2
+ global:
3
+ scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
4
+ evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
5
+ # scrape_timeout is set to the global default (10s).
6
+
7
+ # Alertmanager configuration
8
+ alerting:
9
+ alertmanagers:
10
+ - static_configs:
11
+ - targets:
12
+ # - alertmanager:9093
13
+
14
+ # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
15
+ rule_files:
16
+ # - "first_rules.yml"
17
+ # - "second_rules.yml"
18
+
19
+ # A scrape configuration containing exactly one endpoint to scrape:
20
+ # Here it's Prometheus itself.
21
+ scrape_configs:
22
+ # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
23
+ - job_name: 'prometheus'
24
+
25
+ # metrics_path defaults to '/metrics'
26
+ # scheme defaults to 'http'.
27
+
28
+ static_configs:
29
+ - targets: ['host.docker.internal:3000']
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019,2020. All Rights Reserved.
3
+ // Node module: @loopback/example-metrics-prometheus
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const testlab_1 = require("@loopback/testlab");
8
+ const __1 = require("../..");
9
+ describe('GreetingApplication', () => {
10
+ let app;
11
+ let client;
12
+ before(givenRunningApplicationWithCustomConfiguration);
13
+ after(() => app.stop());
14
+ before(() => {
15
+ client = testlab_1.createRestAppClient(app);
16
+ });
17
+ it('gets greetings', async function () {
18
+ const response = await client.get('/greet/Raymond').expect(200);
19
+ testlab_1.expect(response.body).to.be.an.Array();
20
+ testlab_1.expect(response.body[0]).to.match(/Hello, Raymond/);
21
+ });
22
+ it('reports metrics', async function () {
23
+ const response = await client.get('/metrics').expect(200);
24
+ testlab_1.expect(response.text).to.match(/TYPE loopback_invocation_duration_seconds gauge/);
25
+ });
26
+ async function givenRunningApplicationWithCustomConfiguration() {
27
+ app = new __1.GreetingApplication({
28
+ rest: testlab_1.givenHttpServerConfig(),
29
+ });
30
+ // Start Application
31
+ await app.main();
32
+ }
33
+ });
34
+ //# sourceMappingURL=greeting-service.integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"greeting-service.integration.js","sourceRoot":"","sources":["../../../src/__tests__/integration/greeting-service.integration.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oDAAoD;AACpD,+CAA+C;AAC/C,gEAAgE;;AAEhE,+CAK2B;AAC3B,6BAA0C;AAE1C,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,IAAI,GAAwB,CAAC;IAC7B,IAAI,MAAc,CAAC;IAEnB,MAAM,CAAC,8CAA8C,CAAC,CAAC;IACvD,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAExB,MAAM,CAAC,GAAG,EAAE;QACV,MAAM,GAAG,6BAAmB,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gBAAgB,EAAE,KAAK;QACxB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChE,gBAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACvC,gBAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iBAAiB,EAAE,KAAK;QACzB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1D,gBAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAC5B,iDAAiD,CAClD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,KAAK,UAAU,8CAA8C;QAC3D,GAAG,GAAG,IAAI,uBAAmB,CAAC;YAC5B,IAAI,EAAE,+BAAqB,EAAE;SAC9B,CAAC,CAAC;QAEH,oBAAoB;QACpB,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { ApplicationConfig } from '@loopback/core';
2
+ import { RestApplication } from '@loopback/rest';
3
+ declare const GreetingApplication_base: (new (...args: any[]) => {
4
+ projectRoot: string;
5
+ bootOptions?: import("@loopback/boot").BootOptions | undefined;
6
+ booted: boolean;
7
+ start(): Promise<void>;
8
+ boot(): Promise<void>;
9
+ booters(...booterCls: import("@loopback/core").Constructor<import("@loopback/boot").Booter>[]): import("@loopback/boot").Binding<any>[];
10
+ applicationBooter(subApp: import("@loopback/core").Application & import("@loopback/boot").Bootable, filter?: import("@loopback/core").BindingFilter | undefined): import("@loopback/boot").Binding<import("@loopback/boot").Booter>;
11
+ component<C extends import("@loopback/core").Component = import("@loopback/core").Component>(componentCtor: import("@loopback/core").Constructor<C>, nameOrOptions?: string | import("@loopback/core").BindingFromClassOptions | undefined): import("@loopback/boot").Binding<C>;
12
+ mountComponentBooters(componentInstanceOrClass: import("@loopback/core").Constructor<unknown> | import("@loopback/boot").InstanceWithBooters): void;
13
+ readonly options: ApplicationConfig;
14
+ readonly state: string;
15
+ controller: <T_1>(controllerCtor: import("@loopback/core").ControllerClass<T_1>, nameOrOptions?: string | import("@loopback/core").BindingFromClassOptions | undefined) => import("@loopback/boot").Binding<T_1>;
16
+ server: <T_2 extends import("@loopback/core").Server>(ctor: import("@loopback/core").Constructor<T_2>, nameOrOptions?: string | import("@loopback/core").BindingFromClassOptions | undefined) => import("@loopback/boot").Binding<T_2>;
17
+ servers: <T_3 extends import("@loopback/core").Server>(ctors: import("@loopback/core").Constructor<T_3>[]) => import("@loopback/boot").Binding<any>[];
18
+ getServer: <T_4 extends import("@loopback/core").Server>(target: string | import("@loopback/core").Constructor<T_4>) => Promise<T_4>;
19
+ init: () => Promise<void>;
20
+ onInit: (fn: () => import("@loopback/core").ValueOrPromise<void>) => import("@loopback/boot").Binding<import("@loopback/core").LifeCycleObserver>;
21
+ onStart: (fn: () => import("@loopback/core").ValueOrPromise<void>) => import("@loopback/boot").Binding<import("@loopback/core").LifeCycleObserver>;
22
+ stop: () => Promise<void>;
23
+ onStop: (fn: () => import("@loopback/core").ValueOrPromise<void>) => import("@loopback/boot").Binding<import("@loopback/core").LifeCycleObserver>;
24
+ setMetadata: (metadata: import("@loopback/core").ApplicationMetadata) => void;
25
+ lifeCycleObserver: <T_5 extends import("@loopback/core").LifeCycleObserver>(ctor: import("@loopback/core").Constructor<T_5>, nameOrOptions?: string | import("@loopback/core").BindingFromClassOptions | undefined) => import("@loopback/boot").Binding<T_5>;
26
+ service: <S>(cls: import("@loopback/core").ServiceOrProviderClass<S>, nameOrOptions?: string | import("@loopback/core").ServiceOptions | undefined) => import("@loopback/boot").Binding<S>;
27
+ interceptor: (interceptor: import("@loopback/core").Interceptor | import("@loopback/core").Constructor<import("@loopback/core").Provider<import("@loopback/core").Interceptor>>, nameOrOptions?: string | import("@loopback/core").InterceptorBindingOptions | undefined) => import("@loopback/boot").Binding<import("@loopback/core").Interceptor>;
28
+ readonly name: string;
29
+ readonly subscriptionManager: import("@loopback/core").ContextSubscriptionManager;
30
+ scope: import("@loopback/core").BindingScope;
31
+ readonly parent: import("@loopback/core").Context | undefined;
32
+ emitEvent: <T_6 extends import("@loopback/core").ContextEvent>(type: string, event: T_6) => void;
33
+ emitError: (err: unknown) => void;
34
+ bind: <ValueType = any>(key: import("@loopback/core").BindingAddress<ValueType>) => import("@loopback/boot").Binding<ValueType>;
35
+ add: (binding: import("@loopback/boot").Binding<unknown>) => import("@loopback/core").Application;
36
+ configure: <ConfigValueType = any>(key?: import("@loopback/core").BindingAddress<unknown> | undefined) => import("@loopback/boot").Binding<ConfigValueType>;
37
+ getConfigAsValueOrPromise: <ConfigValueType_1>(key: import("@loopback/core").BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => import("@loopback/core").ValueOrPromise<ConfigValueType_1 | undefined>;
38
+ getConfig: <ConfigValueType_2>(key: import("@loopback/core").BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
39
+ getConfigSync: <ConfigValueType_3>(key: import("@loopback/core").BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
40
+ unbind: (key: import("@loopback/core").BindingAddress<unknown>) => boolean;
41
+ subscribe: (observer: import("@loopback/core").ContextEventObserver) => import("@loopback/core").Subscription;
42
+ unsubscribe: (observer: import("@loopback/core").ContextEventObserver) => boolean;
43
+ close: () => void;
44
+ isSubscribed: (observer: import("@loopback/core").ContextObserver) => boolean;
45
+ createView: <T_7 = unknown>(filter: import("@loopback/core").BindingFilter, comparator?: import("@loopback/core").BindingComparator | undefined) => import("@loopback/core").ContextView<T_7>;
46
+ contains: (key: import("@loopback/core").BindingAddress<unknown>) => boolean;
47
+ isBound: (key: import("@loopback/core").BindingAddress<unknown>) => boolean;
48
+ getOwnerContext: (keyOrBinding: import("@loopback/core").BindingAddress<unknown> | Readonly<import("@loopback/boot").Binding<unknown>>) => import("@loopback/core").Context | undefined;
49
+ getScopedContext: (scope: import("@loopback/core").BindingScope.APPLICATION | import("@loopback/core").BindingScope.SERVER | import("@loopback/core").BindingScope.REQUEST) => import("@loopback/core").Context | undefined;
50
+ getResolutionContext: (binding: Readonly<import("@loopback/boot").Binding<unknown>>) => import("@loopback/core").Context | undefined;
51
+ isVisibleTo: (ctx: import("@loopback/core").Context) => boolean;
52
+ find: <ValueType_1 = any>(pattern?: string | RegExp | import("@loopback/core").BindingFilter | undefined) => Readonly<import("@loopback/boot").Binding<ValueType_1>>[];
53
+ findByTag: <ValueType_2 = any>(tagFilter: RegExp | import("@loopback/core").BindingTag) => Readonly<import("@loopback/boot").Binding<ValueType_2>>[];
54
+ get: {
55
+ <ValueType_3>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_3>, session?: import("@loopback/core").ResolutionSession | undefined): Promise<ValueType_3>;
56
+ <ValueType_4>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_4>, options: import("@loopback/core").ResolutionOptions): Promise<ValueType_4 | undefined>;
57
+ };
58
+ getSync: {
59
+ <ValueType_5>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_5>, session?: import("@loopback/core").ResolutionSession | undefined): ValueType_5;
60
+ <ValueType_6>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_6>, options?: import("@loopback/core").ResolutionOptions | undefined): ValueType_6 | undefined;
61
+ };
62
+ getBinding: {
63
+ <ValueType_7 = any>(key: import("@loopback/core").BindingAddress<ValueType_7>): import("@loopback/boot").Binding<ValueType_7>;
64
+ <ValueType_8>(key: import("@loopback/core").BindingAddress<ValueType_8>, options?: {
65
+ optional?: boolean | undefined;
66
+ } | undefined): import("@loopback/boot").Binding<ValueType_8> | undefined;
67
+ };
68
+ findOrCreateBinding: <T_8>(key: import("@loopback/core").BindingAddress<T_8>, policy?: import("@loopback/core").BindingCreationPolicy | undefined) => import("@loopback/boot").Binding<T_8>;
69
+ getValueOrPromise: <ValueType_9>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_9>, optionsOrSession?: import("@loopback/core").ResolutionOptionsOrSession | undefined) => import("@loopback/core").ValueOrPromise<ValueType_9 | undefined>;
70
+ toJSON: () => import("@loopback/core").JSONObject;
71
+ inspect: (options?: import("@loopback/core").ContextInspectOptions | undefined) => import("@loopback/core").JSONObject;
72
+ on: {
73
+ (eventName: "bind" | "unbind", listener: import("@loopback/core").ContextEventListener): import("@loopback/core").Application;
74
+ (event: string | symbol, listener: (...args: any[]) => void): import("@loopback/core").Application;
75
+ };
76
+ once: {
77
+ (eventName: "bind" | "unbind", listener: import("@loopback/core").ContextEventListener): import("@loopback/core").Application;
78
+ (event: string | symbol, listener: (...args: any[]) => void): import("@loopback/core").Application;
79
+ };
80
+ addListener: (event: string | symbol, listener: (...args: any[]) => void) => import("@loopback/core").Application;
81
+ removeListener: (event: string | symbol, listener: (...args: any[]) => void) => import("@loopback/core").Application;
82
+ off: (event: string | symbol, listener: (...args: any[]) => void) => import("@loopback/core").Application;
83
+ removeAllListeners: (event?: string | symbol | undefined) => import("@loopback/core").Application;
84
+ setMaxListeners: (n: number) => import("@loopback/core").Application;
85
+ getMaxListeners: () => number;
86
+ listeners: (event: string | symbol) => Function[];
87
+ rawListeners: (event: string | symbol) => Function[];
88
+ emit: (event: string | symbol, ...args: any[]) => boolean;
89
+ listenerCount: (type: string | symbol) => number;
90
+ prependListener: (event: string | symbol, listener: (...args: any[]) => void) => import("@loopback/core").Application;
91
+ prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => import("@loopback/core").Application;
92
+ eventNames: () => (string | symbol)[];
93
+ }) & typeof RestApplication;
94
+ export declare class GreetingApplication extends GreetingApplication_base {
95
+ constructor(config?: ApplicationConfig);
96
+ main(): Promise<void>;
97
+ }
98
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019,2020. All Rights Reserved.
3
+ // Node module: @loopback/example-metrics-prometheus
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.GreetingApplication = void 0;
8
+ const boot_1 = require("@loopback/boot");
9
+ const metrics_1 = require("@loopback/metrics");
10
+ const rest_1 = require("@loopback/rest");
11
+ class GreetingApplication extends boot_1.BootMixin(rest_1.RestApplication) {
12
+ constructor(config = {}) {
13
+ super(config);
14
+ this.projectRoot = __dirname;
15
+ this.component(metrics_1.MetricsComponent);
16
+ }
17
+ async main() {
18
+ await this.boot();
19
+ await this.start();
20
+ }
21
+ }
22
+ exports.GreetingApplication = GreetingApplication;
23
+ //# sourceMappingURL=application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oDAAoD;AACpD,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAAyC;AAEzC,+CAAmD;AACnD,yCAA+C;AAE/C,MAAa,mBAAoB,SAAQ,gBAAS,CAAC,sBAAe,CAAC;IACjE,YAAY,SAA4B,EAAE;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,IAAI,CAAC,SAAS,CAAC,0BAAgB,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AAXD,kDAWC"}
@@ -0,0 +1,6 @@
1
+ import { GreetingService } from '../services';
2
+ export declare class GreetingController {
3
+ private greetingService;
4
+ constructor(greetingService: GreetingService);
5
+ greet(name: string, count?: number): Promise<string[]>;
6
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019. All Rights Reserved.
3
+ // Node module: @loopback/example-metrics-prometheus
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.GreetingController = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const core_1 = require("@loopback/core");
10
+ const rest_1 = require("@loopback/rest");
11
+ const services_1 = require("../services");
12
+ let GreetingController = class GreetingController {
13
+ constructor(greetingService) {
14
+ this.greetingService = greetingService;
15
+ }
16
+ async greet(name, count = 1) {
17
+ const tasks = [];
18
+ for (let i = 0; i < count; i++) {
19
+ tasks.push(this.greetingService.greet(name));
20
+ }
21
+ return Promise.all(tasks);
22
+ }
23
+ };
24
+ tslib_1.__decorate([
25
+ rest_1.get('/greet/{name}'),
26
+ tslib_1.__param(0, rest_1.param.path.string('name')),
27
+ tslib_1.__param(1, rest_1.param.query.number('count')),
28
+ tslib_1.__metadata("design:type", Function),
29
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
30
+ tslib_1.__metadata("design:returntype", Promise)
31
+ ], GreetingController.prototype, "greet", null);
32
+ GreetingController = tslib_1.__decorate([
33
+ tslib_1.__param(0, core_1.inject('services.GreetingService', { asProxyWithInterceptors: true })),
34
+ tslib_1.__metadata("design:paramtypes", [services_1.GreetingService])
35
+ ], GreetingController);
36
+ exports.GreetingController = GreetingController;
37
+ //# sourceMappingURL=greeting.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"greeting.controller.js","sourceRoot":"","sources":["../../src/controllers/greeting.controller.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oDAAoD;AACpD,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAAsC;AACtC,yCAA0C;AAC1C,0CAA4C;AAE5C,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAC7B,YAEU,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IACvC,CAAC;IAGJ,KAAK,CAAC,KAAK,CACkB,IAAY,EACV,QAAQ,CAAC;QAEtC,MAAM,KAAK,GAAsB,EAAE,CAAC;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;SAC9C;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AAVC;IADC,UAAG,CAAC,eAAe,CAAC;IAElB,mBAAA,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACzB,mBAAA,YAAK,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;;;;+CAO7B;AAhBU,kBAAkB;IAE1B,mBAAA,aAAM,CAAC,0BAA0B,EAAE,EAAC,uBAAuB,EAAE,IAAI,EAAC,CAAC,CAAA;6CAC3C,0BAAe;GAH/B,kBAAkB,CAiB9B;AAjBY,gDAAkB"}
@@ -0,0 +1 @@
1
+ export * from './greeting.controller';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019. All Rights Reserved.
3
+ // Node module: @loopback/example-metrics-prometheus
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const tslib_1 = require("tslib");
8
+ tslib_1.__exportStar(require("./greeting.controller"), exports);
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/controllers/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oDAAoD;AACpD,+CAA+C;AAC/C,gEAAgE;;;AAEhE,gEAAsC"}
@@ -0,0 +1,2 @@
1
+ export * from './application';
2
+ export declare function main(): Promise<void>;
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019,2020. All Rights Reserved.
3
+ // Node module: @loopback/example-metrics-prometheus
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.main = void 0;
8
+ const tslib_1 = require("tslib");
9
+ tslib_1.__exportStar(require("./application"), exports);
10
+ const application_1 = require("./application");
11
+ async function main() {
12
+ var _a, _b;
13
+ const config = {
14
+ rest: {
15
+ port: +((_a = process.env.PORT) !== null && _a !== void 0 ? _a : 3000),
16
+ host: (_b = process.env.HOST) !== null && _b !== void 0 ? _b : '127.0.0.1',
17
+ openApiSpec: {
18
+ // useful when used with OpenAPI-to-GraphQL to locate your application
19
+ setServersFromRequest: true,
20
+ },
21
+ },
22
+ };
23
+ const app = new application_1.GreetingApplication(config);
24
+ await app.main();
25
+ const url = app.restServer.url;
26
+ console.log(`Greeting service is running at ${url}/greet/world?count=5.`);
27
+ console.log(`Metrics is running at ${url}/metrics`);
28
+ }
29
+ exports.main = main;
30
+ if (require.main === module) {
31
+ main().catch(err => {
32
+ console.error('Cannot start the application.', err);
33
+ process.exit(1);
34
+ });
35
+ }
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oDAAoD;AACpD,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,wDAA8B;AAE9B,+CAAkD;AAC3C,KAAK,UAAU,IAAI;;IACxB,MAAM,MAAM,GAAG;QACb,IAAI,EAAE;YACJ,IAAI,EAAE,CAAC,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,IAAI,mCAAI,IAAI,CAAC;YACjC,IAAI,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,IAAI,mCAAI,WAAW;YACrC,WAAW,EAAE;gBACX,sEAAsE;gBACtE,qBAAqB,EAAE,IAAI;aAC5B;SACF;KACF,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,iCAAmB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;IAC/B,OAAO,CAAC,GAAG,CAAC,kCAAkC,GAAG,uBAAuB,CAAC,CAAC;IAC1E,OAAO,CAAC,GAAG,CAAC,yBAAyB,GAAG,UAAU,CAAC,CAAC;AACtD,CAAC;AAhBD,oBAgBC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;IAC3B,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ export declare class GreetingService {
2
+ greet(name: string): Promise<string>;
3
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019. All Rights Reserved.
3
+ // Node module: @loopback/example-metrics-prometheus
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.GreetingService = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const core_1 = require("@loopback/core");
10
+ const util_1 = require("util");
11
+ const sleep = util_1.promisify(setTimeout);
12
+ let GreetingService = class GreetingService {
13
+ async greet(name) {
14
+ const ts = new Date().toISOString();
15
+ // Delay for a random duration between 0 and 100ms
16
+ const delayInMs = Math.floor(Math.random() * 100);
17
+ await sleep(delayInMs);
18
+ return `[${ts}: ${delayInMs}] Hello, ${name}`;
19
+ }
20
+ };
21
+ GreetingService = tslib_1.__decorate([
22
+ core_1.injectable({ tags: { [core_1.ContextTags.NAMESPACE]: 'services' } })
23
+ ], GreetingService);
24
+ exports.GreetingService = GreetingService;
25
+ //# sourceMappingURL=greeting.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"greeting.service.js","sourceRoot":"","sources":["../../src/services/greeting.service.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oDAAoD;AACpD,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAAuD;AACvD,+BAA+B;AAC/B,MAAM,KAAK,GAAG,gBAAS,CAAC,UAAU,CAAC,CAAC;AAGpC,IAAa,eAAe,GAA5B,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACpC,kDAAkD;QAClD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;QAClD,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC;QACvB,OAAO,IAAI,EAAE,KAAK,SAAS,YAAY,IAAI,EAAE,CAAC;IAChD,CAAC;CACF,CAAA;AARY,eAAe;IAD3B,iBAAU,CAAC,EAAC,IAAI,EAAE,EAAC,CAAC,kBAAW,CAAC,SAAS,CAAC,EAAE,UAAU,EAAC,EAAC,CAAC;GAC7C,eAAe,CAQ3B;AARY,0CAAe"}
@@ -0,0 +1 @@
1
+ export * from './greeting.service';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019. All Rights Reserved.
3
+ // Node module: @loopback/example-metrics-prometheus
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const tslib_1 = require("tslib");
8
+ tslib_1.__exportStar(require("./greeting.service"), exports);
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oDAAoD;AACpD,+CAA+C;AAC/C,gEAAgE;;;AAEhE,6DAAmC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@loopback/example-metrics-prometheus",
3
+ "description": "An example to illustrate metrics provided by @loopback/metrics and Prometheus",
4
+ "version": "0.7.1",
5
+ "keywords": [
6
+ "loopback",
7
+ "LoopBack",
8
+ "example",
9
+ "tutorial"
10
+ ],
11
+ "license": "MIT",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "author": "IBM Corp.",
15
+ "copyright.owner": "IBM Corp.",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/loopbackio/loopback-next.git",
19
+ "directory": "examples/metrics-prometheus"
20
+ },
21
+ "engines": {
22
+ "node": "^10.16 || 12 || 14 || 16"
23
+ },
24
+ "scripts": {
25
+ "acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
26
+ "build": "lb-tsc",
27
+ "build:watch": "lb-tsc --watch",
28
+ "clean": "lb-clean *example-metrics-prometheus*.tgz dist *.tsbuildinfo package",
29
+ "verify": "npm pack && tar xf *example-metrics-prometheus*.tgz && tree package && npm run clean",
30
+ "lint": "npm run prettier:check && npm run eslint",
31
+ "lint:fix": "npm run eslint:fix && npm run prettier:fix",
32
+ "prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
33
+ "prettier:check": "npm run prettier:cli -- -l",
34
+ "prettier:fix": "npm run prettier:cli -- --write",
35
+ "eslint": "lb-eslint --report-unused-disable-directives .",
36
+ "eslint:fix": "npm run eslint -- --fix",
37
+ "pretest": "npm run rebuild",
38
+ "test": "lb-mocha \"dist/__tests__/**/*.js\"",
39
+ "posttest": "npm run lint",
40
+ "test:dev": "lb-mocha dist/__tests__/**/*.js && npm run posttest",
41
+ "rebuild": "npm run clean && npm run build",
42
+ "prestart": "npm run rebuild",
43
+ "start": "node .",
44
+ "demo": "./bin/demo.sh"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "dependencies": {
50
+ "@loopback/boot": "^3.4.3",
51
+ "@loopback/core": "^2.17.0",
52
+ "@loopback/metrics": "^0.8.3",
53
+ "@loopback/rest": "^10.0.1",
54
+ "tslib": "^2.3.1"
55
+ },
56
+ "devDependencies": {
57
+ "@loopback/build": "^7.0.1",
58
+ "@loopback/eslint-config": "^11.0.1",
59
+ "@loopback/testlab": "^3.4.3",
60
+ "@types/node": "^10.17.60",
61
+ "eslint": "^7.32.0",
62
+ "typescript": "~4.3.5"
63
+ },
64
+ "gitHead": "1df36bb1ee2e513d9e197bd6010c4cfb296d50b8"
65
+ }
Binary file
@@ -0,0 +1,46 @@
1
+ // Copyright IBM Corp. 2019,2020. All Rights Reserved.
2
+ // Node module: @loopback/example-metrics-prometheus
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {
7
+ Client,
8
+ createRestAppClient,
9
+ expect,
10
+ givenHttpServerConfig,
11
+ } from '@loopback/testlab';
12
+ import {GreetingApplication} from '../..';
13
+
14
+ describe('GreetingApplication', () => {
15
+ let app: GreetingApplication;
16
+ let client: Client;
17
+
18
+ before(givenRunningApplicationWithCustomConfiguration);
19
+ after(() => app.stop());
20
+
21
+ before(() => {
22
+ client = createRestAppClient(app);
23
+ });
24
+
25
+ it('gets greetings', async function () {
26
+ const response = await client.get('/greet/Raymond').expect(200);
27
+ expect(response.body).to.be.an.Array();
28
+ expect(response.body[0]).to.match(/Hello, Raymond/);
29
+ });
30
+
31
+ it('reports metrics', async function () {
32
+ const response = await client.get('/metrics').expect(200);
33
+ expect(response.text).to.match(
34
+ /TYPE loopback_invocation_duration_seconds gauge/,
35
+ );
36
+ });
37
+
38
+ async function givenRunningApplicationWithCustomConfiguration() {
39
+ app = new GreetingApplication({
40
+ rest: givenHttpServerConfig(),
41
+ });
42
+
43
+ // Start Application
44
+ await app.main();
45
+ }
46
+ });
@@ -0,0 +1,22 @@
1
+ // Copyright IBM Corp. 2019,2020. All Rights Reserved.
2
+ // Node module: @loopback/example-metrics-prometheus
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {BootMixin} from '@loopback/boot';
7
+ import {ApplicationConfig} from '@loopback/core';
8
+ import {MetricsComponent} from '@loopback/metrics';
9
+ import {RestApplication} from '@loopback/rest';
10
+
11
+ export class GreetingApplication extends BootMixin(RestApplication) {
12
+ constructor(config: ApplicationConfig = {}) {
13
+ super(config);
14
+ this.projectRoot = __dirname;
15
+ this.component(MetricsComponent);
16
+ }
17
+
18
+ async main() {
19
+ await this.boot();
20
+ await this.start();
21
+ }
22
+ }
@@ -0,0 +1,27 @@
1
+ // Copyright IBM Corp. 2019. All Rights Reserved.
2
+ // Node module: @loopback/example-metrics-prometheus
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {inject} from '@loopback/core';
7
+ import {get, param} from '@loopback/rest';
8
+ import {GreetingService} from '../services';
9
+
10
+ export class GreetingController {
11
+ constructor(
12
+ @inject('services.GreetingService', {asProxyWithInterceptors: true})
13
+ private greetingService: GreetingService,
14
+ ) {}
15
+
16
+ @get('/greet/{name}')
17
+ async greet(
18
+ @param.path.string('name') name: string,
19
+ @param.query.number('count') count = 1,
20
+ ) {
21
+ const tasks: Promise<string>[] = [];
22
+ for (let i = 0; i < count; i++) {
23
+ tasks.push(this.greetingService.greet(name));
24
+ }
25
+ return Promise.all(tasks);
26
+ }
27
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright IBM Corp. 2019. All Rights Reserved.
2
+ // Node module: @loopback/example-metrics-prometheus
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ export * from './greeting.controller';
package/src/index.ts ADDED
@@ -0,0 +1,32 @@
1
+ // Copyright IBM Corp. 2019,2020. All Rights Reserved.
2
+ // Node module: @loopback/example-metrics-prometheus
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ export * from './application';
7
+
8
+ import {GreetingApplication} from './application';
9
+ export async function main() {
10
+ const config = {
11
+ rest: {
12
+ port: +(process.env.PORT ?? 3000),
13
+ host: process.env.HOST ?? '127.0.0.1',
14
+ openApiSpec: {
15
+ // useful when used with OpenAPI-to-GraphQL to locate your application
16
+ setServersFromRequest: true,
17
+ },
18
+ },
19
+ };
20
+ const app = new GreetingApplication(config);
21
+ await app.main();
22
+ const url = app.restServer.url;
23
+ console.log(`Greeting service is running at ${url}/greet/world?count=5.`);
24
+ console.log(`Metrics is running at ${url}/metrics`);
25
+ }
26
+
27
+ if (require.main === module) {
28
+ main().catch(err => {
29
+ console.error('Cannot start the application.', err);
30
+ process.exit(1);
31
+ });
32
+ }
@@ -0,0 +1,19 @@
1
+ // Copyright IBM Corp. 2019. All Rights Reserved.
2
+ // Node module: @loopback/example-metrics-prometheus
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {ContextTags, injectable} from '@loopback/core';
7
+ import {promisify} from 'util';
8
+ const sleep = promisify(setTimeout);
9
+
10
+ @injectable({tags: {[ContextTags.NAMESPACE]: 'services'}})
11
+ export class GreetingService {
12
+ async greet(name: string) {
13
+ const ts = new Date().toISOString();
14
+ // Delay for a random duration between 0 and 100ms
15
+ const delayInMs = Math.floor(Math.random() * 100);
16
+ await sleep(delayInMs);
17
+ return `[${ts}: ${delayInMs}] Hello, ${name}`;
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright IBM Corp. 2019. All Rights Reserved.
2
+ // Node module: @loopback/example-metrics-prometheus
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ export * from './greeting.service';
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "$schema": "http://json.schemastore.org/tsconfig",
3
+ "extends": "@loopback/build/config/tsconfig.common.json",
4
+ "compilerOptions": {
5
+ "outDir": "dist",
6
+ "rootDir": "src",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "src/**/*",
11
+ "src/**/*.json"
12
+ ],
13
+ "references": [
14
+ {
15
+ "path": "../../extensions/metrics/tsconfig.json"
16
+ },
17
+ {
18
+ "path": "../../packages/boot/tsconfig.json"
19
+ },
20
+ {
21
+ "path": "../../packages/core/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../packages/rest/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../packages/testlab/tsconfig.json"
28
+ }
29
+ ]
30
+ }