Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

pshandler.h

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2004 Russell Leighton
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 
00020 
00021 
00022 #ifndef __AWHANDLER_PS__
00023 #define __AWHANDLER_PS__
00024 
00025 #include <dirent.h>
00026 
00027 #include "monitor.h"
00028 #include "wire.h"
00029 
00030 #include "regexmatch.h"
00031 
00166 /****
00167      moved below comment out of above because the "wire"
00168      interface does not allow you to set these currently
00169 ****/
00170 /*
00171 Options:
00172 <ul>
00173 <li> AW_PSHANDLER_GROUP : Watch a group of processes defined by
00174 matching the regex. Only send 'up' events when the first
00175 match appears and only send 'down' events when the last match disappears.
00176 This is useful for applications like Apache which fork/kill
00177 child processes regularly. 
00178 <li> AW_PSHANDLER_COUNTONCHANGE : Only send 'count' events when the
00179 count of the processes matching the regex changes. By default, the
00180 'count' events are generated every cycle. This option is useful is you
00181 are interested in notification if the number of processes gets
00182 below or above a certain number (used with the rfilterhandler).
00183 </ul>
00184 
00185 \endhtmlonly
00186 
00187 */
00188 
00189 /* 
00190 
00191 Changes:
00192 
00193 02/11/04 Russell Leighton
00194 Port to handler
00195 
00196 03/12/02 Russell Leighton
00197 Fix small buglet if FILE_TO_BUF fails.
00198 
00199 */
00200 
00204 typedef enum {
00205 
00206   AW_PSHANDLER_GROUP = 0x1,         /* only send 'up'/'down' events based on whole group */
00207   AW_PSHANDLER_COUNTONCHANGE = 0x2, /* only send 'count' events when count changes */
00208 
00209 } aw_pshandler_flag_t;
00210 
00211 
00215 #define AW_PSHANDLER_DEFAULT_FLAGS ( AW_PSHANDLER_GROUP | AW_PSHANDLER_COUNTONCHANGE)
00216 
00220 typedef struct aw_pshandler_pidlist_s {
00221 
00222   struct aw_pshandler_pidlist_s 
00223    *next;
00224 
00225   u_int32_t
00226    pid;
00227 
00228   /* rss / memtotal (as a decimal) */
00229   float64_t
00230    percentmem;
00231 
00232   /* utime + stime */
00233   aw_timestamp_t
00234    totaltime;
00235 
00236 } aw_pshandler_pidlist_t;
00237 
00241 typedef struct aw_pshandler_watchlist_s {
00242 
00243   struct aw_pshandler_watchlist_s 
00244    *next;
00245 
00246   u_int32_t
00247    pid;
00248 
00249   byte_t
00250    *cmdline;
00251 
00252 } aw_pshandler_watchlist_t;
00253 
00254 
00258 typedef struct {
00259 
00260   aw_event_sig_t
00261    up,               /* regex matched and process is noticed up */
00262    down,             /* regex matched and process is noticed down */
00263    count;            /* count of regex matched processes */
00264 
00265 } aw_pshandler_events_t;
00266 
00270 typedef struct {
00271 
00272   /* total main memory in KB , used to calc %mem */
00273   u_int32_t
00274    memtotal;
00275 
00276   /* open stream to /proc */
00277   DIR
00278    *dir;             
00279 
00280   /* sorted list of pids that were up last poll interval */
00281   aw_pshandler_pidlist_t
00282    *up;              
00283 
00284   aw_cache_allocator_t
00285    pidlist_factory;
00286 
00287   /* last time the handler was run */
00288   aw_timestamp_t
00289    last_handler_timestamp;
00290 
00291 } aw_pshandler_state_t;
00292 
00293 
00294 
00298 typedef struct {
00299 
00300   aw_pshandler_flag_t
00301    flags;
00302 
00303   aw_pshandler_events_t
00304     events;
00305 
00306   /* regex string */
00307   const byte_t
00308    *regex;
00309 
00310   /* holds substitution string, may be NULL */
00311   const byte_t
00312    *subst;
00313 
00314 } aw_pshandler_regex_t;
00315 
00319 typedef struct {
00320 
00321   aw_pshandler_flag_t
00322    flags;
00323 
00324   aw_pshandler_events_t
00325     events;
00326 
00327   /* holds compiled regular expression  */
00328   regex_t
00329    pattern;
00330 
00331   /* holds substitution string, may be NULL */
00332   byte_t
00333    *subst;
00334 
00335   aw_pshandler_watchlist_t
00336    *watch;           /* list of pids that are in 'up' that matched regex */
00337 
00338   u_int32_t
00339    watchcount;       /* length of watch list */
00340 
00341 } aw_pshandler_watcher_t;
00342 
00346 typedef struct {
00347 
00348   /* generate event if proceses %mem is in [min,max] */
00349   float64_t
00350    min,max;
00351 
00352   aw_event_sig_t
00353    memevent;
00354 
00355 } aw_pshandler_memfilter_t;
00356 
00357 
00361 typedef struct {
00362 
00363   /* generate event if proceses %cpu is in [min,max] */
00364   float64_t
00365    min,max;
00366 
00367   aw_event_sig_t
00368    cpuevent;
00369 
00370 } aw_pshandler_cpufilter_t;
00371 
00372 
00376 typedef struct {
00377 
00378   aw_handler_t 
00379     handler_header;
00380 
00381   u_int32_t
00382    nwatchers;
00383 
00384   aw_pshandler_watcher_t
00385    *watchers;
00386 
00387   aw_pshandler_memfilter_t
00388    memfilter;
00389 
00390   aw_pshandler_cpufilter_t
00391    cpufilter;
00392 
00393   aw_pshandler_state_t
00394    state;
00395 
00396 } aw_pshandler_t ;
00397 
00398 
00411 aw_pshandler_t *aw_create_pshandler(u_int32_t nregexs,
00412                                     aw_pshandler_regex_t *regexs,    
00413                                     aw_pshandler_memfilter_t *memfilter,
00414                                     aw_pshandler_cpufilter_t *cpufilter, 
00415                                     int32_t (*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00416                                     int32_t (*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00417                                     const aw_alarm_sched_t *sched,
00418                                     aw_logger_t *logger
00419                                     );
00420 
00425 void aw_free_pshandler(aw_pshandler_t *p);
00426 
00430 aw_handler_t *aw_wire_pshandler(aw_wire_mkhandler_args_t *args);
00431 
00432 #endif
00433 
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)