root/src/stratcon_jlog_streamer.h

Revision 48e115ad8158970b1f83732d0301d0289f42c7fb, 3.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

first stab at noit connection metrics, refs #170

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _STRATCON_LOG_STREAMER_H
34 #define _STRATCON_LOG_STREAMER_H
35
36 #include "noit_conf.h"
37 #include "utils/noit_atomic.h"
38 #include "jlog/jlog.h"
39 #include <netinet/in.h>
40 #include <sys/un.h>
41 #include <arpa/inet.h>
42 #include "stratcon_datastore.h"
43
44 typedef struct noit_connection_ctx_t {
45   noit_atomic32_t refcnt;
46   union {
47     struct sockaddr remote;
48     struct sockaddr_un remote_un;
49     struct sockaddr_in remote_in;
50     struct sockaddr_in6 remote_in6;
51   } r;
52   socklen_t remote_len;
53   char *remote_str;
54   char *remote_cn;
55   u_int32_t current_backoff;
56   int wants_shutdown;
57   int wants_permanent_shutdown;
58   noit_hash_table *config;
59   noit_hash_table *sslconfig;
60   struct timeval last_connect;
61   eventer_t timeout_event;
62
63   eventer_func_t consumer_callback;
64   void (*consumer_free)(void *);
65   void *consumer_ctx;
66 } noit_connection_ctx_t;
67
68 typedef struct jlog_streamer_ctx_t {
69   u_int32_t jlog_feed_cmd;
70   int bytes_expected;
71   int bytes_read;
72   char *buffer;         /* These guys are for doing partial reads */
73
74   enum {
75     JLOG_STREAMER_WANT_INITIATE = 0,
76     JLOG_STREAMER_WANT_COUNT = 1,
77     JLOG_STREAMER_WANT_HEADER = 2,
78     JLOG_STREAMER_WANT_BODY = 3,
79     JLOG_STREAMER_IS_ASYNC = 4,
80     JLOG_STREAMER_WANT_CHKPT = 5,
81   } state;
82   int count;            /* Number of jlog messages we need to read */
83   struct {
84     jlog_id   chkpt;
85     u_int32_t tv_sec;
86     u_int32_t tv_usec;
87     u_int32_t message_len;
88   } header;
89
90   u_int64_t total_events;
91   u_int64_t total_bytes_read;
92
93   void (*push)(stratcon_datastore_op_t, struct sockaddr *, void *);
94 } jlog_streamer_ctx_t;
95
96 API_EXPORT(void)
97   stratcon_jlog_streamer_init(const char *toplevel);
98 API_EXPORT(void)
99   stratcon_jlog_streamer_reload(const char *toplevel);
100 API_EXPORT(int)
101   stratcon_jlog_recv_handler(eventer_t e, int mask, void *closure,
102                              struct timeval *now);
103 API_EXPORT(jlog_streamer_ctx_t *)
104   stratcon_jlog_streamer_ctx_alloc(void);
105 API_EXPORT(void)
106   jlog_streamer_ctx_free(void *cl);
107 API_EXPORT(void)
108   stratcon_streamer_connection(const char *toplevel, const char *destination,
109                                eventer_func_t handler,
110                                void *(*handler_alloc)(void), void *handler_ctx,
111                                void (*handler_free)(void *));
112
113 #endif
Note: See TracBrowser for help on using the browser.