Beispiel #1
0
static int cc_read_page (web_page_t *wp) /* {{{ */
{
  int status;
  cdtime_t start = 0;

  if (wp->response_time)
    start = cdtime ();

  wp->buffer_fill = 0;
  status = curl_easy_perform (wp->curl);
  if (status != CURLE_OK)
  {
    ERROR ("curl plugin: curl_easy_perform failed with status %i: %s",
        status, wp->curl_errbuf);
    return (-1);
  }

  if (wp->response_time)
    cc_submit_response_time (wp, cdtime() - start);
  if (wp->stats != NULL)
    curl_stats_dispatch (wp->stats, wp->curl, hostname_g, "curl", wp->instance);

  if(wp->response_code)
  {
    long response_code = 0;
    status = curl_easy_getinfo(wp->curl, CURLINFO_RESPONSE_CODE, &response_code);
    if(status != CURLE_OK) {
      ERROR ("curl plugin: Fetching response code failed with status %i: %s",
        status, wp->curl_errbuf);
    } else {
      cc_submit_response_code(wp, response_code);
    }
  }

  for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next)
  {
    cu_match_value_t *mv;

    status = match_apply (wm->match, wp->buffer);
    if (status != 0)
    {
      WARNING ("curl plugin: match_apply failed.");
      continue;
    }

    mv = match_get_user_data (wm->match);
    if (mv == NULL)
    {
      WARNING ("curl plugin: match_get_user_data returned NULL.");
      continue;
    }

    cc_submit (wp, wm, mv);
    match_value_reset (mv);
  } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */

  return (0);
} /* }}} int cc_read_page */
Beispiel #2
0
static int cc_read_page (web_page_t *wp) /* {{{ */
{
  web_match_t *wm;
  int status;
  struct timeval start, end;

  if (wp->response_time)
    gettimeofday (&start, NULL);

  wp->buffer_fill = 0;
  status = curl_easy_perform (wp->curl);
  if (status != CURLE_OK)
  {
    ERROR ("curl plugin: curl_easy_perform failed with staus %i: %s",
        status, wp->curl_errbuf);
    return (-1);
  }

  if (wp->response_time)
  {
    double secs = 0;
    gettimeofday (&end, NULL);
    secs += end.tv_sec - start.tv_sec;
    secs += (end.tv_usec - start.tv_usec) / 1000000.0;
    cc_submit_response_time (wp, secs);
  }

  for (wm = wp->matches; wm != NULL; wm = wm->next)
  {
    cu_match_value_t *mv;

    status = match_apply (wm->match, wp->buffer);
    if (status != 0)
    {
      WARNING ("curl plugin: match_apply failed.");
      continue;
    }

    mv = match_get_user_data (wm->match);
    if (mv == NULL)
    {
      WARNING ("curl plugin: match_get_user_data returned NULL.");
      continue;
    }

    cc_submit (wp, wm, mv);
  } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */

  return (0);
} /* }}} int cc_read_page */
Beispiel #3
0
static int cmc_read_page (web_page_t *wp) /* {{{ */
{
  web_match_t *wm;
  memcached_return rc;
  size_t string_length;
  uint32_t flags;
  int status;

  if (wp->memc == NULL)
    return (-1);

  wp->buffer = memcached_get (wp->memc, wp->key, strlen (wp->key),
                              &string_length, &flags, &rc);
  if (rc != MEMCACHED_SUCCESS)
  {
    ERROR ("memcachec plugin: memcached_get failed: %s",
        memcached_strerror (wp->memc, rc));
    return (-1);
  }

  for (wm = wp->matches; wm != NULL; wm = wm->next)
  {
    cu_match_value_t *mv;

    status = match_apply (wm->match, wp->buffer);
    if (status != 0)
    {
      WARNING ("memcachec plugin: match_apply failed.");
      continue;
    }

    mv = match_get_user_data (wm->match);
    if (mv == NULL)
    {
      WARNING ("memcachec plugin: match_get_user_data returned NULL.");
      continue;
    }

    cmc_submit (wp, wm, mv);
    match_value_reset (mv);
  } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */

  sfree (wp->buffer);

  return (0);
} /* }}} int cmc_read_page */
Beispiel #4
0
static int latency_submit_match(cu_match_t *match, void *user_data) {
  cu_tail_match_simple_t *data = (cu_tail_match_simple_t *)user_data;
  cu_match_value_t *match_value;
  value_list_t vl = VALUE_LIST_INIT;

  match_value = (cu_match_value_t *)match_get_user_data(match);
  if (match_value == NULL)
    return (-1);

  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
  sstrncpy(vl.plugin, data->plugin, sizeof(vl.plugin));
  sstrncpy(vl.plugin_instance, data->plugin_instance,
           sizeof(vl.plugin_instance));
  vl.interval = data->interval;
  vl.time = cdtime();

  /* Submit percentiles */
  sstrncpy(vl.type, data->type, sizeof(vl.type));
  for (size_t i = 0; i < data->latency_config.percentile_num; i++) {
    if (strlen(data->type_instance) != 0)
      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f",
                data->type_instance, data->latency_config.percentile[i]);
    else
      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%.0f",
                data->latency_config.percentile[i]);

    vl.values = &(value_t){
        .gauge =
            (match_value->values_num != 0)
                ? CDTIME_T_TO_DOUBLE(latency_counter_get_percentile(
                      match_value->latency, data->latency_config.percentile[i]))
                : NAN,
    };
    vl.values_len = 1;

    plugin_dispatch_values(&vl);
  }

  /* Submit buckets */
  sstrncpy(vl.type, "bucket", sizeof(vl.type));
  for (size_t i = 0; i < data->latency_config.buckets_num; i++) {
    latency_bucket_t bucket = data->latency_config.buckets[i];

    double lower_bound = CDTIME_T_TO_DOUBLE(bucket.lower_bound);
    double upper_bound =
        bucket.upper_bound ? CDTIME_T_TO_DOUBLE(bucket.upper_bound) : INFINITY;

    if (strlen(data->type_instance) != 0)
      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
                data->type, data->type_instance, lower_bound, upper_bound);
    else
      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
                data->type, lower_bound, upper_bound);

    vl.values = &(value_t){
        .gauge =
            latency_counter_get_rate(match_value->latency, bucket.lower_bound,
                                     bucket.upper_bound, vl.time),
    };
    vl.values_len = 1;

    plugin_dispatch_values(&vl);
  }

  match_value->value.gauge = NAN;
  match_value->values_num = 0;
  latency_counter_reset(match_value->latency);

  return (0);
} /* int latency_submit_match */

static int tail_callback(void *data, char *buf,
                         int __attribute__((unused)) buflen) {
  cu_tail_match_t *obj = (cu_tail_match_t *)data;

  for (size_t i = 0; i < obj->matches_num; i++)
    match_apply(obj->matches[i].match, buf);

  return (0);
} /* int tail_callback */

static void tail_match_simple_free(void *data) {
  cu_tail_match_simple_t *user_data = (cu_tail_match_simple_t *)data;
  latency_config_free(user_data->latency_config);
  sfree(user_data);
} /* void tail_match_simple_free */

/*
 * Public functions
 */
cu_tail_match_t *tail_match_create(const char *filename) {
  cu_tail_match_t *obj;

  obj = calloc(1, sizeof(*obj));
  if (obj == NULL)
    return (NULL);

  obj->tail = cu_tail_create(filename);
  if (obj->tail == NULL) {
    sfree(obj);
    return (NULL);
  }

  return (obj);
} /* cu_tail_match_t *tail_match_create */