]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: dump general info
authorThierry Fournier <tfournier@arpalert.org>
Fri, 18 Mar 2016 07:47:13 +0000 (08:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2016 15:27:40 +0000 (17:27 +0200)
This patch adds function able to dump general haproxy information.

doc/lua-api/index.rst
src/hlua_fcn.c

index cbbab5f7ed6ba52610d5ffa3286257f25705e056..fa16519b62d3e8070fcd08a7c7a8bf36634bd623 100644 (file)
@@ -270,6 +270,19 @@ Core class
   :param string filename: the filename that reference the map entries.
   :param string key: the key which will be deleted.
 
+.. js:function:: core.get_info()
+
+  **context**: body, init, task, action, sample-fetch, converter
+
+  Returns HAProxy core informations. We can found information like the uptime,
+  the pid, memory pool usage, tasks number, ...
+
+  These information are also returned by the management sockat via the command
+  "show info". See the management socket documentation fpor more information
+  about the content of these variables.
+
+  :returns: an array of values.
+
 .. js:function:: core.now()
 
   **context**: body, init, task, action
index 69d6ee652d7693ff91ac72730beb4834025bbf12..f577be4a32d9a6adf543584d93f9e4514e062adb 100644 (file)
 /* Contains the class reference of the concat object. */
 static int class_concat_ref;
 
+#define STATS_LEN (INF_TOTAL_FIELDS)
+
+static struct field stats[STATS_LEN];
+
 /* This function gets a struct field and convert it in Lua
  * variable. The variable is pushed at the top of the stak.
  */
@@ -293,6 +297,21 @@ static int hlua_asctime_date(lua_State *L)
        return hlua_parse_date(L, parse_asctime_date);
 }
 
+static int hlua_get_info(lua_State *L)
+{
+       int i;
+
+       stats_fill_info(stats, STATS_LEN);
+
+       lua_newtable(L);
+       for (i=0; i<INF_TOTAL_FIELDS; i++) {
+               lua_pushstring(L, info_field_names[i]);
+               hlua_fcn_pushfield(L, &stats[i]);
+               lua_settable(L, -3);
+       }
+       return 1;
+}
+
 static struct hlua_concat *hlua_check_concat(lua_State *L, int ud)
 {
        return (struct hlua_concat *)(hlua_checkudata(L, ud, class_concat_ref));
@@ -426,6 +445,7 @@ int hlua_fcn_reg_core_fcn(lua_State *L)
        hlua_class_function(L, "rfc850_date", hlua_rfc850_date);
        hlua_class_function(L, "asctime_date", hlua_asctime_date);
        hlua_class_function(L, "concat", hlua_concat_new);
+       hlua_class_function(L, "get_info", hlua_get_info);
 
        return 5;
 }