root/src/noit_check.h

Revision c385b68fdd537ec15c1467e6c8541b32d3838bf6, 11.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 2 years ago)

Add lookup by ip/module.

Make the counters into a rate like statsd does.

  • 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 _NOIT_CHECK_H
34 #define _NOIT_CHECK_H
35
36 #include "noit_defines.h"
37
38 #include <uuid/uuid.h>
39 #include <netinet/in.h>
40
41 #include "eventer/eventer.h"
42 #include "utils/noit_hash.h"
43 #include "utils/noit_skiplist.h"
44 #include "utils/noit_hooks.h"
45 #include "noit_conf.h"
46 #include "noit_console.h"
47
48 /*
49  * Checks:
50  *  attrs:
51  *   UUID
52  *   host (target)
53  *   check (module)
54  *   name (identifying the check to the user if
55  *         multiple checks of the same module are specified)
56  *   config (params for the module)
57  *   period (ms)
58  *   timeout (ms)
59  *  transient:
60  *   eventer_t (fire)
61  *   stats_t [inprogress, last]
62  *   closure
63  */
64
65 #define NP_RUNNING   0x00000001
66 #define NP_KILLED    0x00000002
67 #define NP_DISABLED  0x00000004
68 #define NP_UNCONFIG  0x00000008
69 #define NP_TRANSIENT 0x00000010
70 #define NP_RESOLVE   0x00000020
71 #define NP_RESOLVED  0x00000040
72
73 #define NP_SUPPRESS_STATUS  0x00001000
74 #define NP_SUPPRESS_METRICS 0x00002000
75
76 #define NP_PREFER_IPV6   0x00004000
77 #define NP_SINGLE_RESOLVE 0x00008000
78
79 #define PREFER_IPV4 "prefer-ipv4"
80 #define PREFER_IPV6 "prefer-ipv6"
81 #define FORCE_IPV4  "force-ipv4"
82 #define FORCE_IPV6  "force-ipv6"
83
84 #define NP_UNKNOWN '0'             /* stats_t.{available,state} */
85 #define NP_AVAILABLE 'A'           /* stats_t.available */
86 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
87 #define NP_BAD 'B'                 /* stats_t.state */
88 #define NP_GOOD 'G'                /* stats_t.state */
89
90 typedef enum {
91   METRIC_GUESS = '0',
92   METRIC_INT32 = 'i',
93   METRIC_UINT32 = 'I',
94   METRIC_INT64 = 'l',
95   METRIC_UINT64 = 'L',
96   METRIC_DOUBLE = 'n',
97   METRIC_STRING = 's'
98 } metric_type_t;
99
100 typedef struct {
101   char *metric_name;
102   metric_type_t metric_type;
103   union {
104     double *n;
105     int32_t *i;
106     u_int32_t *I;
107     int64_t *l;
108     u_int64_t *L;
109     char *s;
110     void *vp; /* used for clever assignments */
111   } metric_value;
112 } metric_t;
113
114 typedef struct {
115   struct timeval whence;
116   int8_t available;
117   int8_t state;
118   u_int32_t duration;
119   char *status;
120   noit_hash_table metrics;
121 } stats_t;
122
123 typedef struct dep_list {
124   struct noit_check *check;
125   struct dep_list *next;
126 } dep_list_t;
127
128 typedef struct noit_check {
129   uuid_t checkid;
130   int8_t target_family;
131   union {
132     struct in_addr addr;
133     struct in6_addr addr6;
134   } target_addr;
135   char *target;
136   char *module;
137   char *name;
138   char *filterset;
139   noit_hash_table *config;
140   char *oncheck;               /* target`name of the check that fires us */
141   u_int32_t period;            /* period of checks in milliseconds */
142   u_int32_t timeout;           /* timeout of check in milliseconds */
143   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
144
145   dep_list_t *causal_checks;
146   eventer_t fire_event;
147   struct timeval last_fire_time;
148   struct {
149     stats_t current;
150     stats_t previous;
151   } stats;
152   u_int32_t generation;        /* This can roll, we don't care */
153   void *closure;
154
155   noit_skiplist *feeds;
156   char target_ip[INET6_ADDRSTRLEN];
157   void **module_metadata;
158   noit_hash_table **module_configs;
159   struct timeval initial_schedule_time;
160 } noit_check_t;
161
162 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
163 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
164 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
165 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
166 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
167 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
168 /* It is resolved if it is resolved or never needed to be resolved */
169 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
170 #define NOIT_CHECK_PREFER_V6(a) ((a)->flags & NP_PREFER_IPV6)
171 #define NOIT_CHECK_SINGLE_RESOLVE(a) ((a)->flags & NP_SINGLE_RESOLVE)
172
173 API_EXPORT(void) noit_poller_init();
174 API_EXPORT(u_int64_t) noit_check_completion_count();
175 API_EXPORT(int) noit_poller_check_count();
176 API_EXPORT(int) noit_poller_transient_check_count();
177 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
178 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
179 API_EXPORT(void) noit_poller_make_causal_map();
180
181 API_EXPORT(void)
182   noit_check_fake_last_check(noit_check_t *check,
183                              struct timeval *lc, struct timeval *_now);
184
185 API_EXPORT(int)
186   noit_poller_schedule(const char *target,
187                        const char *module,
188                        const char *name,
189                        const char *filterset,
190                        noit_hash_table *config,
191                        noit_hash_table **mconfig,
192                        u_int32_t period,
193                        u_int32_t timeout,
194                        const char *oncheck,
195                        int flags,
196                        uuid_t in,
197                        uuid_t out);
198
199 API_EXPORT(int)
200   noit_check_resolve(noit_check_t *check);
201
202 API_EXPORT(int)
203   noit_check_update(noit_check_t *new_check,
204                     const char *target,
205                     const char *name,
206                     const char *filterset,
207                     noit_hash_table *config,
208                     noit_hash_table **mconfig,
209                     u_int32_t period,
210                     u_int32_t timeout,
211                     const char *oncheck,
212                     int flags);
213
214 API_EXPORT(noit_boolean)
215   noit_check_is_valid_target(const char *str);
216
217 API_EXPORT(int)
218   noit_check_activate(noit_check_t *check);
219
220 API_EXPORT(int)
221   noit_poller_deschedule(uuid_t in);
222
223 API_EXPORT(noit_check_t *)
224   noit_poller_lookup(uuid_t in);
225
226 API_EXPORT(noit_check_t *)
227   noit_poller_lookup_by_name(char *target, char *name);
228
229 API_EXPORT(int)
230   noit_poller_lookup_by_ip_module(const char *ip, const char *mod,
231                                   noit_check_t **checks, int nchecks);
232
233 API_EXPORT(int)
234    noit_poller_target_do(const char *target, int (*f)(noit_check_t *, void *),
235                          void *closure);
236
237 API_EXPORT(int)
238   noit_check_xpath(char *xpath, int len,
239                    const char *base, const char *arg);
240
241 API_EXPORT(void)
242   noit_check_stats_clear(noit_check_t *check, stats_t *s);
243
244 struct _noit_module;
245 /* This if for modules (passive) than cannot be watched... */
246 API_EXPORT(void)
247   noit_check_passive_set_stats(noit_check_t *check,
248                                stats_t *newstate);
249 /* This is for normal (active) modules... */
250 API_EXPORT(void)
251   noit_check_set_stats(noit_check_t *check,
252                         stats_t *newstate);
253
254 API_EXPORT(metric_t *)
255   noit_stats_get_metric(noit_check_t *check, stats_t *, const char *);
256
257 API_EXPORT(void)
258   noit_stats_set_metric(noit_check_t *check,
259                         stats_t *, const char *, metric_type_t, const void *);
260
261 API_EXPORT(void)
262   noit_stats_set_metric_coerce(noit_check_t *check,
263                                stats_t *, const char *, metric_type_t,
264                                const char *);
265
266 API_EXPORT(void)
267   noit_stats_log_immediate_metric(noit_check_t *check,
268                                   const char *name, metric_type_t type,
269                                   void *value);
270
271 API_EXPORT(const char *)
272   noit_check_available_string(int16_t available);
273 API_EXPORT(const char *)
274   noit_check_state_string(int16_t state);
275 API_EXPORT(int)
276   noit_calc_rtype_flag(char *resolve_rtype);
277 API_EXPORT(int)
278   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
279 API_EXPORT(int)
280   noit_stats_snprint_metric(char *b, int l, metric_t *m);
281
282 API_EXPORT(noit_check_t *)
283   noit_check_clone(uuid_t in);
284 API_EXPORT(void)
285   noit_poller_free_check(noit_check_t *checker);
286 API_EXPORT(noit_check_t *)
287   noit_check_watch(uuid_t in, int period);
288 API_EXPORT(noit_check_t *)
289   noit_check_get_watch(uuid_t in, int period);
290 API_EXPORT(void)
291   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
292 API_EXPORT(void)
293   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
294
295 API_EXPORT(int)
296   noit_check_register_module(const char *);
297 API_EXPORT(int)
298   noit_check_registered_module_cnt();
299 API_EXPORT(const char *)
300   noit_check_registered_module(int);
301
302 API_EXPORT(void)
303   noit_check_set_module_metadata(noit_check_t *, int, void *, void (*freefunc)(void *));
304 API_EXPORT(void)
305   noit_check_set_module_config(noit_check_t *, int, noit_hash_table *);
306 API_EXPORT(void *)
307   noit_check_get_module_metadata(noit_check_t *, int);
308 API_EXPORT(noit_hash_table *)
309   noit_check_get_module_config(noit_check_t *, int);
310
311 /* These are from noit_check_log.c */
312 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
313 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
314 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
315 API_EXPORT(void) noit_check_log_bundle(noit_check_t *check);
316 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
317 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
318                                        struct timeval *whence, metric_t *m);
319 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
320                                               char *target, int target_len,
321                                               char *module, int module_len,
322                                               char *name, int name_len,
323                                               char *uuid, int uuid_len);
324
325
326 API_EXPORT(char *)
327   noit_console_check_opts(noit_console_closure_t ncct,
328                           noit_console_state_stack_t *stack,
329                           noit_console_state_t *dstate,
330                           int argc, char **argv, int idx);
331 API_EXPORT(char *)
332   noit_console_conf_check_opts(noit_console_closure_t ncct,
333                                noit_console_state_stack_t *stack,
334                                noit_console_state_t *dstate,
335                                int argc, char **argv, int idx);
336
337 API_EXPORT(void) check_slots_inc_tv(struct timeval *tv);
338 API_EXPORT(void) check_slots_dec_tv(struct timeval *tv);
339
340 NOIT_HOOK_PROTO(check_stats_set_metric,
341                 (noit_check_t *check, stats_t *stats, metric_t *m),
342                 void *, closure,
343                 (void *closure, noit_check_t *check, stats_t *stats, metric_t *m))
344
345 NOIT_HOOK_PROTO(check_passive_log_stats,
346                 (noit_check_t *check),
347                 void *, closure,
348                 (void *closure, noit_check_t *check))
349
350 NOIT_HOOK_PROTO(check_log_stats,
351                 (noit_check_t *check),
352                 void *, closure,
353                 (void *closure, noit_check_t *check))
354
355 #endif
Note: See TracBrowser for help on using the browser.