static struct MHD_Response * send_metric(struct brubeck_server *server, const char *url) { static const char *metric_types[] = { "gauge", "meter", "counter", "histogram", "timer", "internal" }; static const char *expire_status[] = { "disabled", "inactive", "active" }; struct brubeck_metric *metric = safe_lookup_metric( server, url + strlen("/metric/")); if (metric) { json_t *mj = json_pack("{s:s, s:s, s:i, s:s}", "key", metric->key, "type", metric_types[metric->type], #if METRIC_SHARD_SPECIFIER "shard", (int)metric->shard, #else "shard", 0, #endif "expire", expire_status[metric->expire] ); char *jsonr = json_dumps(mj, JSON_INDENT(4) | JSON_PRESERVE_ORDER); json_decref(mj); return MHD_create_response_from_data( strlen(jsonr), jsonr, 1, 0); } return NULL; }
static int send_metric(struct mg_connection *conn) { static const char *metric_types[] = { "gauge", "meter", "counter", "histogram", "timer", "internal" }; static const char *expire_status[] = { "disabled", "inactive", "active" }; struct brubeck_server *server = conn->server_param; struct brubeck_metric *metric = safe_lookup_metric( server, conn->uri + strlen("/metric/")); if (metric) { json_t *mj = json_pack("{s:s, s:s, s:i, s:s}", "key", metric->key, "type", metric_types[metric->type], #if METRIC_SHARD_SPECIFIER "shard", (int)metric->shard, #else "shard", 0, #endif "expire", expire_status[metric->expire] ); send_headers(conn); json_dump_callback(mj, &dump_json, (void *)conn, JSON_INDENT(4) | JSON_PRESERVE_ORDER); json_decref(mj); return MG_TRUE; } return MG_FALSE; }
static struct MHD_Response * expire_metric(struct brubeck_server *server, const char *url) { struct brubeck_metric *metric = safe_lookup_metric( server, url + strlen("/expire/")); if (metric) { metric->expire = BRUBECK_EXPIRE_DISABLED; return MHD_create_response_from_data( 0, "", 0, 0); } return NULL; }
static int expire_metric(struct mg_connection *conn) { struct brubeck_server *server = conn->server_param; struct brubeck_metric *metric = safe_lookup_metric( server, conn->uri + strlen("/expire/")); if (metric) { metric->expire = BRUBECK_EXPIRE_DISABLED; mg_send_status(conn, 200); mg_send_header(conn, "Connection", "close"); return MG_TRUE; } return MG_FALSE; }