This patch adds new module httpserver-monitoring-api that provides
read-only subset of the API intended for monitoring purposes only.
The monitoring flavor of httpserver provides following routes:

- /api
- /env
- /file
- /fs
- /hardware
- /network
- /os

where each of the routes expose GET-only paths.
The monitoring module disables YAML file based configuration
as well as SSL connectivity.

It is also possible to add trace plugin - libhttpserver-api_trace.so.

Please note that monitoring module re-uses the same httpserver-api
source code however when compiling we pass '-DMONITORING' flag
to disable subset of code not needed for monitoring functionality.
We also compile the code with '-fvisibility=hidden' to further reduce
size of the monitoring executable (<800K).

Fixes #820

Signed-off-by: Waldemar Kozaczuk <[email protected]>
---
 modules/httpserver-monitoring-api/.gitignore  |   4 +
 modules/httpserver-monitoring-api/Makefile    |  84 +++++
 .../api-doc/listings/api.json                 |  40 +++
 .../api-doc/listings/env.json                 |  57 ++++
 .../api-doc/listings/file.json                | 187 ++++++++++++
 .../api-doc/listings/fs.json                  |  98 ++++++
 .../api-doc/listings/hardware.json            |  73 +++++
 .../api-doc/listings/network.json             | 266 ++++++++++++++++
 .../api-doc/listings/os.json                  | 289 ++++++++++++++++++
 modules/httpserver-monitoring-api/module.py   |  24 ++
 .../mpm/package.yaml                          |   1 +
 11 files changed, 1123 insertions(+)
 create mode 100644 modules/httpserver-monitoring-api/.gitignore
 create mode 100644 modules/httpserver-monitoring-api/Makefile
 create mode 100644 modules/httpserver-monitoring-api/api-doc/listings/api.json
 create mode 100644 modules/httpserver-monitoring-api/api-doc/listings/env.json
 create mode 100644 modules/httpserver-monitoring-api/api-doc/listings/file.json
 create mode 100644 modules/httpserver-monitoring-api/api-doc/listings/fs.json
 create mode 100644 
modules/httpserver-monitoring-api/api-doc/listings/hardware.json
 create mode 100644 
modules/httpserver-monitoring-api/api-doc/listings/network.json
 create mode 100644 modules/httpserver-monitoring-api/api-doc/listings/os.json
 create mode 100644 modules/httpserver-monitoring-api/module.py
 create mode 100644 modules/httpserver-monitoring-api/mpm/package.yaml

diff --git a/modules/httpserver-monitoring-api/.gitignore 
b/modules/httpserver-monitoring-api/.gitignore
new file mode 100644
index 00000000..8d8365ad
--- /dev/null
+++ b/modules/httpserver-monitoring-api/.gitignore
@@ -0,0 +1,4 @@
+*.so
+autogen/*
+obj/*
+*.manifest
diff --git a/modules/httpserver-monitoring-api/Makefile 
b/modules/httpserver-monitoring-api/Makefile
new file mode 100644
index 00000000..b9abc628
--- /dev/null
+++ b/modules/httpserver-monitoring-api/Makefile
@@ -0,0 +1,84 @@
+SRC = $(shell readlink -f ../..)
+include $(SRC)/modules/java-base/common.gmk
+INCLUDES += -I. -I../httpserver-api -I $(SRC)/libc/internal
+
+# compiler flags:
+#  -g    adds debugging information to the executable file
+#  -Wall turns on most, but not all, compiler warnings
+autodepend = -MD -MT $@ -MP
+CXXFLAGS  = -g -Wall -std=c++11 -fPIC $(INCLUDES) -O2 $(autodepend) 
-DMONITORING -fvisibility=hidden
+#TODO: Figure out why lto breaks exception handling
+#CXXFLAGS  = -g -Wall -std=c++11 -fPIC $(INCLUDES) -O2 $(autodepend) 
-DMONITORING -fvisibility=hidden -flto
+#LDFLAGS = -flto
+src = $(shell readlink -f ../..)
+
+ifndef ARCH
+       ARCH = x64
+endif
+
+ifndef mode
+       mode = release
+endif
+
+ifndef OSV_BUILD_PATH
+       OSV_BUILD_PATH = $(src)/build/$(mode).$(ARCH)
+endif
+boost-libs := -lboost_system -lboost_filesystem
+
+# the build target executable:
+TARGET = httpserver-api
+JSON_FILES := $(wildcard api-doc/listings/*.json)
+JSON_CC_FILES := $(subst .json,.json.cc,$(subst 
api-doc/listings/,autogen/,$(JSON_FILES)))
+CPP_FILES := $(addprefix json/,$(notdir $(wildcard 
../httpserver-api/json/*.cc))) \
+       api/fs.cc api/os.cc api/network.cc api/hardware.cc api/env.cc 
api/file.cc api/api.cc \
+       common.cc main.cc plain_server.cc server.cc connection.cc matcher.cc \
+       reply.cc connection_manager.cc mime_types.cc request_handler.cc \
+       transformers.cc global_server.cc request_parser.cc handlers.cc \
+       path_holder.cc routes.cc $(JSON_CC_FILES)
+OBJ_FILES := $(addprefix obj/,$(CPP_FILES:.cc=.o))
+
+DYN_LIBS = -lpthread -ldl -L../libtools -ltools $(boost-libs)
+
+LIBS = $(DYN_LIBS) $(STATIC_LIBS)
+
+quiet = $(if $V, $1, @echo " $2"; $1)
+very-quiet = $(if $V, $1, @$1)
+
+DEPS := $(OBJ_FILES:.o=.d)
+
+module: all
+
+all: lib$(TARGET).so
+       $(call very-quiet, $(SRC)/scripts/manifest_from_host.sh lib$(TARGET).so 
> usr.manifest)
+
+lib$(TARGET).so: $(OBJ_FILES)
+       $(call quiet, $(CXX) $(CXXFLAGS) -shared $(STATIC_LIBS) -o $@ $^ 
$(DYN_LIBS), LINK $@)
+
+ifneq ($(MAKECMDGOALS),clean)
+-include $(DEPS)
+endif
+
+autogen/%.cc: api-doc/listings/% ../httpserver-api/json2code.py
+       $(call very-quiet, mkdir -p autogen)
+       $(call quiet,../httpserver-api/json2code.py -outdir autogen -f $< -ns 
json, GEN $@)
+
+$(OBJ_FILES): obj/%.o: ../httpserver-api/%.cc
+       $(call very-quiet, mkdir -p obj/stub obj/json obj/api obj/autogen)
+       $(call quiet, $(CXX) $(CXXFLAGS) -c -MMD  -o $@ $<, CXX $@)
+
+clean:
+       $(call quiet, $(RM) -f $(TARGET), CLEAN)
+       $(call very-quiet, $(RM) -f lib*.so)
+       $(call very-quiet, $(RM) -rf obj)
+       $(call very-quiet, $(RM) -rf autogen)
+       $(call very-quiet, $(RM) -f *usr*.manifest)
+
+check:
+       # Test plain readonly HTTP
+       cd $(src) && \
+       make image=httpserver-monitoring-api.fg && \
+       PYTHONPATH=$(src)/scripts 
modules/httpserver-api/tests/testhttpserver-monitoring-api.py
+
+.PHONY: check
+
+.SECONDARY:
diff --git a/modules/httpserver-monitoring-api/api-doc/listings/api.json 
b/modules/httpserver-monitoring-api/api-doc/listings/api.json
new file mode 100644
index 00000000..ec18bd9f
--- /dev/null
+++ b/modules/httpserver-monitoring-api/api-doc/listings/api.json
@@ -0,0 +1,40 @@
+{
+   "apiVersion":"0.0.1",
+   "swaggerVersion":"1.2",
+   "basePath":"{{Protocol}}://{{Host}}",
+   "resourcePath":"/api",
+   "produces":[
+      "application/json"
+   ],
+   "apis":[
+      {
+         "path":"/api/batch",
+         "operations":[
+            {
+               "method":"POST",
+               "summary":"Batch process API calls",
+               "notes":"Perform batch API calls in a single command. Commands 
are performed sequentially and independently. Each command has its own response 
code",
+               "type":"string",
+               "errorResponses":[
+                  {
+                     "code":400,
+                     "reason":"Bad request"
+                  }
+               ],
+               "nickname":"api_batch",
+               "produces":[
+                  "application/json"
+               ],
+               "parameters":[
+                  {
+                  "name":"batch",
+                  "paramType":"form",
+                  "type":"string",
+                  "required":true
+                  }
+               ]
+            }
+         ]
+      }
+   ]
+}
diff --git a/modules/httpserver-monitoring-api/api-doc/listings/env.json 
b/modules/httpserver-monitoring-api/api-doc/listings/env.json
new file mode 100644
index 00000000..29ce4384
--- /dev/null
+++ b/modules/httpserver-monitoring-api/api-doc/listings/env.json
@@ -0,0 +1,57 @@
+{
+   "apiVersion":"0.0.1",
+   "swaggerVersion":"1.2",
+   "basePath":"{{Protocol}}://{{Host}}",
+   "resourcePath":"/env",
+   "produces":[
+      "application/json"
+   ],
+   "apis":[
+      {
+         "path":"/env/{var}",
+         "operations":[
+            {
+               "method":"GET",
+               "summary":"Get an environment variable",
+               "notes":"return the environment variable value",
+               "type":"string",
+               "errorResponses":[
+                  {
+                     "code":400,
+                     "reason":"Variable not found"
+                  }
+               ],
+               "nickname":"getEnv",
+               "produces":[
+                  "application/json"
+               ],
+               "parameters":[
+                  {
+                     "name":"var",
+                     "description":"name of the environment variable",
+                     "required":true,
+                     "allowMultiple":true,
+                     "type":"string",
+                     "paramType":"path"
+                  }
+               ]
+            }
+         ]
+      },
+            {
+         "path":"/env/",
+         "operations":[
+            {
+               "method":"GET",
+               "summary":"Returns a list of all environment variables in the 
system.",
+               "type":"array",
+               "items": {"type": "string"},
+               "nickname":"list_env",
+               "produces":[
+                  "application/json"
+               ]
+               }
+               ]
+            }
+         ]
+}
diff --git a/modules/httpserver-monitoring-api/api-doc/listings/file.json 
b/modules/httpserver-monitoring-api/api-doc/listings/file.json
new file mode 100644
index 00000000..7ab8a0d0
--- /dev/null
+++ b/modules/httpserver-monitoring-api/api-doc/listings/file.json
@@ -0,0 +1,187 @@
+{
+   "apiVersion":"0.0.1",
+   "swaggerVersion":"1.2",
+   "basePath":"{{Protocol}}://{{Host}}",
+   "resourcePath":"/file",
+   "produces":[
+      "application/json"
+   ],
+   "apis":[
+      {
+         "path":"/file/{path-par}",
+         "operations":[
+            {
+               "method":"GET",
+               "summary":"Get File/Directory information",
+               "notes":"return File or Directory related information",
+               "type":"string",
+               "errorResponses":[
+                  {
+                     "code":404,
+                     "reason":"File not found"
+                  },
+                  {
+                     "code":400,
+                     "reason":"Bad Request"
+                  }
+               ],
+               "nickname":"getFile",
+               "produces":[
+                  "application/json"
+               ],
+               "parameters":[
+                  {
+                     "name":"path-par",
+                     "description":"Full path of file or directory",
+                     "required":true,
+                     "allowMultiple":true,
+                     "type":"string",
+                     "paramType":"path"
+                  },
+                  {
+                     "name":"op",
+                     "description":"The operation to perform",
+                     "required":true,
+                     "allowMultiple":false,
+                     "type":"string",
+                     "paramType":"query",
+                     "enum":["GET", "LISTSTATUS", "GETFILESTATUS"]
+                  },
+                  {
+                     "name":"offset",
+                     "description":"Offset in a file",
+                     "required":false,
+                     "allowMultiple":false,
+                     "type":"long",
+                     "paramType":"query"
+                  },
+                  {
+                     "name":"length",
+                     "description":"The number of bytes to be processed.",
+                     "required":false,
+                     "allowMultiple":false,
+                     "type":"long",
+                     "paramType":"query"
+                  }
+               ]
+            }
+         ]
+      }
+   ],
+   "models":{
+      "ContentSummary":{
+         "id": "ContentSummary",
+         "properties":{
+            "directoryCount":{
+               "description":"The number of directories.",
+               "type":"int",
+               "required":true
+            },
+            "fileCount":{
+               "description":"The number of files.",
+               "type":"int",
+               "required":true
+            },
+            "length":{
+               "description":"The number of bytes used by the content.",
+               "type":"int",
+               "required":true
+            },
+            "quota":{
+               "description":"The namespace quota of this directory.",
+               "type":"int",
+               "required":true
+            },
+            "spaceConsumed":{
+               "description":"The disk space consumed by the content.",
+               "type":"int",
+               "required":true
+            },
+            "spaceQuota":{
+               "description":"The disk space quota.",
+               "type":"int",
+               "required":true
+            }
+         }
+      },
+      "FileChecksum":{
+         "id": "FileChecksum",
+         "properties":{
+            "algorithm":{
+               "description":"The name of the checksum algorithm.",
+               "type":"string",
+               "required":true
+            },
+            "bytes":{
+               "description":"The byte sequence of the checksum in 
hexadecimal.",
+               "type":"string",
+               "required":true
+            },
+            "length":{
+               "description":"The length of the bytes (not the length of the 
string).",
+               "type":"int",
+               "required":true
+            }
+         }
+      },
+      "FileStatusProperties":{
+         "id": "FileStatusProperties",
+         "properties":{
+            "accessTime":{
+               "description":"The access time.",
+               "type":"int",
+               "required":true
+            },
+            "blockSize":{
+               "description":"The block size of a file.",
+               "type":"int",
+               "required":true
+            },
+            "group":{
+               "description":"The group owner.",
+               "type":"string",
+               "required":true
+            },
+            "length":{
+               "description":"The number of bytes in a file.",
+               "type":"long",
+               "required":true
+            },
+            "modificationTime":{
+               "description":"The modification time.",
+               "type":"int",
+               "required":true
+            },
+            "owner":{
+               "description":"The user who is the owner.",
+               "type":"string",
+               "required":true
+            },
+            "pathSuffix":{
+               "description":"The path suffix.",
+               "type":"string",
+               "required":true
+            },
+            "permission":{
+               "description":"The permission represented as a octal string.",
+               "type":"string",
+               "required":true
+            },
+            "replication":{
+               "description":"The number of replication of a file.",
+               "type":"int",
+               "required":true
+            },
+            "symlink":{
+               "description":"The link target of a symlink.",
+               "type":"string"
+            },
+            "type":{
+               "description":"The type of the path object.",
+               "type":"string",
+               "required":true
+            }
+         }
+      }
+   }
+}
diff --git a/modules/httpserver-monitoring-api/api-doc/listings/fs.json 
b/modules/httpserver-monitoring-api/api-doc/listings/fs.json
new file mode 100644
index 00000000..7fd2062b
--- /dev/null
+++ b/modules/httpserver-monitoring-api/api-doc/listings/fs.json
@@ -0,0 +1,98 @@
+{
+    "apiVersion": "0.0.1",
+    "swaggerVersion": "1.2",
+    "basePath": "{{Protocol}}://{{Host}}",
+    "resourcePath": "/fs",
+    "produces": [
+        "application/json"
+    ],
+    "apis": [
+        {
+            "path": "/fs/df/{mount}",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "report a file system usage",
+                    "type": "array",
+                                   "items": {
+                                       "type": "DFStat"
+                                   },
+                    "errorResponses":[
+                     {
+                         "code":404,
+                         "reason":"File system not found"
+                     }
+                    ],
+                    "nickname" : "getDFStats",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                     {
+                        "name":"mount",
+                        "description":"mount point",
+                        "required":false,
+                        "allowMultiple":true,
+                        "type":"string",
+                        "paramType":"path"
+                    }
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/fs/df/",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Return all file systems",
+                    "type": "array",
+                                   "items": {
+                                       "$ref": "DFStat"
+                                   },
+                    "nickname" : "list_df_stats",
+                    "produces": [
+                        "application/json"
+                    ]
+                }
+            ]
+        }
+    ],
+    "models" : {
+        "DFStat": {
+           "description": "Information on one file system",
+           "id": "DFStat",
+           "properties": {
+                "filesystem" : {
+                     "type": "string",
+                    "description": "fs name"
+                },
+                "mount" : {
+                     "type": "string",
+                    "description": "mount point"
+                },
+                "btotal" : {
+                    "type": "long",
+                    "description": "total data blocks in file system"
+                },
+                "bfree" : {
+                    "type": "long",
+                    "description": "free blocks in file system"
+                },
+                "ftotal" : {
+                    "type": "long",
+                    "description": "total file nodes in file system"
+                },
+                "ffree" : {
+                    "type": "long",
+                    "description": "free file nodes in file system"
+                },
+                "blocksize" : {
+                    "type": "long",
+                    "description": "block size in bytes"
+                }
+            }
+        }
+    }
+}
diff --git a/modules/httpserver-monitoring-api/api-doc/listings/hardware.json 
b/modules/httpserver-monitoring-api/api-doc/listings/hardware.json
new file mode 100644
index 00000000..eaf26279
--- /dev/null
+++ b/modules/httpserver-monitoring-api/api-doc/listings/hardware.json
@@ -0,0 +1,73 @@
+{
+    "apiVersion": "0.0.1",
+    "swaggerVersion": "1.2",
+    "basePath": "{{Protocol}}://{{Host}}",
+    "resourcePath": "/hardware",
+    "produces": [
+        "application/json"
+    ],
+    "apis": [
+        {
+            "path": "/hardware/processor/flags",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "list all present processor features",
+                    "type": "string",
+                    "nickname" : "processorFeatures",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/hardware/firmware/vendor",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Return the firmware vendor",
+                    "type": "string",
+                    "nickname" : "firmware_vendor",
+                    "produces": [
+                        "application/json"
+                    ]
+                }
+            ]
+        },
+        {
+            "path": "/hardware/hypervisor",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns name of the hypervisor OSv is running 
on.",
+                    "type": "string",
+                    "nickname" : "hypervisor_name",
+                    "produces": [
+                        "application/json"
+                    ]
+                }
+            ]
+        },
+        {
+            "path": "/hardware/processor/count",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "list the current number of processors",
+                    "type": "long",
+                    "nickname" : "processorCount",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        }
+    ]
+}
diff --git a/modules/httpserver-monitoring-api/api-doc/listings/network.json 
b/modules/httpserver-monitoring-api/api-doc/listings/network.json
new file mode 100644
index 00000000..0d082f3e
--- /dev/null
+++ b/modules/httpserver-monitoring-api/api-doc/listings/network.json
@@ -0,0 +1,266 @@
+{
+   "apiVersion":"0.0.1",
+   "swaggerVersion":"1.2",
+   "basePath":"{{Protocol}}://{{Host}}",
+   "resourcePath":"/network",
+   "produces":[
+      "application/json"
+   ],
+   "apis":[
+   {
+         "path":"/network/ifconfig/",
+         "operations":[
+            {
+               "method":"GET",
+               "summary":"Get all interfaces",
+               "notes":"Get a list of all the interfaces configuration and 
data",
+               "type":"array",
+               "items": {"type": "Interface"},
+               "nickname":"listIfconfig",
+               "produces":[
+                  "application/json"
+               ],
+               "parameters":[
+               ]
+            }
+      ]
+      },
+      {
+         "path":"/network/ifconfig/{intf}",
+         "operations":[
+            {
+               "method":"GET",
+               "summary":"Get an interface",
+               "notes":"Get an interface configuration and data",
+               "type":"Interface",
+               "errorResponses":[
+                  {
+                     "code":404,
+                     "reason":"Interface not found"
+                  }
+               ],
+               "nickname":"getIfconfig",
+               "produces":[
+                  "application/json"
+               ],
+               "parameters":[
+                  {
+                     "name":"intf",
+                     "description":"name of the interface",
+                     "required":true,
+                     "allowMultiple":false,
+                     "type":"string",
+                     "paramType":"path"
+                  }
+               ]
+            }
+         ]
+      },
+      {
+         "path":"/network/route/",
+         "operations":[
+            {
+               "method":"GET",
+               "summary":"Get the ip route table",
+               "notes":"Get a list of the available routes",
+               "type":"Routes",
+               "items": {"type": "Route"},
+               "nickname":"getRoute",
+               "produces":[
+                  "application/json"
+               ],
+               "parameters":[
+
+               ]
+            }
+         ]
+      }
+   ],
+   "models":{
+      "Interface_config":{
+         "id": "Interface_config",
+         "properties":{
+            "name":{
+               "type":"string"
+            },
+            "addr":{
+               "type":"string"
+            },
+            "mask":{
+               "type":"string"
+            },
+            "broadcast":{
+               "type":"string"
+            },
+            "flags":{
+               "type":"string"
+            },
+            "mtu":{
+               "type":"string"
+            },
+            "phys_addr":{
+               "type":"string"
+            }
+         }
+      },
+      "Wakeup_stats":{
+         "id": "Wakeup_stats",
+         "properties":{
+            "packets_8":{
+               "type":"long"
+            },
+            "packets_16":{
+               "type":"long"
+            },
+            "packets_32":{
+               "type":"long"
+            },
+            "packets_64":{
+                "type":"long"
+            },
+            "packets_128":{
+                "type":"long"
+            },
+            "packets_256":{
+                "type":"long"
+            }
+        }
+      },
+      "Interface_data":{
+         "id": "Interface_data",
+         "properties":{
+            "ifi_type":{
+               "type":"char"
+            },
+            "ifi_physical":{
+               "type":"char"
+            },
+            "ifi_addrlen":{
+               "type":"char"
+            },
+            "ifi_hdrlen":{
+               "type":"char"
+            },
+            "ifi_link_state":{
+               "type":"char"
+            },
+            "ifi_spare_char1":{
+               "type":"char"
+            },
+            "ifi_spare_char2":{
+               "type":"char"
+            },
+            "ifi_datalen":{
+               "type":"char"
+            },
+            "ifi_mtu":{
+               "type":"long"
+            },
+            "ifi_metric":{
+               "type":"long"
+            },
+            "ifi_baudrate":{
+               "type":"long"
+            },
+            "ifi_ipackets":{
+               "type":"long"
+            },
+            "ifi_ierrors":{
+               "type":"long"
+            },
+            "ifi_opackets":{
+               "type":"long"
+            },
+            "ifi_oerrors":{
+               "type":"long"
+            },
+            "ifi_collisions":{
+               "type":"long"
+            },
+            "ifi_ibytes":{
+               "type":"long"
+            },
+            "ifi_obytes":{
+               "type":"long"
+            },
+            "ifi_imcasts":{
+               "type":"long"
+            },
+            "ifi_omcasts":{
+               "type":"long"
+            },
+            "ifi_iqdrops":{
+               "type":"long"
+            },
+            "ifi_noproto":{
+               "type":"long"
+            },
+            "ifi_hwassist":{
+               "type":"long"
+            },
+            "ifi_epoch":{
+               "type":"long"
+            },
+           "ifi_ibh_wakeups":{
+               "type":"long"
+            },
+           "ifi_oworker_kicks":{
+               "type":"long"
+            },
+           "ifi_oworker_wakeups":{
+               "type":"long"
+            },
+           "ifi_oworker_packets":{
+               "type":"long"
+            },
+           "ifi_okicks":{
+               "type":"long"
+            },
+           "ifi_oqueue_is_full":{
+               "type":"long"
+            },
+            "ifi_iwakeup_stats":{
+                "type": "Wakeup_stats"
+            },
+            "ifi_owakeup_stats":{
+                "type": "Wakeup_stats"
+            }
+         }
+      },
+      "Interface":{
+         "id":"Interface",
+         "properties":{
+            "config":{
+               "type":"Interface_config"
+            },
+            "data":{
+               "type":"Interface_data"
+            },
+            "time":{
+               "type":"long",
+               "description":"Time when interface information was taken 
(microseconds since uptime)"
+            }
+         }
+      },
+      "Route":{
+         "id":"Route",
+         "properties":{
+            "destination":{
+               "type":"string"
+            },
+            "gateway":{
+               "type":"string"
+            },
+            "flags":{
+               "type":"string"
+            },
+            "netif":{
+               "type":"string"
+            },
+            "ipv6":{
+               "type":"boolean"
+            }
+         }
+      }
+   }
+}
diff --git a/modules/httpserver-monitoring-api/api-doc/listings/os.json 
b/modules/httpserver-monitoring-api/api-doc/listings/os.json
new file mode 100644
index 00000000..a3ecae80
--- /dev/null
+++ b/modules/httpserver-monitoring-api/api-doc/listings/os.json
@@ -0,0 +1,289 @@
+{
+    "apiVersion": "0.0.1",
+    "swaggerVersion": "1.2",
+    "basePath": "{{Protocol}}://{{Host}}",
+    "resourcePath": "/os",
+    "produces": [
+        "application/json"
+    ],
+    "apis": [
+        {
+            "path": "/os/name",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns name of the operating system",
+                    "type": "string",
+                    "nickname": "os_name",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/version",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns version of the operating system",
+                    "type": "string",
+                    "nickname": "os_version",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/vendor",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the vendor of the operating system",
+                    "type": "string",
+                    "nickname": "os_vendor",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/uptime",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the number of seconds since the system 
was booted",
+                    "type": "long",
+                    "nickname": "os_uptime",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/date",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the current date and time",
+                    "type": "string",
+                    "nickname": "os_date",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/memory/total",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns total amount of memory usable by the 
system (in bytes)",
+                    "type": "long",
+                    "nickname": "os_memory_total",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/memory/free",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the amount of free memory in the 
system (in bytes)",
+                    "type": "long",
+                    "nickname": "os_memory_free",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/memory/balloon",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the JVM balloon size (in bytes)",
+                    "type": "long",
+                    "nickname": "os_memory_balloon",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ]
+                }
+            ]
+        },
+        {
+            "path": "/os/dmesg",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the operating system boot log",
+                    "type": "string",
+                    "nickname": "os_dmesg",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/hostname",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the system host name",
+                    "type": "string",
+                    "nickname": "os_get_hostname",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/threads",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns a list of threads in the system",
+                    "type": "Threads",
+                    "nickname": "os_threads",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        },
+        {
+            "path": "/os/cmdline",
+            "operations": [
+                {
+                    "method": "GET",
+                    "summary": "Returns the current boot command line",
+                    "notes": "This operation retrieves the current OSv command 
line. The current command line is either the command line used for the current 
boot, or the one written by POST.",
+                    "type": "string",
+                    "nickname": "os_get_cmdline",
+                    "produces": [
+                        "application/json"
+                    ],
+                    "parameters": [
+                    ],
+                    "deprecated": "false"
+                }
+            ]
+        }
+    ],
+    "models": {
+        "Thread": {
+            "id": "Thread",
+            "description": "Information on one thread",
+            "properties": {
+                "id": {
+                    "type": "long",
+                    "description": "32-bit thread id"
+                },
+                "cpu": {
+                    "type": "long",
+                    "description": "CPU the thread is running on"
+                },
+                "cpu_ms": {
+                    "type": "long",
+                    "description": "Total CPU time used by the thread (in 
milliseconds)"
+                },
+                "switches": {
+                    "type": "long",
+                    "description": "Number of times this thread was 
context-switched in"
+                },
+                "migrations": {
+                    "type": "long",
+                    "description": "Number of times this thread was migrated 
between CPUs"
+                },
+                "preemptions": {
+                    "type": "long",
+                    "description": "Number of times this thread was preempted 
(still runnable, but switched out)"
+                },
+                "priority": {
+                    "type": "float"
+                },
+                "stack_size": {
+                    "type": "long"
+                },
+                "status": {
+                    "type": "string",
+                    "description": "thread status",
+                    "enum": [
+                        "invalid",
+                        "prestarted",
+                        "unstarted",
+                        "waiting",
+                        "running",
+                        "queued",
+                        "waking",
+                        "terminating",
+                        "terminated"
+                    ]
+                },
+                "name": {
+                    "type": "string",
+                    "description": "Thread description (not necessarily 
unique)"
+                }
+            }
+        },
+        "Threads": {
+            "id": "Threads",
+            "description": "List of threads",
+            "properties": {
+                "list": {
+                    "type": "array",
+                    "items": {
+                        "type": "Thread"
+                    },
+                    "description": "List of thread objects"
+                },
+                "time_ms": {
+                    "type": "long",
+                    "description": "Time when thread list was taken 
(milliseconds since epoche)"
+                }
+            }
+        }
+    }
+}
diff --git a/modules/httpserver-monitoring-api/module.py 
b/modules/httpserver-monitoring-api/module.py
new file mode 100644
index 00000000..6ae9aae7
--- /dev/null
+++ b/modules/httpserver-monitoring-api/module.py
@@ -0,0 +1,24 @@
+import os
+from osv.modules.api import *
+from osv.modules.filemap import FileMap
+from osv.modules import api
+
+provides = ['httpserver-api']
+
+_module = '${OSV_BASE}/modules/httpserver-monitoring-api'
+
+_exe = '/libhttpserver-api.so'
+
+usr_files = FileMap()
+usr_files.link(_exe).to('/usr/lib/libhttpserver-api.so')
+usr_files.add(os.path.join(_module, 'api-doc')).to('/usr/mgmt/api')
+
+api.require('libtools')
+
+# httpserver will run regardless of an explicit command line
+# passed with "run.py -e".
+daemon = api.run_on_init(_exe + ' --access-allow=true &!')
+
+fg = api.run(_exe + ' --access-allow=true')
+
+default = daemon
diff --git a/modules/httpserver-monitoring-api/mpm/package.yaml 
b/modules/httpserver-monitoring-api/mpm/package.yaml
new file mode 100644
index 00000000..21023036
--- /dev/null
+++ b/modules/httpserver-monitoring-api/mpm/package.yaml
@@ -0,0 +1 @@
+title: OSv httpserver monitoring APIs
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20200319204501.23817-2-jwkozaczuk%40gmail.com.

Reply via email to