static mtev_hook_return_t zipkin_fq_publish(void *closure, int64_t traceid, int64_t spanid, unsigned char *buf, size_t len) { if(N_L_S_ON(debugls)) { int blen; char *b64buf; b64buf = malloc(len*2); blen = mtev_b64_encode(buf,len,b64buf,len*3); b64buf[blen] = '\0'; mtevL(debugls,"%s\n", b64buf); free(b64buf); } if(zc_client != NULL) { char buff[128]; fq_msg *msg; snprintf(buff, sizeof(buff), "%s%llx", zc_routing_prefix, (long long int)traceid); msg = fq_msg_alloc(buf, len); fq_msg_id(msg,NULL); fq_msg_route(msg, buff, strlen(buff)); fq_msg_exchange(msg, zc_exchange, strlen(zc_exchange)); fq_client_publish(zc_client, msg); fq_msg_free(msg); } return MTEV_HOOK_CONTINUE; }
static void log_histo(struct histogram_config *conf, noit_check_t *check, u_int64_t whence_s, const char *metric_name, histogram_t *h, mtev_boolean live_feed) { mtev_boolean extended_id = mtev_false; char uuid_str[256*3+37]; const char *v; char *hist_serial = NULL; char *hist_encode = NULL; struct timeval whence; ssize_t est, enc_est; whence.tv_sec = whence_s; whence.tv_usec = 0; if(!conf->histogram) return; SETUP_LOG(metrics, ); if(metrics_log) { v = mtev_log_stream_get_property(metrics_log, "extended_id"); if(v && !strcmp(v, "on")) extended_id = mtev_true; } uuid_str[0] = '\0'; if(extended_id) { strlcat(uuid_str, check->target, sizeof(uuid_str)-37); strlcat(uuid_str, "`", sizeof(uuid_str)-37); strlcat(uuid_str, check->module, sizeof(uuid_str)-37); strlcat(uuid_str, "`", sizeof(uuid_str)-37); strlcat(uuid_str, check->name, sizeof(uuid_str)-37); strlcat(uuid_str, "`", sizeof(uuid_str)-37); } uuid_unparse_lower(check->checkid, uuid_str + strlen(uuid_str)); #define SECPART(a) ((unsigned long)(a)->tv_sec) #define MSECPART(a) ((unsigned long)((a)->tv_usec / 1000)) est = hist_serialize_estimate(h); hist_serial = malloc(est); if(!hist_serial) { mtevL(noit_error, "malloc(%d) failed\n", (int)est); goto cleanup; } enc_est = ((est + 2)/3)*4; hist_encode = malloc(enc_est); if(!hist_encode) { mtevL(noit_error, "malloc(%d) failed\n", (int)enc_est); goto cleanup; } if(hist_serialize(h, hist_serial, est) != est) { mtevL(noit_error, "histogram serialization failure\n"); goto cleanup; } enc_est = mtev_b64_encode((unsigned char *)hist_serial, est, hist_encode, enc_est); if(enc_est < 0) { mtevL(noit_error, "base64 histogram encoding failure\n"); goto cleanup; } if(live_feed && check->feeds) { mtev_skiplist_node *curr, *next; curr = next = mtev_skiplist_getlist(check->feeds); while(curr) { const char *feed_name = (char *)curr->data; mtev_log_stream_t ls = mtev_log_stream_find(feed_name); mtev_skiplist_next(check->feeds, &next); if(!ls || mtev_log(ls, &whence, __FILE__, __LINE__, "H1\t%lu.%03lu\t%s\t%s\t%.*s\n", SECPART(&whence), MSECPART(&whence), uuid_str, metric_name, (int)enc_est, hist_encode)) noit_check_transient_remove_feed(check, feed_name); curr = next; } } if(!live_feed) { SETUP_LOG(metrics, goto cleanup); mtev_log(metrics_log, &whence, __FILE__, __LINE__, "H1\t%lu.%03lu\t%s\t%s\t%.*s\n", SECPART(&whence), MSECPART(&whence), uuid_str, metric_name, (int)enc_est, hist_encode); }