Browse Source

added support for lighty.status[] in mod_magnet

- moved the status_counter_* functions from mod_fastcgi.c to status_counter.[ch]


git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1298 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.12
Jan Kneschke 16 years ago
parent
commit
c7b9858b03
  1. 4
      src/Makefile.am
  2. 1
      src/SConscript
  3. 44
      src/mod_fastcgi.c
  4. 46
      src/mod_magnet.c
  5. 60
      src/status_counter.c
  6. 14
      src/status_counter.h

4
src/Makefile.am

@ -46,7 +46,7 @@ common_src=buffer.c log.c \
network_write.c network_linux_sendfile.c \
network_freebsd_sendfile.c network_writev.c \
network_solaris_sendfilev.c network_openssl.c \
splaytree.c
splaytree.c status_counter.c
src = server.c response.c connections.c network.c \
configfile.c configparser.c request.c proc_open.c
@ -246,7 +246,7 @@ hdr = server.h buffer.h network.h log.h keyvalue.h \
mod_ssi.h mod_ssi_expr.h inet_ntop_cache.h \
configparser.h mod_ssi_exprparser.h \
sys-mmap.h sys-socket.h mod_cml.h mod_cml_funcs.h \
splaytree.h proc_open.h
splaytree.h proc_open.h status_counter.h
DEFS= @DEFS@ -DLIBRARY_DIR="\"$(libdir)\""

1
src/SConscript

@ -22,6 +22,7 @@ common_src = Split("buffer.c log.c \
network_write.c network_linux_sendfile.c \
network_freebsd_sendfile.c \
network_solaris_sendfilev.c network_openssl.c \
status_counter.c \
")
src = Split("server.c response.c connections.c network.c \

44
src/mod_fastcgi.c

@ -23,6 +23,7 @@
#include "inet_ntop_cache.h"
#include "stat_cache.h"
#include "status_counter.h"
#include <fastcgi.h>
#include <stdio.h>
@ -363,49 +364,6 @@ typedef struct {
/* ok, we need a prototype */
static handler_t fcgi_handle_fdevent(void *s, void *ctx, int revents);
data_integer *status_counter_get_counter(server *srv, const char *s, size_t len) {
data_integer *di;
if (NULL == (di = (data_integer *)array_get_element(srv->status, s))) {
/* not found, create it */
if (NULL == (di = (data_integer *)array_get_unused_element(srv->status, TYPE_INTEGER))) {
di = data_integer_init();
}
buffer_copy_string_len(di->key, s, len);
di->value = 0;
array_insert_unique(srv->status, (data_unset *)di);
}
return di;
}
/* dummies of the statistic framework functions
* they will be moved to a statistics.c later */
int status_counter_inc(server *srv, const char *s, size_t len) {
data_integer *di = status_counter_get_counter(srv, s, len);
di->value++;
return 0;
}
int status_counter_dec(server *srv, const char *s, size_t len) {
data_integer *di = status_counter_get_counter(srv, s, len);
if (di->value > 0) di->value--;
return 0;
}
int status_counter_set(server *srv, const char *s, size_t len, int val) {
data_integer *di = status_counter_get_counter(srv, s, len);
di->value = val;
return 0;
}
int fastcgi_status_copy_procname(buffer *b, fcgi_extension_host *host, fcgi_proc *proc) {
buffer_copy_string(b, "fastcgi.backend.");
buffer_append_string_buffer(b, host->id);

46
src/mod_magnet.c

@ -16,6 +16,7 @@
#include "mod_magnet_cache.h"
#include "response.h"
#include "stat_cache.h"
#include "status_counter.h"
#define MAGNET_CONFIG_RAW_URL "magnet.attract-raw-url-to"
@ -214,6 +215,42 @@ static int magnet_reqhdr_get(lua_State *L) {
return 1;
}
static int magnet_status_get(lua_State *L) {
data_integer *di;
server *srv;
size_t key_len = 0;
const char *key = luaL_checklstring(L, 2, &key_len);
lua_pushstring(L, "lighty.srv");
lua_gettable(L, LUA_REGISTRYINDEX);
srv = lua_touserdata(L, -1);
lua_pop(L, 1);
di = status_counter_get_counter(srv, key, key_len);
lua_pushnumber(L, (double)di->value);
return 1;
}
static int magnet_status_set(lua_State *L) {
size_t key_len = 0;
server *srv;
const char *key = luaL_checklstring(L, 2, &key_len);
int counter = luaL_checkint(L, 3);
lua_pushstring(L, "lighty.srv");
lua_gettable(L, LUA_REGISTRYINDEX);
srv = lua_touserdata(L, -1);
lua_pop(L, 1);
status_counter_set(srv, key, key_len, counter);
return 0;
}
typedef struct {
const char *name;
enum {
@ -511,6 +548,15 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu
lua_setmetatable(L, -2); /* tie the metatable to request (sp -= 1) */
lua_setfield(L, -2, "env"); /* content = {} (sp -= 1) */
lua_newtable(L); /* {} (sp += 1) */
lua_newtable(L); /* the meta-table for the request-table (sp += 1) */
lua_pushcfunction(L, magnet_status_get); /* (sp += 1) */
lua_setfield(L, -2, "__index"); /* (sp -= 1) */
lua_pushcfunction(L, magnet_status_set); /* (sp += 1) */
lua_setfield(L, -2, "__newindex"); /* (sp -= 1) */
lua_setmetatable(L, -2); /* tie the metatable to request (sp -= 1) */
lua_setfield(L, -2, "status"); /* content = {} (sp -= 1) */
/* add empty 'content' and 'header' tables */
lua_newtable(L); /* {} (sp += 1) */
lua_setfield(L, -2, "content"); /* content = {} (sp -= 1) */

60
src/status_counter.c

@ -0,0 +1,60 @@
#include <stdlib.h>
#include "status_counter.h"
/**
* The status array can carry all the status information you want
* the key to the array is <module-prefix>.<name>
* and the values are counters
*
* example:
* fastcgi.backends = 10
* fastcgi.active-backends = 6
* fastcgi.backend.<key>.load = 24
* fastcgi.backend.<key>....
*
* fastcgi.backend.<key>.disconnects = ...
*/
data_integer *status_counter_get_counter(server *srv, const char *s, size_t len) {
data_integer *di;
if (NULL == (di = (data_integer *)array_get_element(srv->status, s))) {
/* not found, create it */
if (NULL == (di = (data_integer *)array_get_unused_element(srv->status, TYPE_INTEGER))) {
di = data_integer_init();
}
buffer_copy_string_len(di->key, s, len);
di->value = 0;
array_insert_unique(srv->status, (data_unset *)di);
}
return di;
}
/* dummies of the statistic framework functions
* they will be moved to a statistics.c later */
int status_counter_inc(server *srv, const char *s, size_t len) {
data_integer *di = status_counter_get_counter(srv, s, len);
di->value++;
return 0;
}
int status_counter_dec(server *srv, const char *s, size_t len) {
data_integer *di = status_counter_get_counter(srv, s, len);
if (di->value > 0) di->value--;
return 0;
}
int status_counter_set(server *srv, const char *s, size_t len, int val) {
data_integer *di = status_counter_get_counter(srv, s, len);
di->value = val;
return 0;
}

14
src/status_counter.h

@ -0,0 +1,14 @@
#ifndef _STATUS_COUNTER_H_
#define _STATUS_COUNTER_H_
#include <sys/types.h>
#include "array.h"
#include "base.h"
data_integer *status_counter_get_counter(server *srv, const char *s, size_t len);
int status_counter_inc(server *srv, const char *s, size_t len);
int status_counter_dec(server *srv, const char *s, size_t len);
int status_counter_set(server *srv, const char *s, size_t len, int val);
#endif
Loading…
Cancel
Save