コード例 #1
0
static void
handle_metric_buffer(const char *payload, int payload_len,
    int has_noit) {

  if (payload_len <= 0) {
    return;
  }

  switch (payload[0]) {
    case 'C':
    case 'D':
    case 'S':
    case 'H':
    case 'M':
      {
        // mtev_fq will free the fq_msg -> copy the payload
        char *copy = mtev__strndup(payload, payload_len);
        noit_metric_message_t *message = calloc(1, sizeof(noit_metric_message_t));

        message->type = copy[0];
        message->original_message = copy;
        message->original_message_len = payload_len;
        noit_metric_director_message_ref(message);

        int rv = noit_message_decoder_parse_line(copy, payload_len,
            &message->id.id, &message->id.name,
            &message->id.name_len, &message->value, has_noit);

        if(rv == 1) {
          distribute_message(message);
        }

        noit_metric_director_message_deref(message);
      }
      break;
    case 'B':
      {
        int n_metrics, i;
        char **metrics = NULL;
        n_metrics = noit_check_log_b_to_sm((const char *)payload, payload_len,
            &metrics, has_noit);
        for(i = 0; i < n_metrics; i++) {
          handle_metric_buffer(metrics[i], strlen(metrics[i]), false);
          free(metrics[i]);
        }
        free(metrics);
      }
      break;
    default: ;
      /* ignored */
  }
}
コード例 #2
0
static void
send_individual_metric(noit_websocket_closure_t *wcl, const char *metric_string, size_t len)
{
#ifdef HAVE_WSLAY
  noit_metric_message_t message;
  char *json = NULL;
  size_t json_len = 0;

  int rval = noit_message_decoder_parse_line(metric_string, len, &message.id.id, &message.id.name,
                                             &message.id.name_len, &message.value, mtev_false);
  if (rval < 0) {
    return;
  }

  message.type = metric_string[0];

  if (wcl->use_filter == mtev_true) {
    for (int i = 0; i < wcl->filter_count; i++) {
      if (message.id.name_len > 0 &&
        strncmp(wcl->filters[i], message.id.name, message.id.name_len) == 0) {
        noit_metric_to_json(&message, &json, &json_len, mtev_false);
        mtev_http_websocket_queue_msg(wcl->restc->http_ctx,
                                      WSLAY_TEXT_FRAME,
                                      (const unsigned char *)json, json_len);
        free(json);
        break;
      }
    }
  } else {
        noit_metric_to_json(&message, &json, &json_len, mtev_false);
        mtev_http_websocket_queue_msg(wcl->restc->http_ctx,
                                      WSLAY_TEXT_FRAME,
                                      (const unsigned char *)json, json_len);
        free(json);
  }
#endif
}
コード例 #3
0
mtev_http_websocket_queue_msg(wcl->restc->http_ctx,
                              WSLAY_TEXT_FRAME,
                              (const unsigned char *)heartbeat_str, heartbeat_str_len);
#endif
}

static int
send_individual_metric(noit_websocket_closure_t *wcl, const char *metric_string, size_t len)
{
#ifdef HAVE_WSLAY
  noit_metric_message_t message = { .original_message = (char *)metric_string, .original_message_len = len };
  char *json = NULL;
  size_t json_len = 0;
  int sent = 0;

  int rval = noit_message_decoder_parse_line(&message, mtev_false);
  if (rval < 0) {
    noit_metric_message_clear(&message);
    return sent;
  }

  message.type = metric_string[0];

  if (wcl->use_filter == mtev_true) {
    for (int i = 0; i < wcl->filter_count; i++) {
      if ((message.id.name_len_with_tags > 0) &&
          (strlen(wcl->filters[i]) == message.id.name_len_with_tags) &&
          (0 == memcmp(wcl->filters[i], message.id.name, message.id.name_len_with_tags))) {
        noit_metric_to_json(&message, &json, &json_len, mtev_false);
        mtev_http_websocket_queue_msg(wcl->restc->http_ctx,
                                      WSLAY_TEXT_FRAME,