static enum http_rc_e action_status(struct req_args_s *args) { if (0 == strcasecmp("HEAD", args->rq->cmd)) return _reply_success_json(args, NULL); if (0 != strcasecmp("GET", args->rq->cmd)) return _reply_method_error(args); GString *gstr = g_string_sized_new (128); /* first, the stats about all the requests received */ GArray *array = network_server_stat_getall(args->rq->client->server); for (guint i=0; i<array->len ; ++i) { struct server_stat_s *st = &g_array_index (array, struct server_stat_s, i); g_string_append_printf (gstr, "%s = %"G_GUINT64_FORMAT"\n", g_quark_to_string (st->which), st->value); } g_array_free (array, TRUE); /* some stats about the internal cache */ struct hc_resolver_stats_s s = {0}; hc_resolver_info(resolver, &s); g_string_append_printf(gstr, "gauge cache.dir.count = %"G_GINT64_FORMAT"\n", s.csm0.count); g_string_append_printf(gstr, "gauge cache.dir.max = %u\n", s.csm0.max); g_string_append_printf(gstr, "gauge cache.dir.ttl = %lu\n", s.csm0.ttl); g_string_append_printf(gstr, "gauge cache.dir.clock = %lu\n", s.clock); g_string_append_printf(gstr, "gauge cache.srv.count = %"G_GINT64_FORMAT"\n", s.services.count); g_string_append_printf(gstr, "gauge cache.srv.max = %u\n", s.services.max); g_string_append_printf(gstr, "gauge cache.srv.ttl = %lu\n", s.services.ttl); g_string_append_printf(gstr, "gauge cache.srv.clock = %lu\n", s.clock); gint64 count_down = 0; SRV_DO(count_down = lru_tree_count(srv_down)); g_string_append_printf(gstr, "gauge down.srv = %"G_GINT64_FORMAT"\n", count_down); args->rp->set_body_gstr(gstr); args->rp->set_status(HTTP_CODE_OK, "OK"); args->rp->set_content_type("text/x-java-properties"); args->rp->finalize(); return HTTPRC_DONE; }
static enum http_rc_e action_cache (struct http_request_s *rq, struct http_reply_ctx_s *rp, struct req_uri_s *uri, const gchar *path) { struct cache_action_s { const gchar *method; const gchar *prefix; enum http_rc_e (*hook) (const struct cache_args_s * args); }; static struct cache_action_s dir_actions[] = { {"GET", "status/", action_cache_status}, {"POST", "flush/high/", action_cache_flush_high}, {"POST", "flush/low/", action_cache_flush_low}, {"POST", "set/ttl/high/", action_cache_set_ttl_high}, {"POST", "set/ttl/low/", action_cache_set_ttl_low}, {"POST", "set/max/high/", action_cache_set_max_high}, {"POST", "set/max/low/", action_cache_set_max_low}, {NULL, NULL, NULL} }; gboolean matched = FALSE; (void) uri; for (struct cache_action_s * pa = dir_actions; pa->prefix; ++pa) { if (!g_str_has_prefix (path, pa->prefix)) continue; matched = TRUE; if (0 != strcmp (rq->cmd, pa->method)) continue; struct cache_args_s args; memset (&args, 0, sizeof (args)); args.uri = path + strlen (pa->prefix); args.count = atoi (args.uri); args.rq = rq; args.rp = rp; return pa->hook (&args); } if (matched) return _reply_method_error (rp); return _reply_no_handler (rp); }