Add nodeinfo-http - a faster nodeinfo

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2020-03-01 11:12:54 +00:00
parent e2494e2228
commit 8d0996ad39
4 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,2 @@
template
build

View 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
};

View 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"
}

View File

@ -90,3 +90,11 @@ functions:
lang: go
handler: ./business-strategy-generator
image: functions/business-strategy-generator:0.13.0
nodeinfo-http:
lang: node12
handler: ./nodeinfo-http
image: functions/nodeinfo-http:latest
environment:
RAW_BODY: true