[Sysfence-commit] sysfence conditions.c,1.4,1.4.2.1 conditions.h,1.8,1.8.2.1 exit.c,1.4,1.4.2.1 exit
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-05-17 15:32:52
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18568 Modified Files: Tag: get_stat_value_function conditions.c conditions.h exit.c exit.h getstats.c getstats.h log.c Log Message: + introducing get_stat_value function. this won't work yet - stat value logging is now disabled; needs to be rewritten Index: conditions.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.h,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -u -d -r1.8 -r1.8.2.1 --- conditions.h 27 Feb 2004 11:16:07 -0000 1.8 +++ conditions.h 17 May 2004 15:32:35 -0000 1.8.2.1 @@ -29,9 +29,10 @@ } expression; typedef struct { - vartype type; - int val_id; - void *thresh; + stattype label; + statarg arg1; + statarg arg2; + statval thresh; token op; } atomic; @@ -54,10 +55,6 @@ // indicate if expression was true after this check and previous one int hit, prevhit; - - // bool vector that shows which stats are used within this rule. - // used by logging functions to report only important values - int showstat[STA_LAST]; } ruleset; /* Index: log.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/log.c,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -d -r1.6 -r1.6.2.1 --- log.c 1 Mar 2004 17:28:10 -0000 1.6 +++ log.c 17 May 2004 15:32:35 -0000 1.6.2.1 @@ -24,6 +24,7 @@ #include "conditions.h" #include "log.h" +#if 0 char * stats2str (int *sta) { char *res = xalloc (NULL, LOGLINEBUF); @@ -67,6 +68,7 @@ return res; } +#endif void log_start (int rules) { @@ -79,50 +81,7 @@ void log_rulehit (ruleset *rule) { - char *stattxt = stats2str (&(rule->showstat[0])); - - if (rule->name != NULL) - syslog (LOG_WARNING, - "%s: %s", - rule->name, - stattxt - ); - else - syslog (LOG_WARNING, - "rule hit: %s", - stattxt - ); - - free (stattxt); - - /* - if (rule->name != NULL) { - syslog (LOG_WARNING, - "%s: %s=%0.2f %s=%0.2f %s=%0.2f, " - "%s=%d %s=%d, %s=%d %s=%d", - rule->name, - stat[STA_LA1].label, stat[STA_LA1].val.dbl, - stat[STA_LA5].label, stat[STA_LA5].val.dbl, - stat[STA_LA15].label, stat[STA_LA15].val.dbl, - stat[STA_MFREE].label, stat[STA_MFREE].val.siz, - stat[STA_MUSED].label, stat[STA_MUSED].val.siz, - stat[STA_SFREE].label, stat[STA_SFREE].val.siz, - stat[STA_SUSED].label, stat[STA_SUSED].val.siz - ); - } else { - syslog (LOG_WARNING, - "rule hit: %s=%0.2f %s=%0.2f %s=%0.2f, " - "%s=%d %s=%d, %s=%d %s=%d", - stat[STA_LA1].label, stat[STA_LA1].val.dbl, - stat[STA_LA5].label, stat[STA_LA5].val.dbl, - stat[STA_LA15].label, stat[STA_LA15].val.dbl, - stat[STA_MFREE].label, stat[STA_MFREE].val.siz, - stat[STA_MUSED].label, stat[STA_MUSED].val.siz, - stat[STA_SFREE].label, stat[STA_SFREE].val.siz, - stat[STA_SUSED].label, stat[STA_SUSED].val.siz - ); - } - */ + syslog (LOG_WARNING, "rule %s hit", rule->name); } void log_end () Index: exit.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/exit.h,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -d -r1.4 -r1.4.2.1 --- exit.h 1 Mar 2004 17:32:39 -0000 1.4 +++ exit.h 17 May 2004 15:32:35 -0000 1.4.2.1 @@ -26,6 +26,8 @@ #define EXIT_VALUE 22 #define EXIT_OPTION 23 +#define EXIT_BUG 101 + void bail_out (int excode, const char *details); /* $Id$ */ Index: getstats.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.h,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -d -r1.5 -r1.5.2.1 --- getstats.h 17 Apr 2004 16:54:35 -0000 1.5 +++ getstats.h 17 May 2004 15:32:35 -0000 1.5.2.1 @@ -16,14 +16,28 @@ #define BUFSIZE 512 -#define STA_LA1 0 -#define STA_LA5 1 -#define STA_LA15 2 -#define STA_MFREE 3 -#define STA_MUSED 4 -#define STA_SFREE 5 -#define STA_SUSED 6 -#define STA_LAST 7 +typedef enum { + STA_LOAD, + STA_MEMORY, + STA_SWAP, + STA_FILESYS, + STA_PROC +} stattype; + +typedef enum { + ARG_MIN1, + ARG_MIN5, + ARG_MIN15, + ARG_TOTAL, + ARG_USED, + ARG_FREE, + ARG_AVAIL +} arg_simple; + +typedef union { + arg_simple simple; + void *ptr; +} statarg; typedef enum { DOUBLE, @@ -31,23 +45,19 @@ } vartype; typedef struct { - char *label; - vartype type; - + vartype type; union { - double dbl; - long int siz; + long int intval; + double dblval; } val; - } statval; typedef struct { char *path; long int total, used, free; - } pathspaceval; -statval stat [STA_LAST]; +statval *get_stat_value (stattype label, statarg arg1, statarg arg2); void fetch_la (); void fetch_mem (); Index: conditions.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -d -r1.4 -r1.4.2.1 --- conditions.c 26 Feb 2004 20:11:09 -0000 1.4 +++ conditions.c 17 May 2004 15:32:35 -0000 1.4.2.1 @@ -14,6 +14,7 @@ */ #include <stdio.h> +#include "exit.h" #include "parseopt/lex.h" #include "getstats.h" #include "conditions.h" @@ -52,24 +53,24 @@ int check_atomic (atomic *at) { - double dv = stat[at->val_id].val.dbl, - *dt = (double *) at->thresh; - long int iv = stat[at->val_id].val.siz, - *it = (long int *) at->thresh; + statval *stval = get_stat_value (at->label, at->arg1, at->arg2); + + if (at->thresh.type != stval->type) + bail_out (EXIT_BUG, "incompatible stat value and threshold types"); - switch (at->type) { + switch (stval->type) { case DOUBLE: return ordcmp ( - (dv < *dt), - (dv == *dt), - (dv > *dt), + (stval->val.dblval < at->thresh.val.dblval), + (stval->val.dblval == at->thresh.val.dblval), + (stval->val.dblval > at->thresh.val.dblval), at->op ); case SIZE: return ordcmp ( - (iv < *it), - (iv == *it), - (iv > *it), + (stval->val.intval < at->thresh.val.intval), + (stval->val.intval == at->thresh.val.intval), + (stval->val.intval > at->thresh.val.intval), at->op ); default: Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -u -d -r1.8 -r1.8.2.1 --- getstats.c 18 Apr 2004 17:25:36 -0000 1.8 +++ getstats.c 17 May 2004 15:32:35 -0000 1.8.2.1 @@ -14,24 +14,26 @@ /* $Id$ */ -#include "exit.h" -#include "getstats.h" #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <strings.h> #include <sys/vfs.h> +#include "xalloc.h" +#include "exit.h" +#include "getstats.h" -statval stat [STA_LAST] = { - [STA_LA1] = { "la1", DOUBLE, {0} }, - [STA_LA5] = { "la5", DOUBLE, {0} }, - [STA_LA15] = { "la15", DOUBLE, {0} }, - [STA_MFREE] = { "memfree", SIZE, {0} }, - [STA_MUSED] = { "memused", SIZE, {0} }, - [STA_SFREE] = { "swapfree", SIZE, {0} }, - [STA_SUSED] = { "swapused", SIZE, {0} } -}; +statval *get_stat_value (stattype label, statarg arg1, statarg arg2) +{ + /* This function brings stat value from shared memory */ + + statval *s = (statval *) xalloc (NULL, sizeof (statval)); + + s->type = SIZE; + s->val.intval = 1; + return s; +} const char *lafile = "/proc/loadavg"; int lafha; @@ -43,6 +45,7 @@ void fetch_la () { +#if 0 char *one, *two, *three; lseek (lafha, 0, SEEK_SET); @@ -60,10 +63,13 @@ printf ("fetch_la(): la1=%0.2f la5=%0.2f la15=%0.2f\n", stat[STA_LA1], stat[STA_LA5], stat[STA_LA15]); #endif + +#endif } void fetch_mem () { +#if 0 char *ptr; long int vmtot, vmused, vmbuf, vmcache; @@ -115,6 +121,8 @@ stat[STA_SUSED].val.siz ); #endif + +#endif } void open_files () Index: exit.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/exit.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -d -r1.4 -r1.4.2.1 --- exit.c 1 Mar 2004 17:28:10 -0000 1.4 +++ exit.c 17 May 2004 15:32:35 -0000 1.4.2.1 @@ -28,7 +28,9 @@ [EXIT_PARSE] = "Parse error: %s", [EXIT_VALUE] = "Invalid value: %s", - [EXIT_OPTION] = "Invalid option: %s" + [EXIT_OPTION] = "Invalid option: %s", + + [EXIT_BUG] = "Internal bug: %s" }; extern char *usage; |