steren commited on
Commit
66e65d0
1 Parent(s): 34c528f

Upload 2 files

Browse files
Files changed (2) hide show
  1. index.js +67 -0
  2. package.json +14 -0
index.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const app = express();
3
+
4
+ const fs = require('node:fs');
5
+ const os = require("node:os");
6
+ const v8 = require("node:v8");
7
+ const process = require('node:process');
8
+
9
+ function handle(signal) {
10
+ console.log(`Received signal ${signal}`);
11
+ }
12
+
13
+ process.on('SIGINT', handle);
14
+ process.on('SIGTERM', handle);
15
+
16
+ app.get('/', (req, res) => {
17
+ console.log('Received a request.');
18
+
19
+ const files = [
20
+ "/sys/fs/cgroup/memory/memory.usage_in_bytes",
21
+ "/sys/fs/cgroup/memory/memory.limit_in_bytes",
22
+ "/sys/fs/cgroup/cpu/cpuacct.usage",
23
+ "/sys/fs/cgroup/cpu/cpu.shares",
24
+ "/sys/fs/cgroup/cpu/cpu.cfs_quota_us",
25
+ "/sys/fs/cgroup/cpu/cpu.cfs_period_us",
26
+ ]
27
+
28
+ let cgroup = {};
29
+ for (let f of files) {
30
+ try {
31
+ cgroup[f] = fs.readFileSync(f, 'utf8');
32
+ } catch(e) {
33
+ console.error(`Cannot read cgroup info for ${f}`, e);
34
+ }
35
+ }
36
+
37
+ let memory = {
38
+ freemem: os.freemem(),
39
+ totalmem: os.totalmem(),
40
+ memoryUsage: process.memoryUsage(),
41
+ };
42
+
43
+ let cpus = os.cpus();
44
+ let availableParallelism = os.availableParallelism();
45
+
46
+ let username = os.userInfo().username
47
+
48
+ let product_name;
49
+ try {
50
+ product_name = fs.readFileSync('/sys/class/dmi/id/product_name', 'utf8');
51
+ } catch(e) {
52
+ console.error(`Cannot read /sys/class/dmi/id/product_name`, e);
53
+ }
54
+
55
+ let env = process.env;
56
+
57
+ let heapinfo = v8.getHeapStatistics();
58
+
59
+ let pid = process.pid;
60
+
61
+ res.send({cgroup, memory, heapinfo, cpus, username, product_name, env, availableParallelism, pid});
62
+ });
63
+
64
+ const port = process.env.PORT || 8080;
65
+ app.listen(port, () => {
66
+ console.log('Hello world listening on port', port);
67
+ });
package.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "container-info",
3
+ "version": "1.0.0",
4
+ "description": "Return some memory, CPU and cgroup info about the current container",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js"
8
+ },
9
+ "author": "",
10
+ "license": "Apache-2.0",
11
+ "dependencies": {
12
+ "express": "^4.16.4"
13
+ }
14
+ }