Changeset 8504a3bc4b5a70ad76874cc27cff73a2308a0543

Show
Ignore:
Timestamp:
09/23/09 01:56:38 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253670998 +0000
git-parent:

[a1c8f68c6a11759d58d1e16bd9f017d86710f904]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1253670998 +0000
Message:

export noit info over REST

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/Makefile.in

    r3c56016 r8504a3b  
    4747        noit_console_complete.o noit_xml.o \ 
    4848        noit_conf.o noit_http.o noit_rest.o noit_tokenizer.o \ 
     49        noit_capabilities_listener.o \ 
    4950        stratcon_realtime_http.o \ 
    5051        stratcon_jlog_streamer.o stratcon_datastore.o \ 
  • src/noit_rest.c

    r3c56016 r8504a3b  
    322322} 
    323323void noit_http_rest_init() { 
    324   eventer_name_callback("noit_wite_rest_api/1.0", noit_http_rest_handler); 
     324  eventer_name_callback("noit_wire_rest_api/1.0", noit_http_rest_handler); 
    325325  eventer_name_callback("http_rest_api", noit_http_rest_raw_handler); 
    326326  noit_control_dispatch_delegate(noit_control_dispatch, 
  • src/stratcon.conf.in

    ra1c8f68 r8504a3b  
    3131  </noits> 
    3232 
    33   <iep disable="false"> <!-- false the default --> 
     33  <iep disabled="false"> <!-- false the default --> 
    3434    <start directory="%iepdbdir%" 
    3535           command="%iepbindir%/run-iep.sh" /> 
     
    113113 
    114114  <listeners> 
    115   <consoles type="noit_console"> 
    116     <listener address="/tmp/stratcon"> 
    117       <config><line_protocol>telnet</line_protocol></config> 
    118     </listener> 
    119   </consoles> 
    120   <realtime type="http_rest_api"> 
    121     <listener address="*" port="80"> 
    122       <config> 
    123         <hostname>stratcon.noit.example.com</hostname> 
    124         <document_domain>noit.example.com</document_domain> 
    125       </config> 
    126     </listener> 
    127   </realtime> 
     115    <sslconfig> 
     116      <key_file>%sysconfdir%/%PKIPREFIX%stratcon.key</key_file> 
     117      <certificate_file>%sysconfdir%/%PKIPREFIX%stratcon.crt</certificate_file> 
     118      <ca_chain>%sysconfdir%/%PKIPREFIX%ca.crt</ca_chain> 
     119    </sslconfig> 
     120    <consoles type="noit_console"> 
     121      <listener address="/tmp/stratcon"> 
     122        <config><line_protocol>telnet</line_protocol></config> 
     123      </listener> 
     124    </consoles> 
     125    <realtime type="http_rest_api"> 
     126      <listener address="*" port="80"> 
     127        <config> 
     128          <hostname>stratcon.noit.example.com</hostname> 
     129          <document_domain>noit.example.com</document_domain> 
     130        </config> 
     131      </listener> 
     132    </realtime> 
     133    <listener type="control_dispatch" address="*" port="43191" ssl="on" /> 
    128134  </listeners> 
    129135 
  • src/stratcon_jlog_streamer.c

    rd9fd356 r8504a3b  
    3737#include "utils/noit_log.h" 
    3838#include "noit_jlog_listener.h" 
     39#include "noit_rest.h" 
    3940#include "stratcon_datastore.h" 
    4041#include "stratcon_jlog_streamer.h" 
     
    703704    noit_connection_ctx_deref(ctx[i]); 
    704705  } 
     706  free(ctx); 
    705707  return 0; 
    706708} 
     
    719721} 
    720722 
     723static int 
     724rest_show_noits(noit_http_rest_closure_t *restc, 
     725                int npats, char **pats) { 
     726  xmlDocPtr doc; 
     727  xmlNodePtr root; 
     728  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     729  uuid_t key_id; 
     730  int klen, n = 0, i; 
     731  void *vconn; 
     732  noit_connection_ctx_t **ctxs; 
     733  struct timeval now, diff; 
     734  gettimeofday(&now, NULL); 
     735 
     736  pthread_mutex_lock(&noits_lock); 
     737  ctxs = malloc(sizeof(*ctxs) * noits.size); 
     738  while(noit_hash_next(&noits, &iter, (const char **)key_id, &klen, 
     739                       &vconn)) { 
     740    ctxs[n] = (noit_connection_ctx_t *)vconn; 
     741    noit_atomic_inc32(&ctxs[n]->refcnt); 
     742    n++; 
     743  } 
     744  pthread_mutex_unlock(&noits_lock); 
     745  qsort(ctxs, n, sizeof(*ctxs), remote_str_sort); 
     746 
     747  doc = xmlNewDoc((xmlChar *)"1.0"); 
     748  root = xmlNewDocNode(doc, NULL, (xmlChar *)"noits", NULL); 
     749  xmlDocSetRootElement(doc, root); 
     750  for(i=0; i<n; i++) { 
     751    char buff[256], *feedtype = "unknown", *state = "unknown"; 
     752    xmlNodePtr node; 
     753    noit_connection_ctx_t *ctx = ctxs[i]; 
     754    jlog_streamer_ctx_t *jctx = ctx->consumer_ctx; 
     755 
     756    node = xmlNewNode(NULL, (xmlChar *)"noit"); 
     757    snprintf(buff, sizeof(buff), "%llu.%06d", 
     758             (long long unsigned)ctx->last_connect.tv_sec, 
     759             (int)ctx->last_connect.tv_usec); 
     760    xmlSetProp(node, (xmlChar *)"last_connect", (xmlChar *)buff); 
     761    xmlSetProp(node, (xmlChar *)"state", ctx->timeout_event ? 
     762               (xmlChar *)"disconnected" : (xmlChar *)"connected"); 
     763    if(ctx->timeout_event) { 
     764      sub_timeval(now, ctx->timeout_event->whence, &diff); 
     765      snprintf(buff, sizeof(buff), "%llu.%06d", 
     766               (long long unsigned)diff.tv_sec, (int)diff.tv_usec); 
     767      xmlSetProp(node, (xmlChar *)"next_attempt", (xmlChar *)buff); 
     768    } 
     769    xmlSetProp(node, (xmlChar *)"remote", (xmlChar *)ctx->remote_str); 
     770    if(ctx->remote_cn) 
     771      xmlSetProp(node, (xmlChar *)"remote_cn", (xmlChar *)ctx->remote_cn); 
     772 
     773    switch(ntohl(jctx->jlog_feed_cmd)) { 
     774      case NOIT_JLOG_DATA_FEED: feedtype = "durable/storage"; break; 
     775      case NOIT_JLOG_DATA_TEMP_FEED: feedtype = "transient/iep"; break; 
     776    } 
     777    xmlSetProp(node, (xmlChar *)"type", (xmlChar *)feedtype); 
     778    switch(jctx->state) { 
     779      case JLOG_STREAMER_WANT_INITIATE: state = "initiate"; break; 
     780      case JLOG_STREAMER_WANT_COUNT: state = "waiting for next batch"; break; 
     781      case JLOG_STREAMER_WANT_HEADER: state = "reading header"; break; 
     782      case JLOG_STREAMER_WANT_BODY: state = "reading body"; break; 
     783      case JLOG_STREAMER_IS_ASYNC: state = "asynchronously processing"; break; 
     784      case JLOG_STREAMER_WANT_CHKPT: state = "checkpointing"; break; 
     785    } 
     786    xmlSetProp(node, (xmlChar *)"state", (xmlChar *)state); 
     787    snprintf(buff, sizeof(buff), "%08x:%08x",  
     788             jctx->header.chkpt.log, jctx->header.chkpt.marker); 
     789    xmlSetProp(node, (xmlChar *)"checkpoint", (xmlChar *)buff); 
     790    snprintf(buff, sizeof(buff), "%lu", jctx->total_events); 
     791    xmlSetProp(node, (xmlChar *)"session_events", (xmlChar *)buff); 
     792    snprintf(buff, sizeof(buff), "%lu", jctx->total_bytes_read); 
     793    xmlSetProp(node, (xmlChar *)"session_bytes", (xmlChar *)buff); 
     794 
     795    sub_timeval(now, ctx->last_connect, &diff); 
     796    snprintf(buff, sizeof(buff), "%llu.%06d", 
     797             (long long unsigned)diff.tv_sec, (int)diff.tv_usec); 
     798    xmlSetProp(node, (xmlChar *)"session_duration", (xmlChar *)buff); 
     799 
     800    xmlAddChild(root, node); 
     801    noit_connection_ctx_deref(ctx); 
     802  } 
     803  free(ctxs); 
     804 
     805  noit_http_response_ok(restc->http_ctx, "text/xml"); 
     806  noit_http_response_xml(restc->http_ctx, doc); 
     807  noit_http_response_end(restc->http_ctx); 
     808  xmlFreeDoc(doc); 
     809  return 0; 
     810} 
    721811void 
    722812stratcon_jlog_streamer_init(const char *toplevel) { 
     
    732822  register_console_streamer_commands(); 
    733823  stratcon_jlog_streamer_reload(toplevel); 
    734 
     824  assert(noit_http_rest_register( 
     825    "GET", "/noits/", "^show$", rest_show_noits 
     826  ) == 0); 
     827
  • src/stratcond.c

    r3c56016 r8504a3b  
    5050#include "noit_conf.h" 
    5151#include "noit_rest.h" 
     52#include "noit_capabilities_listener.h" 
    5253#include "stratcon_jlog_streamer.h" 
    5354#include "stratcon_datastore.h" 
     
    173174  noit_http_rest_init(); 
    174175  stratcon_realtime_http_init(APPNAME); 
     176  noit_capabilities_listener_init(); 
    175177  noit_listener_init(APPNAME); 
    176178