Changeset a1d250980c50e88be7098fda4f74a0acb7fb61a7

Show
Ignore:
Timestamp:
02/15/10 19:42:26 (4 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1266262946 +0000
git-parent:

[4c3718f19eebb897212b1b22151af348ad501cdb]

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

fixes #258

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/mysql.c

    r2b04ed7 ra1d2509  
    5858  noit_module_t *self; 
    5959  noit_check_t *check; 
     60  stats_t current; 
    6061  MYSQL *conn; 
    6162  MYSQL_RES *result; 
     63  double connect_duration_d; 
     64  double *connect_duration; 
     65  double query_duration_d; 
     66  double *query_duration; 
    6267  int rv; 
    6368  noit_hash_table attrs; 
     
    7984  } 
    8085} 
    81 static void mysql_log_results(noit_module_t *self, noit_check_t *check) { 
    82   stats_t current; 
    83   struct timeval duration; 
    84   mysql_check_info_t *ci = check->closure; 
    85  
    86   noit_check_stats_clear(&current); 
    87  
    88   gettimeofday(&current.whence, NULL); 
    89   sub_timeval(current.whence, check->last_fire_time, &duration); 
    90   current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 
    91   current.available = NP_UNAVAILABLE; 
    92   current.state = NP_BAD; 
    93   if(ci->error) current.status = ci->error; 
    94   else if(ci->timed_out) current.status = "timeout"; 
    95   else if(ci->rv == 0) { 
    96     current.available = NP_AVAILABLE; 
    97     current.state = NP_GOOD; 
    98     current.status = "no rows, ok"; 
    99   } 
    100   else { 
    101     current.available = NP_AVAILABLE; 
    102     current.state = NP_GOOD; 
    103     current.status = "got rows, ok"; 
    104   } 
    105  
    106   if(ci->rv >= 0) 
    107     noit_stats_set_metric(&current, "row_count", METRIC_INT32, &ci->rv); 
    108  
     86static void mysql_ingest_stats(mysql_check_info_t *ci) { 
    10987  if(ci->rv > 0) { 
    11088    /* metrics */ 
     
    138116              piv = &iv; 
    139117            } 
    140             noit_stats_set_metric(&current, mname, METRIC_INT32, piv); 
     118            noit_stats_set_metric(&ci->current, mname, METRIC_INT32, piv); 
    141119            break; 
    142120          case FIELD_TYPE_INT24: 
     
    147125              plv = &lv; 
    148126            } 
    149             noit_stats_set_metric(&current, mname, METRIC_INT64, plv); 
     127            noit_stats_set_metric(&ci->current, mname, METRIC_INT64, plv); 
    150128            break; 
    151129          case FIELD_TYPE_DECIMAL: 
     
    157135              pdv = &dv; 
    158136            } 
    159             noit_stats_set_metric(&current, mname, METRIC_DOUBLE, pdv); 
     137            noit_stats_set_metric(&ci->current, mname, METRIC_DOUBLE, pdv); 
    160138            break; 
    161139          default: 
    162140            if(!row[j]) sv = NULL; 
    163141            else sv = row[j]; 
    164             noit_stats_set_metric(&current, mname, METRIC_GUESS, sv); 
     142            noit_stats_set_metric(&ci->current, mname, METRIC_GUESS, sv); 
    165143            break; 
    166144        } 
     
    168146    } 
    169147  } 
    170   noit_check_set_stats(self, check, &current); 
     148
     149static void mysql_log_results(noit_module_t *self, noit_check_t *check) { 
     150  struct timeval duration; 
     151  mysql_check_info_t *ci = check->closure; 
     152 
     153  gettimeofday(&ci->current.whence, NULL); 
     154  sub_timeval(ci->current.whence, check->last_fire_time, &duration); 
     155  ci->current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 
     156  ci->current.available = NP_UNAVAILABLE; 
     157  ci->current.state = NP_BAD; 
     158  if(ci->error) ci->current.status = ci->error; 
     159  else if(ci->timed_out) ci->current.status = "timeout"; 
     160  else if(ci->rv == 0) { 
     161    ci->current.available = NP_AVAILABLE; 
     162    ci->current.state = NP_GOOD; 
     163    ci->current.status = "no rows, ok"; 
     164  } 
     165  else { 
     166    ci->current.available = NP_AVAILABLE; 
     167    ci->current.state = NP_GOOD; 
     168    ci->current.status = "got rows, ok"; 
     169  } 
     170 
     171  if(ci->rv >= 0) 
     172    noit_stats_set_metric(&ci->current, "row_count", METRIC_INT32, &ci->rv); 
     173  if(ci->connect_duration) 
     174    noit_stats_set_metric(&ci->current, "connect_duration", METRIC_DOUBLE, 
     175                          ci->connect_duration); 
     176  if(ci->query_duration) 
     177    noit_stats_set_metric(&ci->current, "query_duration", METRIC_DOUBLE, 
     178                          ci->query_duration); 
     179 
     180  noit_check_set_stats(self, check, &ci->current); 
    171181} 
    172182 
     
    220230  mysql_check_info_t *ci = closure; 
    221231  noit_check_t *check = ci->check; 
     232  struct timeval t1, t2, diff; 
    222233  noit_hash_table dsn_h = NOIT_HASH_EMPTY; 
    223234  const char *host=NULL; 
     
    241252  switch(mask) { 
    242253    case EVENTER_ASYNCH_WORK: 
     254      noit_check_stats_clear(&ci->current); 
     255      ci->connect_duration = NULL; 
     256      ci->query_duration = NULL; 
     257 
    243258      FETCH_CONFIG_OR(dsn, ""); 
    244259      noit_check_interpolate(dsn_buff, sizeof(dsn_buff), dsn, 
     
    267282        AVAIL_BAIL(mysql_error(ci->conn)); 
    268283 
     284      gettimeofday(&t1, NULL); 
     285      sub_timeval(t1, check->last_fire_time, &diff); 
     286      ci->connect_duration_d = diff.tv_sec * 1000.0 + diff.tv_usec / 1000.0; 
     287      ci->connect_duration = &ci->connect_duration_d; 
     288 
    269289      FETCH_CONFIG_OR(sql, ""); 
    270290      noit_check_interpolate(sql_buff, sizeof(sql_buff), sql, 
     
    272292      if (mysql_query(ci->conn, sql_buff)) 
    273293        AVAIL_BAIL(mysql_error(ci->conn)); 
     294 
     295      gettimeofday(&t2, NULL); 
     296      sub_timeval(t2, t1, &diff); 
     297      ci->query_duration_d = diff.tv_sec * 1000.0 + diff.tv_usec / 1000.0; 
     298      ci->query_duration = &ci->query_duration_d; 
     299 
    274300      ci->result = mysql_store_result(ci->conn); 
    275301      if(!ci->result) AVAIL_BAIL("mysql_store_result failed"); 
    276302      ci->rv = mysql_num_rows(ci->result); 
     303      mysql_ingest_stats(ci); 
    277304      ci->timed_out = 0; 
    278305      return 0; 
  • src/modules/postgres.c

    rf1f93ff ra1d2509  
    11/* 
    2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc. 
     2 * Copyright (c) 2007-2010, OmniTI Computer Consulting, Inc. 
    33 * All rights reserved. 
    44 * 
     
    7373  noit_module_t *self; 
    7474  noit_check_t *check; 
     75  stats_t current; 
    7576  PGconn *conn; 
    7677  PGresult *result; 
    7778  int rv; 
     79  double connect_duration_d; 
     80  double *connect_duration; 
     81  double query_duration_d; 
     82  double *query_duration; 
    7883  noit_hash_table attrs; 
    7984  int timed_out; 
     
    9499  } 
    95100} 
    96 static void postgres_log_results(noit_module_t *self, noit_check_t *check) { 
    97   stats_t current; 
    98   struct timeval duration; 
    99   postgres_check_info_t *ci = check->closure; 
    100  
    101   noit_check_stats_clear(&current); 
    102  
    103   gettimeofday(&current.whence, NULL); 
    104   sub_timeval(current.whence, check->last_fire_time, &duration); 
    105   current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 
    106   current.available = NP_UNAVAILABLE; 
    107   current.state = NP_BAD; 
    108   if(ci->error) current.status = ci->error; 
    109   else if(ci->timed_out) current.status = "timeout"; 
    110   else if(ci->rv == PGRES_COMMAND_OK) { 
    111     current.available = NP_AVAILABLE; 
    112     current.state = NP_GOOD; 
    113     current.status = "command ok"; 
    114   } 
    115   else if(ci->rv == PGRES_TUPLES_OK) { 
    116     current.available = NP_AVAILABLE; 
    117     current.state = NP_GOOD; 
    118     current.status = "tuples ok"; 
    119   } 
    120   else current.status = "internal error"; 
    121  
     101static void postgres_ingest_stats(postgres_check_info_t *ci) { 
    122102  if(ci->rv == PGRES_TUPLES_OK) { 
    123103    /* metrics */ 
     
    125105    nrows = PQntuples(ci->result); 
    126106    ncols = PQnfields(ci->result); 
    127     noit_stats_set_metric(&current, "row_count", METRIC_INT32, &nrows); 
     107    noit_stats_set_metric(&ci->current, "row_count", METRIC_INT32, &nrows); 
    128108    for (i=0; i<nrows; i++) { 
    129109      noitL(nldeb, "postgres: row %d [%d cols]:\n", i, ncols); 
     
    149129              piv = &iv; 
    150130            } 
    151             noit_stats_set_metric(&current, mname, METRIC_INT32, piv); 
     131            noit_stats_set_metric(&ci->current, mname, METRIC_INT32, piv); 
    152132            break; 
    153133          case INT2OID: 
     
    159139              plv = &lv; 
    160140            } 
    161             noit_stats_set_metric(&current, mname, METRIC_INT64, plv); 
     141            noit_stats_set_metric(&ci->current, mname, METRIC_INT64, plv); 
    162142          case FLOAT4OID: 
    163143          case FLOAT8OID: 
     
    168148              pdv = &dv; 
    169149            } 
    170             noit_stats_set_metric(&current, mname, METRIC_DOUBLE, pdv); 
     150            noit_stats_set_metric(&ci->current, mname, METRIC_DOUBLE, pdv); 
    171151          default: 
    172152            if(PQgetisnull(ci->result, i, j)) sv = NULL; 
    173153            else sv = PQgetvalue(ci->result, i, j); 
    174             noit_stats_set_metric(&current, mname, METRIC_GUESS, sv); 
     154            noit_stats_set_metric(&ci->current, mname, METRIC_GUESS, sv); 
    175155            break; 
    176156        } 
     
    178158    } 
    179159  } 
    180   noit_check_set_stats(self, check, &current); 
     160
     161static void postgres_log_results(noit_module_t *self, noit_check_t *check) { 
     162  struct timeval duration; 
     163  postgres_check_info_t *ci = check->closure; 
     164 
     165  gettimeofday(&ci->current.whence, NULL); 
     166  sub_timeval(ci->current.whence, check->last_fire_time, &duration); 
     167  ci->current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 
     168  ci->current.available = NP_UNAVAILABLE; 
     169  ci->current.state = NP_BAD; 
     170  if(ci->connect_duration) 
     171    noit_stats_set_metric(&ci->current, "connect_duration", METRIC_DOUBLE, 
     172                          ci->connect_duration); 
     173  if(ci->query_duration) 
     174    noit_stats_set_metric(&ci->current, "query_duration", METRIC_DOUBLE, 
     175                          ci->query_duration); 
     176  if(ci->error) ci->current.status = ci->error; 
     177  else if(ci->timed_out) ci->current.status = "timeout"; 
     178  else if(ci->rv == PGRES_COMMAND_OK) { 
     179    ci->current.available = NP_AVAILABLE; 
     180    ci->current.state = NP_GOOD; 
     181    ci->current.status = "command ok"; 
     182  } 
     183  else if(ci->rv == PGRES_TUPLES_OK) { 
     184    ci->current.available = NP_AVAILABLE; 
     185    ci->current.state = NP_GOOD; 
     186    ci->current.status = "tuples ok"; 
     187  } 
     188  else ci->current.status = "internal error"; 
     189 
     190  noit_check_set_stats(self, check, &ci->current); 
    181191} 
    182192 
     
    197207  char sql_buff[8192]; 
    198208  char dsn_buff[512]; 
     209  struct timeval t1, t2, diff; 
    199210  postgres_check_info_t *ci = closure; 
    200211  noit_check_t *check = ci->check; 
     
    209220    return 0; 
    210221  } 
     222 
    211223  switch(mask) { 
    212224    case EVENTER_ASYNCH_WORK: 
     225      noit_check_stats_clear(&ci->current); 
     226      ci->connect_duration = NULL; 
     227      ci->query_duration = NULL; 
     228 
    213229      FETCH_CONFIG_OR(dsn, ""); 
    214230      noit_check_interpolate(dsn_buff, sizeof(dsn_buff), dsn, 
     
    222238      noit_check_interpolate(sql_buff, sizeof(sql_buff), sql, 
    223239                             &ci->attrs, check->config); 
     240      gettimeofday(&t1, NULL); 
     241      sub_timeval(t1, check->last_fire_time, &diff); 
     242      ci->connect_duration_d = diff.tv_sec * 1000.0 + diff.tv_usec / 1000.0; 
     243      ci->connect_duration = &ci->connect_duration_d; 
     244 
    224245      ci->result = PQexec(ci->conn, sql_buff); 
     246 
     247      gettimeofday(&t2, NULL); 
     248      sub_timeval(t2, t1, &diff); 
     249      ci->query_duration_d = diff.tv_sec * 1000.0 + diff.tv_usec / 1000.0; 
     250      ci->query_duration = &ci->query_duration_d; 
     251 
    225252      if(!ci->result) AVAIL_BAIL("PQexec failed"); 
    226253      ci->rv = PQresultStatus(ci->result); 
    227254      switch(ci->rv) { 
    228255       case PGRES_TUPLES_OK: 
     256        postgres_ingest_stats(ci); 
    229257       case PGRES_COMMAND_OK: 
    230258        break;