From: Florian G. <re...@us...> - 2008-01-03 22:06:10
|
Update of /cvsroot/perfparse/_perfparse/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10160/modules Modified Files: Makefile.am Makefile.in libpp_storage.h storage_mysql.c Log Message: some refactoring Index: Makefile.in =================================================================== RCS file: /cvsroot/perfparse/_perfparse/modules/Makefile.in,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Makefile.in 18 Dec 2007 15:10:34 -0000 1.21 --- Makefile.in 3 Jan 2008 22:04:44 -0000 1.22 *************** *** 332,338 **** top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ ! STORAGE_INCLUDES = ${GLIB_CFLAGS} -I${top_srcdir} -I${top_srcdir}/libpp_common -I${top_srcdir}/libnagios_perfdata_parser '-DLOCALEDIR="$(datadir)/locale"' STORAGE_LIBS = ! STORAGE_LDFLAGS = -module @USE_DB_MYSQL_TRUE@GO_LIBPP_STORAGE_MYSQL = libpp_storage_mysql.la @USE_DB_POSTGRESQL_TRUE@GO_LIBPP_STORAGE_POSTGRESQL = libpp_storage_postgresql.la --- 332,341 ---- top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ ! ! # Perfparse storage module api. Change if API has changed. ! STORAGE_MODULE_API_VERSION = 2 ! STORAGE_INCLUDES = ${GLIB_CFLAGS} -I${top_srcdir} -I${top_srcdir}/libpp_common -I${top_srcdir}/libnagios_perfdata_parser '-DLOCALEDIR="$(datadir)/locale"' -DSTORAGE_MODULE_API_VERSION=${STORAGE_MODULE_API_VERSION} STORAGE_LIBS = ! STORAGE_LDFLAGS = -module -version-info ${STORAGE_MODULE_API_VERSION}:0:0 @USE_DB_MYSQL_TRUE@GO_LIBPP_STORAGE_MYSQL = libpp_storage_mysql.la @USE_DB_POSTGRESQL_TRUE@GO_LIBPP_STORAGE_POSTGRESQL = libpp_storage_postgresql.la Index: libpp_storage.h =================================================================== RCS file: /cvsroot/perfparse/_perfparse/modules/libpp_storage.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** libpp_storage.h 18 Dec 2007 15:08:50 -0000 1.4 --- libpp_storage.h 3 Jan 2008 22:04:44 -0000 1.5 *************** *** 28,33 **** #define __LIB_STORAGE__ - // versioning for storage modules to avoid loading of incompatible modules - #define STORAGE_MODULE_API_VERSION 2 #include <time.h> --- 28,31 ---- Index: Makefile.am =================================================================== RCS file: /cvsroot/perfparse/_perfparse/modules/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Makefile.am 26 Sep 2005 14:36:33 -0000 1.1.1.1 --- Makefile.am 3 Jan 2008 22:04:44 -0000 1.2 *************** *** 1,5 **** ! STORAGE_INCLUDES=${GLIB_CFLAGS} -I${top_srcdir} -I${top_srcdir}/libpp_common -I${top_srcdir}/libnagios_perfdata_parser '-DLOCALEDIR="$(datadir)/locale"' STORAGE_LIBS= ! STORAGE_LDFLAGS=-module if USE_DB_MYSQL --- 1,9 ---- ! # Perfparse storage module api. Change if API has changed. ! STORAGE_MODULE_API_VERSION=2 ! ! STORAGE_INCLUDES=${GLIB_CFLAGS} -I${top_srcdir} -I${top_srcdir}/libpp_common -I${top_srcdir}/libnagios_perfdata_parser '-DLOCALEDIR="$(datadir)/locale"' -DSTORAGE_MODULE_API_VERSION=${STORAGE_MODULE_API_VERSION} STORAGE_LIBS= ! ! STORAGE_LDFLAGS=-module -version-info ${STORAGE_MODULE_API_VERSION}:0:0 if USE_DB_MYSQL Index: storage_mysql.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/modules/storage_mysql.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** storage_mysql.c 18 Dec 2007 15:08:50 -0000 1.21 --- storage_mysql.c 3 Jan 2008 22:04:44 -0000 1.22 *************** *** 5,9 **** * $Id$ * ! * Copyright (c) 2004-2007 Ben Clewett, Florian Gleixner * * License: --- 5,9 ---- * $Id$ * ! * Copyright (c) 2004-2008 Ben Clewett, Florian Gleixner * * License: *************** *** 68,74 **** void storage_mysql_periodic_cleanup(storage_module_t *); - void purge_all_metricid_data(int); - void purge_all_serviceid_data(int); - static int validate_host(storage_module_t*this, const char *); static int validate_service(storage_module_t*this, const char *, const char *); --- 68,71 ---- *************** *** 370,378 **** pp_log_func; /* delete all data of objects that are marked as deleted */ ! GSList *tmplist2,*tmplist=NULL; ! int *p=NULL; ! time_t dps=DEL_POLICY_UNDEFINED; ! time_t t=time(NULL); ! // connect again to mysql since this is a forked process --- 367,371 ---- pp_log_func; /* delete all data of objects that are marked as deleted */ ! // connect again to mysql since this is a forked process *************** *** 380,504 **** pp_log(__FILE__,__LINE__,LOG_DEBUG_SQL,"MySQL version: %s\n", query_char("SELECT VERSION()")); ! // find metric ids to delete completely ! g_string_printf(s_SQL, "SELECT metric_id from perfdata_service_metric where is_deleted=1"); ! query(s_SQL->str); ! ! while ((result_row = mysql_fetch_row(query_result))) { ! p = (int *)malloc(sizeof(int)); ! *p = iData(0); ! pp_log(__FILE__,__LINE__,LOG_DEBUG,"metric_id %d is marked for deletion\n",iData(0)); ! tmplist=g_slist_append(tmplist,p); ! } ! ! tmplist2=tmplist; ! while(tmplist2) { ! purge_all_metricid_data(*(int *)tmplist2->data); ! tmplist2=g_slist_next(tmplist2); ! } ! ! g_slist_free(tmplist); ! tmplist2=tmplist=NULL; ! ! // find service ids to delete completely ! g_string_printf(s_SQL, "SELECT service_id from perfdata_service where is_deleted=1"); ! query(s_SQL->str); ! ! while ((result_row = mysql_fetch_row(query_result))) { ! p = (int *)malloc(sizeof(int)); ! *p = iData(0); ! pp_log(__FILE__,__LINE__,LOG_DEBUG,"service_id %d is marked for deletion\n",iData(0)); ! tmplist=g_slist_append(tmplist,p); ! } ! ! tmplist2=tmplist; ! while(tmplist2) { ! purge_all_serviceid_data(*(int *)tmplist2->data); ! tmplist2=g_slist_next(tmplist2); ! } ! ! g_slist_free(tmplist); ! tmplist2=tmplist=NULL; - /* walk through all services and metrics and purge old data */ - t_policyinfo *raw_policyinfo=NULL; - - g_string_printf(s_SQL,"SELECT service_id,service_description,host_id,policy_name,delete_policy_seconds,raw_delete_policy_individual FROM perfdata_service s LEFT JOIN perfdata_delete_policy d ON s.raw_delete_policy_id=d.policy_id"); - query(s_SQL->str); - - while ((result_row = mysql_fetch_row(query_result))) { - raw_policyinfo = (t_policyinfo *)malloc(sizeof(t_policyinfo)); - raw_policyinfo->iPolicySource=DEL_POLICY_SOURCE_NONE; - raw_policyinfo->iServiceId = iData(0); - raw_policyinfo->sServiceDesc=strdup(sData(1)); - raw_policyinfo->iHostId=iData(2); - raw_policyinfo->sPolicyName=strdup(sData(3)); - raw_policyinfo->iPolicySeconds=DEL_POLICY_UNDEFINED; - - if(!isNull(5)) { - raw_policyinfo->iPolicySeconds=iData(5); - raw_policyinfo->iPolicySource=DEL_POLICY_SOURCE_SERVICE; - } else if (!isNull(4)){ - raw_policyinfo->iPolicySeconds=iData(4); - raw_policyinfo->iPolicySource=DEL_POLICY_SOURCE_SERVICE_GROUP; - } - - tmplist=g_slist_append(tmplist,raw_policyinfo); - } - - tmplist2=tmplist; - - while(tmplist2) { - raw_policyinfo=(t_policyinfo *) tmplist2->data; - if(raw_policyinfo->iPolicySource==DEL_POLICY_SOURCE_NONE) { // get policy info from host or hostgroup - getRawHostPolicy(raw_policyinfo); - } - - pp_log(__FILE__,__LINE__,LOG_DEBUG,"service_id %d raw policy info (ServiceDesc: %s,HostId: %d, PolicyName: %s, PolicySeconds: %d, PolicySource: %d) in temporary list\n" - ,raw_policyinfo->iServiceId,raw_policyinfo->sServiceDesc, - raw_policyinfo->iHostId,raw_policyinfo->sPolicyName, - raw_policyinfo->iPolicySeconds, - raw_policyinfo->iPolicySource); - //todo: now purge data - - if(raw_policyinfo->iPolicySeconds>1) { - dps=t-raw_policyinfo->iPolicySeconds; - pp_log_fl(LOG_INFO,_("Purging raw data older than %s from service '%s', ServiceId %d due to "), - asctime(localtime(&dps)),raw_policyinfo->sServiceDesc, - raw_policyinfo->iServiceId); - switch(raw_policyinfo->iPolicySource) { - case DEL_POLICY_SOURCE_SERVICE: - pp_log_fl(LOG_INFO,_("individual service setting\n")); - break; - case DEL_POLICY_SOURCE_HOST: - pp_log_fl(LOG_INFO,_("individual host setting\n")); - break; - case DEL_POLICY_SOURCE_HOSTGROUP: - pp_log_fl(LOG_INFO,_("individual hostgroup setting\n")); - break; - case DEL_POLICY_SOURCE_SERVICE_GROUP: - pp_log_fl(LOG_INFO,_("group '%s' setting in service.\n"),raw_policyinfo->sPolicyName); - break; - case DEL_POLICY_SOURCE_HOST_GROUP: - pp_log_fl(LOG_INFO,_("group '%s' setting in host.\n"),raw_policyinfo->sPolicyName); - break; - case DEL_POLICY_SOURCE_HOSTGROUP_GROUP: - pp_log_fl(LOG_INFO,_("group '%s' setting in hostgroup.\n"),raw_policyinfo->sPolicyName); - break; - case DEL_POLICY_SOURCE_DEFAULT: - pp_log_fl(LOG_INFO,_("default setting.\n")); - default: - pp_log_fl(LOG_FATAL,_("This is a error. This line should not be executed.\n")); - } - - - g_string_printf(s_SQL,"DELETE FROM perfdata_service_raw WHERE service_id=%d and ctime < %d", - raw_policyinfo->iServiceId,(int) dps); - query(s_SQL->str); - } - tmplist2=g_slist_next(tmplist2); - } --- 373,384 ---- pp_log(__FILE__,__LINE__,LOG_DEBUG_SQL,"MySQL version: %s\n", query_char("SELECT VERSION()")); ! purge_all_deleted_metrics(); ! purge_all_deleted_services(); /* walk through all services and metrics and purge old data */ + purge_raw_by_policy(); + purge_bin_by_policy(); *************** *** 513,531 **** *******************************************************/ - void purge_all_metricid_data(int iMid) { - pp_log_func; - pp_log(__FILE__,__LINE__,LOG_INFO,"Deleting all data from metric id %d\n",iMid); - g_string_printf(s_SQL,"DELETE from perfdata_service_bin WHERE metric_id=%d",iMid); - query_no_return(s_SQL->str); - } - - void purge_all_serviceid_data(int iSid) { - pp_log_func; - pp_log(__FILE__,__LINE__,LOG_INFO,"Deleting all data from service id %d\n",iSid); - g_string_printf(s_SQL,"DELETE from perfdata_service_raw WHERE service_id=%d",iSid); - query_no_return(s_SQL->str); - } - - /******************************************************** * --- 393,396 ---- |