--- projects/cms/source/ihost/ihost.c 2002/05/17 11:21:17 1.9 +++ projects/cms/source/ihost/ihost.c 2002/05/19 15:14:31 1.15 @@ -1,13 +1,33 @@ +/* + * i-scream central monitoring system + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include -#include #include #include #include #include #include "ukcprog.h" #include -#include +#include #include "statgrab.h" +#include +#include #define RECONFIGURE_RETURN_CODE 2 #define UDP_MAX_PACKET_SIZE 8192 @@ -274,6 +294,9 @@ int heartbeat(ihost_state_t *ihost_state){ return -1; } + fflush(fm_fd_r); + fflush(fm_fd_w); + if(fclose(fm_fd_r) !=0){ errf("Failed to close read FD (%m)"); return -1; @@ -362,6 +385,8 @@ int send_stats(ihost_state_t *ihost_state, char *data_ return -1; } + close(sd); + return 0; } @@ -369,7 +394,7 @@ int main(int argc, char **argv){ ihost_state_t ihost_state; int heartbeat_exit; int counter=0; - long udp_time=0, tcp_time=0, cur_time=0; + long udp_time=0, tcp_time=0, stat_grab_time=0, cur_time=0; int sleep_delay=0; char *xml_stats; @@ -397,25 +422,13 @@ int main(int argc, char **argv){ exit(1); } - /* get starting stats */ - if((heartbeat(&ihost_state)) == -1){ - errf("inital heartbeat failed (%m)"); - exit(1); - } - - - if((xml_stats=stat_grab(&ihost_state, counter)) == NULL){ - errf("Failed to get stats (%m)"); - exit(1); - } - - for(;;){ cur_time=time(NULL); if(cur_time>=tcp_time){ + /*printf("sending TCP\n");*/ heartbeat_exit=heartbeat(&ihost_state); if(heartbeat_exit==RECONFIGURE_RETURN_CODE){ - errf("heartbeat needs to be reconfigured"); + /*errf("heartbeat needs to be reconfigured");*/ ihost_configure(&ihost_state); /* So udp doesn't wait til next sending before updating */ udp_time=0; @@ -426,21 +439,28 @@ int main(int argc, char **argv){ } tcp_time=time(NULL)+ihost_state.tcp_update_time; } + if(cur_time>=udp_time){ - send_stats(&ihost_state, xml_stats); - free(xml_stats); - if((xml_stats=stat_grab(&ihost_state, counter)) == NULL){ + /*printf("sending UDP\n");*/ + stat_grab_time=time(NULL); + if((xml_stats=stat_grab(&ihost_state, counter++)) == NULL){ errf("Failed to get stats (%m)"); exit(1); } - udp_time=time(NULL)+ihost_state.udp_update_time; + stat_grab_time=time(NULL)-stat_grab_time; + send_stats(&ihost_state, xml_stats); + free(xml_stats); + udp_time=time(NULL)+ihost_state.udp_update_time-stat_grab_time; } - if(tcp_time>udp_time){ - sleep_delay=time(NULL)-tcp_time; + + if(tcp_time0) sleep(sleep_delay); } return 0; }