root/src/noit_check.h

Revision 397f56dda527bb85b65aa7a4ab60c1f289361565, 11.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

The spread of the checks across time was bunched to the beginning of
the second for no sound reason. More dastardly, every DNS based check
could tend to coallesce over time around the point of a DNS timeout.
Now checks stay true to their originally set period of their initial
schedule time.

This can be seen a runtime through the console command: "show timing_slots"

DNS-based checks still suffer from an immediate fire "at boot".

  • 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_target_do(char *target, int (*f)(noit_check_t *, void *),
231                          void *closure);
232
233 API_EXPORT(int)
234   noit_check_xpath(char *xpath, int len,
235                    const char *base, const char *arg);
236
237 API_EXPORT(void)
238   noit_check_stats_clear(noit_check_t *check, stats_t *s);
239
240 struct _noit_module;
241 /* This if for modules (passive) than cannot be watched... */
242 API_EXPORT(void)
243   noit_check_passive_set_stats(noit_check_t *check,
244                                stats_t *newstate);
245 /* This is for normal (active) modules... */
246 API_EXPORT(void)
247   noit_check_set_stats(noit_check_t *check,
248                         stats_t *newstate);
249
250 API_EXPORT(void)
251   noit_stats_set_metric(noit_check_t *check,
252                         stats_t *, const char *, metric_type_t, const void *);
253
254 API_EXPORT(void)
255   noit_stats_set_metric_coerce(noit_check_t *check,
256                                stats_t *, const char *, metric_type_t,
257                                const char *);
258
259 API_EXPORT(void)
260   noit_stats_log_immediate_metric(noit_check_t *check,
261                                   const char *name, metric_type_t type,
262                                   void *value);
263
264 API_EXPORT(const char *)
265   noit_check_available_string(int16_t available);
266 API_EXPORT(const char *)
267   noit_check_state_string(int16_t state);
268 API_EXPORT(int)
269   noit_calc_rtype_flag(char *resolve_rtype);
270 API_EXPORT(int)
271   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
272 API_EXPORT(int)
273   noit_stats_snprint_metric(char *b, int l, metric_t *m);
274
275 API_EXPORT(noit_check_t *)
276   noit_check_clone(uuid_t in);
277 API_EXPORT(void)
278   noit_poller_free_check(noit_check_t *checker);
279 API_EXPORT(noit_check_t *)
280   noit_check_watch(uuid_t in, int period);
281 API_EXPORT(noit_check_t *)
282   noit_check_get_watch(uuid_t in, int period);
283 API_EXPORT(void)
284   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
285 API_EXPORT(void)
286   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
287
288 API_EXPORT(int)
289   noit_check_register_module(const char *);
290 API_EXPORT(int)
291   noit_check_registered_module_cnt();
292 API_EXPORT(const char *)
293   noit_check_registered_module(int);
294
295 API_EXPORT(void)
296   noit_check_set_module_metadata(noit_check_t *, int, void *, void (*freefunc)(void *));
297 API_EXPORT(void)
298   noit_check_set_module_config(noit_check_t *, int, noit_hash_table *);
299 API_EXPORT(void *)
300   noit_check_get_module_metadata(noit_check_t *, int);
301 API_EXPORT(noit_hash_table *)
302   noit_check_get_module_config(noit_check_t *, int);
303
304 /* These are from noit_check_log.c */
305 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
306 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
307 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
308 API_EXPORT(void) noit_check_log_bundle(noit_check_t *check);
309 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
310 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
311                                        struct timeval *whence, metric_t *m);
312 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
313                                               char *target, int target_len,
314                                               char *module, int module_len,
315                                               char *name, int name_len,
316                                               char *uuid, int uuid_len);
317
318
319 API_EXPORT(char *)
320   noit_console_check_opts(noit_console_closure_t ncct,
321                           noit_console_state_stack_t *stack,
322                           noit_console_state_t *dstate,
323                           int argc, char **argv, int idx);
324 API_EXPORT(char *)
325   noit_console_conf_check_opts(noit_console_closure_t ncct,
326                                noit_console_state_stack_t *stack,
327                                noit_console_state_t *dstate,
328                                int argc, char **argv, int idx);
329
330 API_EXPORT(void) check_slots_inc_tv(struct timeval *tv);
331 API_EXPORT(void) check_slots_dec_tv(struct timeval *tv);
332
333 NOIT_HOOK_PROTO(check_stats_set_metric,
334                 (noit_check_t *check, stats_t *stats, metric_t *m),
335                 void *, closure,
336                 (void *closure, noit_check_t *check, stats_t *stats, metric_t *m))
337
338 NOIT_HOOK_PROTO(check_passive_log_stats,
339                 (noit_check_t *check),
340                 void *, closure,
341                 (void *closure, noit_check_t *check))
342
343 NOIT_HOOK_PROTO(check_log_stats,
344                 (noit_check_t *check),
345                 void *, closure,
346                 (void *closure, noit_check_t *check))
347
348 #endif
Note: See TracBrowser for help on using the browser.