@superhero/http-server 4.3.8 → 4.4.0

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.
@@ -1,3 +1,5 @@
1
+ import os from 'os'
2
+
1
3
  export function locate(locator)
2
4
  {
3
5
  const server = locator.locate('@superhero/http-server')
@@ -17,14 +19,48 @@ export default class StatusDispatcher
17
19
  this.server = server
18
20
  }
19
21
 
20
- dispatch(_, session)
22
+ dispatch(request, session)
21
23
  {
22
- session.view.body.name = this.server.name
23
- session.view.body.started = this.started_json
24
- session.view.body.uptime = this.started.getTime() - new Date().getTime()
25
- session.view.body.dispatched = String(this.server.dispatched) + 'n'
26
- session.view.body.completed = String(this.server.completed) + 'n'
27
- session.view.body.abortions = String(this.server.abortions) + 'n'
28
- session.view.body.rejections = String(this.server.rejections) + 'n'
24
+ session.view.body.name = this.server.name
25
+ session.view.body.started = this.started_json
26
+
27
+ // Statistics
28
+ if(request.url.query.stats)
29
+ {
30
+ session.view.body.dispatched = String(this.server.dispatched)
31
+ session.view.body.completed = String(this.server.completed)
32
+ session.view.body.abortions = String(this.server.abortions)
33
+ session.view.body.rejections = String(this.server.rejections)
34
+ }
35
+
36
+ // Uptime
37
+ if(request.url.query.uptime)
38
+ {
39
+ session.view.body.uptime = String(this.started.getTime() - new Date().getTime())
40
+ }
41
+
42
+ // CPU usage
43
+ if(request.url.query.cpu)
44
+ {
45
+ session.view.body.cpu = os.cpus().map((cpu) =>
46
+ {
47
+ const
48
+ total = Object.values(cpu.times).reduce((a, b) => a + b, 0),
49
+ usage = Number(((total - cpu.times.idle) / total) * 100).toFixed(2)
50
+
51
+ return { total, usage }
52
+ })
53
+ }
54
+
55
+ // RAM usage
56
+ if(request.url.query.ram)
57
+ {
58
+ const
59
+ total = os.totalmem(),
60
+ free = os.freemem(),
61
+ usage = Number((((total - free) / total) * 100).toFixed(2))
62
+
63
+ session.view.body.ram = { total, usage }
64
+ }
29
65
  }
30
- }
66
+ }
package/index.js CHANGED
@@ -44,7 +44,9 @@ export default class HttpServer
44
44
 
45
45
  async bootstrap(settings)
46
46
  {
47
- const
47
+ Object.assign(this.log.config, settings?.log)
48
+
49
+ const
48
50
  routes = settings?.router?.routes ?? {},
49
51
  serverSettings = Object.assign({}, settings?.server)
50
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/http-server",
3
- "version": "4.3.8",
3
+ "version": "4.4.0",
4
4
  "description": "HTTP(S) server component supporting both HTTP 1.1 and HTTP 2.0",
5
5
  "keywords": [
6
6
  "http server",
@@ -25,11 +25,11 @@
25
25
  "dependencies": {
26
26
  "@superhero/router": "^4.1.4",
27
27
  "@superhero/deep": "^4.1.0",
28
- "@superhero/log": "^4.0.1",
28
+ "@superhero/log": "^4.0.2",
29
29
  "@superhero/id-name-generator": "^4.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@superhero/locator": "^4.3.7",
32
+ "@superhero/locator": "^4.3.8",
33
33
  "@superhero/http-request": "^4.0.10"
34
34
  },
35
35
  "scripts": {