root/src/noit_check.h

Revision 9c44e5a54c4ada69e5e61476fc5775b6e4d96c14, 14.4 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 weeks ago)

Make stats on checks use epoch memory reclamation.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  * Copyright (c) 2013-2015, 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 <mtev_defines.h>
38
39 #include <uuid/uuid.h>
40 #include <netinet/in.h>
41
42 #include <eventer/eventer.h>
43 #include <mtev_hash.h>
44 #include <mtev_skiplist.h>
45 #include <mtev_hooks.h>
46 #include <mtev_conf.h>
47 #include <mtev_console.h>
48
49 #include "noit_metric.h"
50
51 /*
52  * Checks:
53  *  attrs:
54  *   UUID
55  *   host (target)
56  *   check (module)
57  *   name (identifying the check to the user if
58  *         multiple checks of the same module are specified)
59  *   config (params for the module)
60  *   period (ms)
61  *   timeout (ms)
62  *  transient:
63  *   eventer_t (fire)
64  *   stats_t [inprogress, current, previous]
65  *   closure
66  */
67
68 /* The check is currently in-flight (running) */
69 #define NP_RUNNING               0x00000001
70 /* The check has been killed by the scheduling system */
71 #define NP_KILLED                0x00000002
72 /* The check is disable and should not be run */
73 #define NP_DISABLED              0x00000004
74 /* The check is not sufficiently configured to operate */
75 #define NP_UNCONFIG              0x00000008
76 /* The check is a transient copy of another check */
77 #define NP_TRANSIENT             0x00000010
78 /* The check requires name service resolution */
79 #define NP_RESOLVE               0x00000020
80 /* Name service resolution has been compelted for the check */
81 #define NP_RESOLVED              0x00000040
82 /* This check should have 'S' lines suppressed from logging */
83 #define NP_SUPPRESS_STATUS       0x00001000
84 /* This check should have 'M' lines suppressed from logging */
85 #define NP_SUPPRESS_METRICS      0x00002000
86 /* The check should lookup IPv6 records before IPv4 */
87 #define NP_PREFER_IPV6           0x00004000
88 /* Do no fallback to IPv6 from IPv4 and vice versa */
89 #define NP_SINGLE_RESOLVE        0x00008000
90 /* Indicates that the check is receiving data passively
91  * and it does not do anything during invocation to collect metrics
92  */
93 #define NP_PASSIVE_COLLECTION    0x00010000
94
95 #define PREFER_IPV4 "prefer-ipv4"
96 #define PREFER_IPV6 "prefer-ipv6"
97 #define FORCE_IPV4  "force-ipv4"
98 #define FORCE_IPV6  "force-ipv6"
99
100 #define NP_UNKNOWN '0'             /* stats_t.{available,state} */
101 #define NP_AVAILABLE 'A'           /* stats_t.available */
102 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
103 #define NP_BAD 'B'                 /* stats_t.state */
104 #define NP_GOOD 'G'                /* stats_t.state */
105
106 typedef struct stats_t stats_t;
107
108 typedef struct dep_list {
109   struct noit_check *check;
110   struct dep_list *next;
111 } dep_list_t;
112
113 typedef struct noit_check {
114   uuid_t checkid;
115   int8_t target_family;
116   union {
117     struct in_addr addr;
118     struct in6_addr addr6;
119   } target_addr;
120   char *target;
121   char *module;
122   char *name;
123   char *filterset;
124   mtev_hash_table *config;
125   char *oncheck;               /* target`name of the check that fires us */
126   u_int32_t period;            /* period of checks in milliseconds */
127   u_int32_t timeout;           /* timeout of check in milliseconds */
128   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
129
130   dep_list_t *causal_checks;
131   eventer_t fire_event;
132   struct timeval last_fire_time;
133   u_int32_t generation;        /* This can roll, we don't care */
134   void *closure;
135
136   mtev_skiplist *feeds;
137   char target_ip[INET6_ADDRSTRLEN];
138   void **module_metadata;
139   mtev_hash_table **module_configs;
140   struct timeval initial_schedule_time;
141   int64_t config_seq;          /* If non-zero, must increase */
142
143   void *statistics;
144 } noit_check_t;
145
146 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
147 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
148 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
149 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
150 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
151 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
152 /* It is resolved if it is resolved or never needed to be resolved */
153 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
154 #define NOIT_CHECK_PREFER_V6(a) ((a)->flags & NP_PREFER_IPV6)
155 #define NOIT_CHECK_SINGLE_RESOLVE(a) ((a)->flags & NP_SINGLE_RESOLVE)
156
157 API_EXPORT(void) noit_poller_init();
158 API_EXPORT(u_int64_t) noit_check_completion_count();
159 API_EXPORT(u_int64_t) noit_check_metric_count();
160 API_EXPORT(void) noit_check_metric_count_add(int);
161 API_EXPORT(int) noit_poller_check_count();
162 API_EXPORT(int) noit_poller_transient_check_count();
163 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
164 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
165 API_EXPORT(void) noit_poller_make_causal_map();
166 API_EXPORT(void) noit_check_dns_ignore_tld(const char* extension, const char* ignore);
167
168 API_EXPORT(void)
169   noit_check_fake_last_check(noit_check_t *check,
170                              struct timeval *lc, struct timeval *_now);
171
172 API_EXPORT(int)
173   noit_poller_schedule(const char *target,
174                        const char *module,
175                        const char *name,
176                        const char *filterset,
177                        mtev_hash_table *config,
178                        mtev_hash_table **mconfig,
179                        u_int32_t period,
180                        u_int32_t timeout,
181                        const char *oncheck,
182                        int64_t seq,
183                        int flags,
184                        uuid_t in,
185                        uuid_t out);
186
187 API_EXPORT(int)
188   noit_check_resolve(noit_check_t *check);
189
190 API_EXPORT(int)
191   noit_check_update(noit_check_t *new_check,
192                     const char *target,
193                     const char *name,
194                     const char *filterset,
195                     mtev_hash_table *config,
196                     mtev_hash_table **mconfig,
197                     u_int32_t period,
198                     u_int32_t timeout,
199                     const char *oncheck,
200                     int64_t seq,
201                     int flags);
202
203 API_EXPORT(mtev_boolean)
204   noit_check_is_valid_target(const char *str);
205
206 API_EXPORT(int)
207   noit_check_activate(noit_check_t *check);
208
209 API_EXPORT(int)
210   noit_poller_deschedule(uuid_t in);
211
212 API_EXPORT(noit_check_t *)
213   noit_poller_lookup(uuid_t in);
214
215 API_EXPORT(noit_check_t *)
216   noit_poller_lookup_by_name(char *target, char *name);
217
218 API_EXPORT(int)
219   noit_poller_lookup_by_ip_module(const char *ip, const char *mod,
220                                   noit_check_t **checks, int nchecks);
221
222 API_EXPORT(int)
223    noit_poller_target_ip_do(const char *target,
224                             int (*f)(noit_check_t *, void *),
225                             void *closure);
226
227 API_EXPORT(int)
228    noit_poller_target_do(const char *target,
229                          int (*f)(noit_check_t *, void *),
230                          void *closure);
231
232 API_EXPORT(int)
233    noit_poller_do(int (*f)(noit_check_t *, void *),
234                   void *closure);
235
236 API_EXPORT(int)
237   noit_check_xpath(char *xpath, int len,
238                    const char *base, const char *arg);
239
240 struct _noit_module;
241
242 stats_t *
243 noit_check_get_stats_inprogress(noit_check_t *c);
244 stats_t *
245 noit_check_get_stats_current(noit_check_t *c);
246 stats_t *
247 noit_check_get_stats_previous(noit_check_t *c);
248
249 /* This if for modules (passive) than cannot be watched... */
250 API_EXPORT(void)
251   noit_check_passive_set_stats(noit_check_t *check);
252
253 /* This is for normal (active) modules... */
254 API_EXPORT(void)
255   noit_check_set_stats(noit_check_t *check);
256
257 API_EXPORT(void)
258   noit_stats_set_whence(noit_check_t *check, struct timeval *t);
259 API_EXPORT(void)
260   noit_stats_set_duration(noit_check_t *check, u_int32_t t);
261 API_EXPORT(void)
262   noit_stats_set_available(noit_check_t *check, int8_t t);
263 API_EXPORT(void)
264   noit_stats_set_state(noit_check_t *check, int8_t t);
265 API_EXPORT(void)
266   noit_stats_set_status(noit_check_t *check, const char *t);
267
268 API_EXPORT(metric_t *)
269   noit_stats_get_metric(noit_check_t *check, stats_t *, const char *);
270
271 API_EXPORT(void)
272   noit_stats_set_metric(noit_check_t *check,
273                         const char *, metric_type_t, const void *);
274
275 API_EXPORT(void)
276   noit_stats_set_metric_coerce(noit_check_t *check,
277                                const char *, metric_type_t,
278                                const char *);
279
280 API_EXPORT(void)
281   noit_stats_log_immediate_metric(noit_check_t *check,
282                                   const char *name, metric_type_t type,
283                                   void *value);
284
285 API_EXPORT(const char *)
286   noit_check_available_string(int16_t available);
287 API_EXPORT(const char *)
288   noit_check_state_string(int16_t state);
289 API_EXPORT(int)
290   noit_calc_rtype_flag(char *resolve_rtype);
291 API_EXPORT(int)
292   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
293 API_EXPORT(int)
294   noit_stats_snprint_metric(char *b, int l, metric_t *m);
295
296 API_EXPORT(noit_check_t *)
297   noit_check_clone(uuid_t in);
298 API_EXPORT(void)
299   noit_poller_free_check(noit_check_t *checker);
300 API_EXPORT(noit_check_t *)
301   noit_check_watch(uuid_t in, int period);
302 API_EXPORT(noit_check_t *)
303   noit_check_get_watch(uuid_t in, int period);
304 API_EXPORT(void)
305   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
306 API_EXPORT(void)
307   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
308
309 API_EXPORT(int)
310   noit_check_register_module(const char *);
311 API_EXPORT(int)
312   noit_check_registered_module_cnt();
313 API_EXPORT(const char *)
314   noit_check_registered_module(int);
315
316 API_EXPORT(int)
317   noit_check_validate_target(const char *);
318 API_EXPORT(int)
319   noit_check_validate_name(const char *);
320
321 API_EXPORT(void)
322   noit_check_set_module_metadata(noit_check_t *, int, void *, void (*freefunc)(void *));
323 API_EXPORT(void)
324   noit_check_set_module_config(noit_check_t *, int, mtev_hash_table *);
325 API_EXPORT(void *)
326   noit_check_get_module_metadata(noit_check_t *, int);
327 API_EXPORT(mtev_hash_table *)
328   noit_check_get_module_config(noit_check_t *, int);
329
330 /* These are from noit_check_log.c */
331 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
332 API_EXPORT(void) noit_filterset_log_auto_add(char *filter, noit_check_t *check,
333                                              metric_t *m, mtev_boolean allow);
334 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
335 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
336 API_EXPORT(void) noit_check_log_bundle(noit_check_t *check);
337 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
338 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
339                                        struct timeval *whence, metric_t *m);
340 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
341                                               char *target, int target_len,
342                                               char *module, int module_len,
343                                               char *name, int name_len,
344                                               char *uuid, int uuid_len);
345
346
347 API_EXPORT(char *)
348   noit_console_check_opts(mtev_console_closure_t ncct,
349                           mtev_console_state_stack_t *stack,
350                           mtev_console_state_t *dstate,
351                           int argc, char **argv, int idx);
352 API_EXPORT(char *)
353   noit_console_conf_check_opts(mtev_console_closure_t ncct,
354                                mtev_console_state_stack_t *stack,
355                                mtev_console_state_t *dstate,
356                                int argc, char **argv, int idx);
357
358 API_EXPORT(void) check_slots_inc_tv(struct timeval *tv);
359 API_EXPORT(void) check_slots_dec_tv(struct timeval *tv);
360
361 API_EXPORT(struct timeval *)
362   noit_check_stats_whence(stats_t *s, struct timeval *n);
363 API_EXPORT(int8_t)
364   noit_check_stats_available(stats_t *s, int8_t *n);
365 API_EXPORT(int8_t)
366   noit_check_stats_state(stats_t *s, int8_t *n);
367 API_EXPORT(u_int32_t)
368   noit_check_stats_duration(stats_t *s, u_int32_t *n);
369 API_EXPORT(const char *)
370   noit_check_stats_status(stats_t *s, const char *n);
371 API_EXPORT(mtev_hash_table *)
372   noit_check_stats_metrics(stats_t *s);
373
374 MTEV_HOOK_PROTO(check_config_fixup,
375                 (noit_check_t *check),
376                 void *, closure,
377                 (void *closure, noit_check_t *check))
378
379 MTEV_HOOK_PROTO(check_stats_set_metric,
380                 (noit_check_t *check, stats_t *stats, metric_t *m),
381                 void *, closure,
382                 (void *closure, noit_check_t *check, stats_t *stats, metric_t *m))
383
384 MTEV_HOOK_PROTO(check_stats_set_metric_coerce,
385                 (noit_check_t *check, stats_t *stats, const char *name,
386                  metric_type_t type, const char *v, mtev_boolean success),
387                 void *, closure,
388                 (void *closure, noit_check_t *check, stats_t *stats, const char *name,
389                  metric_type_t type, const char *v, mtev_boolean success))
390
391 MTEV_HOOK_PROTO(check_passive_log_stats,
392                 (noit_check_t *check),
393                 void *, closure,
394                 (void *closure, noit_check_t *check))
395
396 MTEV_HOOK_PROTO(check_log_stats,
397                 (noit_check_t *check),
398                 void *, closure,
399                 (void *closure, noit_check_t *check))
400
401 #endif
Note: See TracBrowser for help on using the browser.