Show
Ignore:
Timestamp:
03/02/11 21:16:23 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1299100583 +0000
git-parent:

[bf924d6886edb8393112493c37f2b1132cb1bcfe]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1299100583 +0000
Message:

implementation of separating status and metrics logging, refs #356

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check.c

    r7fac98e r870413e  
    860860  s->available = NP_UNKNOWN; 
    861861} 
    862 static void 
    863 __free_metric(void *vm) { 
    864   metric_t *m = vm
    865   free(m->metric_name); 
     862void 
     863free_metric(metric_t *m) { 
     864  if(!m) return
     865  if(m->metric_name) free(m->metric_name); 
    866866  if(m->metric_value.i) free(m->metric_value.i); 
    867867  free(m); 
     
    871871__stats_add_metric(stats_t *newstate, metric_t *m) { 
    872872  noit_hash_replace(&newstate->metrics, m->metric_name, strlen(m->metric_name), 
    873                     m, NULL, __free_metric); 
     873                    m, NULL, (void (*)(void *))free_metric); 
    874874} 
    875875 
     
    10091009  return type; 
    10101010} 
    1011 void 
    1012 noit_stats_set_metric(stats_t *newstate, const char *name, metric_type_t type, 
    1013                       void *value) { 
    1014   metric_t *m; 
     1011int 
     1012noit_stats_populate_metric(metric_t *m, const char *name, metric_type_t type, 
     1013                           void *value) { 
    10151014  void *replacement = NULL; 
    10161015  if(type == METRIC_GUESS) 
    10171016    type = noit_metric_guess_type((char *)value, &replacement); 
    1018   if(type == METRIC_GUESS) return; 
    1019  
    1020   m = calloc(1, sizeof(*m)); 
     1017  if(type == METRIC_GUESS) return -1; 
     1018 
    10211019  m->metric_name = strdup(name); 
    10221020  m->metric_type = type; 
     
    10291027    memcpy(m->metric_value.vp, value, len); 
    10301028  } 
     1029  return 0; 
     1030} 
     1031void 
     1032noit_stats_set_metric(stats_t *newstate, const char *name, metric_type_t type, 
     1033                      void *value) { 
     1034  metric_t *m = calloc(1, sizeof(*m)); 
     1035  if(noit_stats_populate_metric(m, name, type, value)) { 
     1036    free_metric(m); 
     1037    return; 
     1038  } 
    10311039  __stats_add_metric(newstate, m); 
     1040} 
     1041void 
     1042noit_stats_log_immediate_metric(noit_check_t *check, 
     1043                                const char *name, metric_type_t type, 
     1044                                void *value) { 
     1045  struct timeval now; 
     1046  metric_t *m = calloc(1, sizeof(*m)); 
     1047  if(noit_stats_populate_metric(m, name, type, value)) { 
     1048    free_metric(m); 
     1049    return; 
     1050  } 
     1051  gettimeofday(&now, NULL); 
     1052  noit_check_log_metric(check, &now, m); 
     1053  free_metric(m); 
    10321054} 
    10331055 
     
    10691091  if(check->stats.previous.status) 
    10701092    free(check->stats.previous.status); 
    1071   noit_hash_destroy(&check->stats.previous.metrics, NULL, __free_metric); 
     1093  noit_hash_destroy(&check->stats.previous.metrics, NULL, 
     1094                    (void (*)(void *))free_metric); 
    10721095  memcpy(&check->stats.previous, &check->stats.current, sizeof(stats_t)); 
    10731096  memcpy(&check->stats.current, newstate, sizeof(stats_t));