#include "settings.h"
#include "client.h"
+#ifdef HAVE_MALLINFO
+#include <malloc.h>
+
+void print_meminfo(WRBUF wrbuf) {
+
+ struct mallinfo minfo;
+ minfo = mallinfo();
+ wrbuf_printf(wrbuf, " <memory>\n"
+ " <arena>%d</arena>\n"
+ " <uordblks>%d</uordblks>\n"
+ " <fordblks>%d</fordblks>\n"
+ " <ordblks>%d</ordblks>\n"
+ " <keepcost>%d</keepcost>\n"
+ " <hblks>%d</hblks>\n"
+ " <hblkhd>%d</hblkhd>\n"
+ " <virt>%d</virt>\n"
+ " <virtuse>%d</virtuse>\n"
+ " </memory>\n",
+ minfo.arena, minfo.uordblks, minfo.fordblks,minfo.ordblks, minfo.keepcost, minfo.hblks, minfo.hblkhd, minfo.arena + minfo.hblkhd, minfo.uordblks + minfo.hblkhd);
+
+}
+#else
+#define print_meminfo(x)
+#endif
+
+
// Update this when the protocol changes
#define PAZPAR2_PROTOCOL_VERSION "1"
unsigned int res;
seq++;
- if (global_parameters.debug_mode)
+ if (global_parameters.predictable_sessions)
res = seq;
else
{
static void cmd_exit(struct http_channel *c)
{
+ char buf[1024];
+ struct http_response *rs = c->response;
yaz_log(YLOG_WARN, "exit");
+ sprintf(buf, HTTP_COMMAND_RESPONSE_PREFIX "<exit><status>OK</status></exit>");
+ rs->payload = nmem_strdup(c->nmem, buf);
+ http_send_response(c);
http_close_server(c->server);
}
size_t session_get_memory_status(struct session *session);
-static void cmd_session_status(struct http_channel *c)
+static void session_status(struct http_channel *c, struct http_session *s)
{
+ size_t session_nmem;
+ wrbuf_printf(c->wrbuf, "<http_count>%u</http_count>\n", s->activity_counter);
+ wrbuf_printf(c->wrbuf, "<http_nmem>%zu</http_nmem>\n", nmem_total(s->nmem) );
+ session_nmem = session_get_memory_status(s->psession);
+ wrbuf_printf(c->wrbuf, "<session_nmem>%zu</session_nmem>\n", session_nmem);
+}
+
+static void cmd_session_status(struct http_channel *c) {
struct http_response *rs = c->response;
struct http_session *s = locate_session(c);
- size_t session_nmem;
if (!s)
return;
wrbuf_rewind(c->wrbuf);
wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "<sessionstatus><status>OK</status>\n");
- wrbuf_printf(c->wrbuf, "<http_count>%u</http_count>\n", s->activity_counter);
- wrbuf_printf(c->wrbuf, "<http_nmem>%zu</http_nmem>\n", nmem_total(s->nmem) );
-
- session_nmem = session_get_memory_status(s->psession);
- wrbuf_printf(c->wrbuf, "<session_nmem>%zu</session_nmem>\n", session_nmem);
-
+ session_status(c, s);
wrbuf_puts(c->wrbuf, "</sessionstatus>\n");
rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
http_send_response(c);
int sessions_count(void);
int clients_count(void);
+#ifdef HAVE_RESULTSETS_COUNT
int resultsets_count(void);
+#else
+#define resultsets_count() 0
+#endif
static void cmd_server_status(struct http_channel *c)
{
int clients = clients_count();
int resultsets = resultsets_count();
wrbuf_rewind(c->wrbuf);
- wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "<server-status><status>OK</status>\n");
- wrbuf_printf(c->wrbuf, "Sessions %u Clients: %u Resultsets: %u\n</server-status>\n", sessions, clients, resultsets);
+ wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "<server-status>\n");
+ wrbuf_printf(c->wrbuf, " <sessions>%u</sessions>\n", sessions);
+ wrbuf_printf(c->wrbuf, " <clients>%u</clients>\n", clients);
+ /* Only works if yaz has been compiled with enabling of this */
+ wrbuf_printf(c->wrbuf, " <resultsets>%u</resultsets>\n",resultsets);
+ print_meminfo(c->wrbuf);
+
+/* TODO add all sessions status */
+/* http_sessions_t http_sessions = c->http_sessions; */
+/* struct http_session *p; */
+/*
+ yaz_mutex_enter(http_sessions->mutex);
+ for (p = http_sessions->session_list; p; p = p->next) {
+ p->activity_counter++;
+ wrbuf_puts(c->wrbuf, "<session-status>\n");
+ wrbuf_printf(c->wrbuf, "<id>%s</id>\n", p->session_id);
+ yaz_mutex_leave(http_sessions->mutex);
+ session_status(c, p);
+ wrbuf_puts(c->wrbuf, "</session-status>\n");
+ yaz_mutex_enter(http_sessions->mutex);
+ p->activity_counter--;
+ }
+ yaz_mutex_leave(http_sessions->mutex);
+*/
+ wrbuf_puts(c->wrbuf, "</server-status>\n");
rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
http_send_response(c);
+ xmalloc_trav(0);
}
-
static void cmd_bytarget(struct http_channel *c)
{
struct http_response *rs = c->response;
if (settings && *settings == '1')
{
wrbuf_puts(c->wrbuf, "<settings>\n");
- wrbuf_puts(c->wrbuf, wrbuf_cstr(ht[i].settings_xml));
+ wrbuf_puts(c->wrbuf, ht[i].settings_xml);
wrbuf_puts(c->wrbuf, "</settings>\n");
}
wrbuf_puts(c->wrbuf, "</target>");
- wrbuf_destroy(ht[i].settings_xml);
}
wrbuf_puts(c->wrbuf, "</bytarget>");
wrbuf_rewind(c->wrbuf);
wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "<info>\n");
wrbuf_puts(c->wrbuf, " <version>\n");
- wrbuf_puts(c->wrbuf, "<pazpar2");
+ wrbuf_puts(c->wrbuf, " <pazpar2");
#ifdef PAZPAR2_VERSION_SHA1
wrbuf_printf(c->wrbuf, " sha1=\"%s\"", PAZPAR2_VERSION_SHA1);
#endif
{ "search", cmd_search },
{ "termlist", cmd_termlist },
{ "exit", cmd_exit },
- { "sessionstatus", cmd_session_status },
- { "serverstatus", cmd_server_status },
+ { "session-status", cmd_session_status },
+ { "server-status", cmd_server_status },
{ "ping", cmd_ping },
{ "record", cmd_record },
{ "info", cmd_info },