root/src/noit_check.h

Revision c074ec5eb4f7824656223e5305f90f92c2d34f33, 13.5 kB (checked in by Philip Maddox <pmaddox@circonus.com>, 5 months ago)

Revert "use a 32bit counter until the issue can be tracked down."

This reverts commit fd488eda0a7dc25673299ce80c091454f891883f.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  * Copyright (c) 2013, Circonus, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above
13  *       copyright notice, this list of conditions and the following
14  *       disclaimer in the documentation and/or other materials provided
15  *       with the distribution.
16  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
17  *       of its contributors may be used to endorse or promote products
18  *       derived from this software without specific prior written
19  *       permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _NOIT_CHECK_H
35 #define _NOIT_CHECK_H
36
37 #include "noit_defines.h"
38
39 #include <uuid/uuid.h>
40 #include <netinet/in.h>
41
42 #include "eventer/eventer.h"
43 #include "utils/noit_hash.h"
44 #include "utils/noit_skiplist.h"
45 #include "utils/noit_hooks.h"
46 #include "noit_conf.h"
47 #include "noit_console.h"
48
49 /*
50  * Checks:
51  *  attrs:
52  *   UUID
53  *   host (target)
54  *   check (module)
55  *   name (identifying the check to the user if
56  *         multiple checks of the same module are specified)
57  *   config (params for the module)
58  *   period (ms)
59  *   timeout (ms)
60  *  transient:
61  *   eventer_t (fire)
62  *   stats_t [inprogress, current, previous]
63  *   closure
64  */
65
66 /* The check is currently in-flight (running) */
67 #define NP_RUNNING               0x00000001
68 /* The check has been killed by the scheduling system */
69 #define NP_KILLED                0x00000002
70 /* The check is disable and should not be run */
71 #define NP_DISABLED              0x00000004
72 /* The check is not sufficiently configured to operate */
73 #define NP_UNCONFIG              0x00000008
74 /* The check is a transient copy of another check */
75 #define NP_TRANSIENT             0x00000010
76 /* The check requires name service resolution */
77 #define NP_RESOLVE               0x00000020
78 /* Name service resolution has been compelted for the check */
79 #define NP_RESOLVED              0x00000040
80 /* This check should have 'S' lines suppressed from logging */
81 #define NP_SUPPRESS_STATUS       0x00001000
82 /* This check should have 'M' lines suppressed from logging */
83 #define NP_SUPPRESS_METRICS      0x00002000
84 /* The check should lookup IPv6 records before IPv4 */
85 #define NP_PREFER_IPV6           0x00004000
86 /* Do no fallback to IPv6 from IPv4 and vice versa */
87 #define NP_SINGLE_RESOLVE        0x00008000
88 /* Indicates that the check is receiving data passively
89  * and it does not do anything during invocation to collect metrics
90  */
91 #define NP_PASSIVE_COLLECTION    0x00010000
92
93 #define PREFER_IPV4 "prefer-ipv4"
94 #define PREFER_IPV6 "prefer-ipv6"
95 #define FORCE_IPV4  "force-ipv4"
96 #define FORCE_IPV6  "force-ipv6"
97
98 #define NP_UNKNOWN '0'             /* stats_t.{available,state} */
99 #define NP_AVAILABLE 'A'           /* stats_t.available */
100 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
101 #define NP_BAD 'B'                 /* stats_t.state */
102 #define NP_GOOD 'G'                /* stats_t.state */
103
104 typedef enum {
105   METRIC_GUESS = '0',
106   METRIC_INT32 = 'i',
107   METRIC_UINT32 = 'I',
108   METRIC_INT64 = 'l',
109   METRIC_UINT64 = 'L',
110   METRIC_DOUBLE = 'n',
111   METRIC_STRING = 's'
112 } metric_type_t;
113
114 typedef struct {
115   char *metric_name;
116   metric_type_t metric_type;
117   union {
118     double *n;
119     int32_t *i;
120     u_int32_t *I;
121     int64_t *l;
122     u_int64_t *L;
123     char *s;
124     void *vp; /* used for clever assignments */
125   } metric_value;
126 } metric_t;
127
128 typedef struct {
129   struct timeval whence;
130   int8_t available;
131   int8_t state;
132   u_int32_t duration;
133   char *status;
134   noit_hash_table metrics;
135 } stats_t;
136
137 typedef struct dep_list {
138   struct noit_check *check;
139   struct dep_list *next;
140 } dep_list_t;
141
142 typedef struct noit_check {
143   uuid_t checkid;
144   int8_t target_family;
145   union {
146     struct in_addr addr;
147     struct in6_addr addr6;
148   } target_addr;
149   char *target;
150   char *module;
151   char *name;
152   char *filterset;
153   noit_hash_table *config;
154   char *oncheck;               /* target`name of the check that fires us */
155   u_int32_t period;            /* period of checks in milliseconds */
156   u_int32_t timeout;           /* timeout of check in milliseconds */
157   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
158
159   dep_list_t *causal_checks;
160   eventer_t fire_event;
161   struct timeval last_fire_time;
162   struct {
163     stats_t inprogress;
164     stats_t current;
165     stats_t previous;
166   } stats;
167   u_int32_t generation;        /* This can roll, we don't care */
168   void *closure;
169
170   noit_skiplist *feeds;
171   char target_ip[INET6_ADDRSTRLEN];
172   void **module_metadata;
173   noit_hash_table **module_configs;
174   struct timeval initial_schedule_time;
175 } noit_check_t;
176
177 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
178 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
179 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
180 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
181 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
182 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
183 /* It is resolved if it is resolved or never needed to be resolved */
184 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
185 #define NOIT_CHECK_PREFER_V6(a) ((a)->flags & NP_PREFER_IPV6)
186 #define NOIT_CHECK_SINGLE_RESOLVE(a) ((a)->flags & NP_SINGLE_RESOLVE)
187
188 API_EXPORT(void) noit_poller_init();
189 API_EXPORT(u_int64_t) noit_check_completion_count();
190 API_EXPORT(u_int64_t) noit_check_metric_count();
191 API_EXPORT(void) noit_check_metric_count_add(int);
192 API_EXPORT(int) noit_poller_check_count();
193 API_EXPORT(int) noit_poller_transient_check_count();
194 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
195 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
196 API_EXPORT(void) noit_poller_make_causal_map();
197
198 API_EXPORT(void)
199   noit_check_fake_last_check(noit_check_t *check,
200                              struct timeval *lc, struct timeval *_now);
201
202 API_EXPORT(int)
203   noit_poller_schedule(const char *target,
204                        const char *module,
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                        uuid_t in,
214                        uuid_t out);
215
216 API_EXPORT(int)
217   noit_check_resolve(noit_check_t *check);
218
219 API_EXPORT(int)
220   noit_check_update(noit_check_t *new_check,
221                     const char *target,
222                     const char *name,
223                     const char *filterset,
224                     noit_hash_table *config,
225                     noit_hash_table **mconfig,
226                     u_int32_t period,
227                     u_int32_t timeout,
228                     const char *oncheck,
229                     int flags);
230
231 API_EXPORT(noit_boolean)
232   noit_check_is_valid_target(const char *str);
233
234 API_EXPORT(int)
235   noit_check_activate(noit_check_t *check);
236
237 API_EXPORT(int)
238   noit_poller_deschedule(uuid_t in);
239
240 API_EXPORT(noit_check_t *)
241   noit_poller_lookup(uuid_t in);
242
243 API_EXPORT(noit_check_t *)
244   noit_poller_lookup_by_name(char *target, char *name);
245
246 API_EXPORT(int)
247   noit_poller_lookup_by_ip_module(const char *ip, const char *mod,
248                                   noit_check_t **checks, int nchecks);
249
250 API_EXPORT(int)
251    noit_poller_target_ip_do(const char *target,
252                             int (*f)(noit_check_t *, void *),
253                             void *closure);
254
255 API_EXPORT(int)
256    noit_poller_target_do(const char *target,
257                          int (*f)(noit_check_t *, void *),
258                          void *closure);
259
260 API_EXPORT(int)
261    noit_poller_do(int (*f)(noit_check_t *, void *),
262                   void *closure);
263
264 API_EXPORT(int)
265   noit_check_xpath(char *xpath, int len,
266                    const char *base, const char *arg);
267
268 API_EXPORT(void)
269   noit_check_stats_clear(noit_check_t *check, stats_t *s);
270
271 struct _noit_module;
272 /* This if for modules (passive) than cannot be watched... */
273 API_EXPORT(void)
274   noit_check_passive_set_stats(noit_check_t *check,
275                                stats_t *newstate);
276 /* This is for normal (active) modules... */
277 API_EXPORT(void)
278   noit_check_set_stats(noit_check_t *check,
279                         stats_t *newstate);
280
281 API_EXPORT(metric_t *)
282   noit_stats_get_metric(noit_check_t *check, stats_t *, const char *);
283
284 API_EXPORT(void)
285   noit_stats_set_metric(noit_check_t *check,
286                         stats_t *, const char *, metric_type_t, const void *);
287
288 API_EXPORT(void)
289   noit_stats_set_metric_coerce(noit_check_t *check,
290                                stats_t *, const char *, metric_type_t,
291                                const char *);
292
293 API_EXPORT(void)
294   noit_stats_log_immediate_metric(noit_check_t *check,
295                                   const char *name, metric_type_t type,
296                                   void *value);
297
298 API_EXPORT(const char *)
299   noit_check_available_string(int16_t available);
300 API_EXPORT(const char *)
301   noit_check_state_string(int16_t state);
302 API_EXPORT(int)
303   noit_calc_rtype_flag(char *resolve_rtype);
304 API_EXPORT(int)
305   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
306 API_EXPORT(int)
307   noit_stats_snprint_metric(char *b, int l, metric_t *m);
308
309 API_EXPORT(noit_check_t *)
310   noit_check_clone(uuid_t in);
311 API_EXPORT(void)
312   noit_poller_free_check(noit_check_t *checker);
313 API_EXPORT(noit_check_t *)
314   noit_check_watch(uuid_t in, int period);
315 API_EXPORT(noit_check_t *)
316   noit_check_get_watch(uuid_t in, int period);
317 API_EXPORT(void)
318   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
319 API_EXPORT(void)
320   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
321
322 API_EXPORT(int)
323   noit_check_register_module(const char *);
324 API_EXPORT(int)
325   noit_check_registered_module_cnt();
326 API_EXPORT(const char *)
327   noit_check_registered_module(int);
328
329 API_EXPORT(void)
330   noit_check_set_module_metadata(noit_check_t *, int, void *, void (*freefunc)(void *));
331 API_EXPORT(void)
332   noit_check_set_module_config(noit_check_t *, int, noit_hash_table *);
333 API_EXPORT(void *)
334   noit_check_get_module_metadata(noit_check_t *, int);
335 API_EXPORT(noit_hash_table *)
336   noit_check_get_module_config(noit_check_t *, int);
337
338 /* These are from noit_check_log.c */
339 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
340 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
341 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
342 API_EXPORT(void) noit_check_log_bundle(noit_check_t *check);
343 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
344 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
345                                        struct timeval *whence, metric_t *m);
346 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
347                                               char *target, int target_len,
348                                               char *module, int module_len,
349                                               char *name, int name_len,
350                                               char *uuid, int uuid_len);
351
352
353 API_EXPORT(char *)
354   noit_console_check_opts(noit_console_closure_t ncct,
355                           noit_console_state_stack_t *stack,
356                           noit_console_state_t *dstate,
357                           int argc, char **argv, int idx);
358 API_EXPORT(char *)
359   noit_console_conf_check_opts(noit_console_closure_t ncct,
360                                noit_console_state_stack_t *stack,
361                                noit_console_state_t *dstate,
362                                int argc, char **argv, int idx);
363
364 API_EXPORT(void) check_slots_inc_tv(struct timeval *tv);
365 API_EXPORT(void) check_slots_dec_tv(struct timeval *tv);
366
367 NOIT_HOOK_PROTO(check_stats_set_metric,
368                 (noit_check_t *check, stats_t *stats, metric_t *m),
369                 void *, closure,
370                 (void *closure, noit_check_t *check, stats_t *stats, metric_t *m))
371
372 NOIT_HOOK_PROTO(check_stats_set_metric_coerce,
373                 (noit_check_t *check, stats_t *stats, const char *name,
374                  metric_type_t type, const char *v, noit_boolean success),
375                 void *, closure,
376                 (void *closure, noit_check_t *check, stats_t *stats, const char *name,
377                  metric_type_t type, const char *v, noit_boolean success))
378
379 NOIT_HOOK_PROTO(check_passive_log_stats,
380                 (noit_check_t *check),
381                 void *, closure,
382                 (void *closure, noit_check_t *check))
383
384 NOIT_HOOK_PROTO(check_log_stats,
385                 (noit_check_t *check),
386                 void *, closure,
387                 (void *closure, noit_check_t *check))
388
389 #endif
Note: See TracBrowser for help on using the browser.