mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 00:36:46 +00:00
Add nodeinfo-http - a faster nodeinfo
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
parent
e2494e2228
commit
8d0996ad39
2
sample-functions/nodeinfo-http/.gitignore
vendored
Normal file
2
sample-functions/nodeinfo-http/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
template
|
||||||
|
build
|
32
sample-functions/nodeinfo-http/handler.js
Normal file
32
sample-functions/nodeinfo-http/handler.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
'use strict'
|
||||||
|
let os = require('os');
|
||||||
|
let fs = require('fs');
|
||||||
|
const fsPromises = fs.promises
|
||||||
|
let util = require('util');
|
||||||
|
|
||||||
|
module.exports = async (event, context) => {
|
||||||
|
let content = event.body;
|
||||||
|
|
||||||
|
let res = await info(content)
|
||||||
|
return context
|
||||||
|
.status(200)
|
||||||
|
.succeed(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function info(content, callback) {
|
||||||
|
let data = await fsPromises.readFile("/etc/hostname", "utf8")
|
||||||
|
|
||||||
|
let val = "";
|
||||||
|
val += "Hostname: " + data +"\n";
|
||||||
|
val += "Platform: " + os.platform()+"\n";
|
||||||
|
val += "Arch: " + os.arch() + "\n";
|
||||||
|
val += "CPU count: " + os.cpus().length+ "\n";
|
||||||
|
|
||||||
|
val += "Uptime: " + os.uptime()+ "\n";
|
||||||
|
|
||||||
|
if (content && content.length && content.indexOf("verbose") > -1) {
|
||||||
|
val += util.inspect(os.cpus()) + "\n";
|
||||||
|
val += util.inspect(os.networkInterfaces())+ "\n"
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
};
|
12
sample-functions/nodeinfo-http/package.json
Normal file
12
sample-functions/nodeinfo-http/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "openfaas-function",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "OpenFaaS Function",
|
||||||
|
"main": "handler.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 0"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "OpenFaaS Ltd",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
@ -90,3 +90,11 @@ functions:
|
|||||||
lang: go
|
lang: go
|
||||||
handler: ./business-strategy-generator
|
handler: ./business-strategy-generator
|
||||||
image: functions/business-strategy-generator:0.13.0
|
image: functions/business-strategy-generator:0.13.0
|
||||||
|
nodeinfo-http:
|
||||||
|
lang: node12
|
||||||
|
handler: ./nodeinfo-http
|
||||||
|
image: functions/nodeinfo-http:latest
|
||||||
|
environment:
|
||||||
|
RAW_BODY: true
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user