Sha256: fc204b6b0fd050b5a8922088bcc4b7f3161463fa3a35b890ee1f93ccd659a1d1

Contents?: true

Size: 779 Bytes

Versions: 3

Compression:

Stored size: 779 Bytes

Contents

#include <stdio.h>
#include <stdlib.h>

#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"


/*https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-proc-loadavg.html
Gives load average in regard to both the CPU and IO over time, as well as additional
data used by uptime and other commands. 
*/

/* Immunio Lua bindings */

static int
lua_loadavg(lua_State *L) {
  char c[100];
  FILE *fp;
  if ((fp=fopen("/proc/loadavg","r"))==NULL) {
    printf("Error! opening file");
  }
  if (fgets(c, 100, fp) != NULL) {
    lua_pushstring(L, c);
  }
  fclose(fp);
  return 1;
}

static const luaL_Reg libloadavg[] = {
  {"loadavg", lua_loadavg},
  {NULL, NULL}
};

int
luaopen_loadavg(lua_State *L) {
  luaL_checkversion(L);
  luaL_register(L, "perf", libloadavg);
  return 1;
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
immunio-1.0.17 lua-hooks/ext/perf/lualoadavg.c
immunio-1.0.15 lua-hooks/ext/perf/lualoadavg.c
immunio-1.0.14 lua-hooks/ext/perf/lualoadavg.c