root/src/noit_check.h

Revision 304ec80b8cf842fc0abe5f9029790908b6455957, 13.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 1 month ago)

Convert to libmtev.

  • 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 {
107   struct timeval whence;
108   int8_t available;
109   int8_t state;
110   u_int32_t duration;
111   char *status;
112   mtev_hash_table metrics;
113 } stats_t;
114
115 typedef struct dep_list {
116   struct noit_check *check;
117   struct dep_list *next;
118 } dep_list_t;
119
120 typedef struct noit_check {
121   uuid_t checkid;
122   int8_t target_family;
123   union {
124     struct in_addr addr;
125     struct in6_addr addr6;
126   } target_addr;
127   char *target;
128   char *module;
129   char *name;
130   char *filterset;
131   mtev_hash_table *config;
132   char *oncheck;               /* target`name of the check that fires us */
133   u_int32_t period;            /* period of checks in milliseconds */
134   u_int32_t timeout;           /* timeout of check in milliseconds */
135   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
136
137   dep_list_t *causal_checks;
138   eventer_t fire_event;
139   struct timeval last_fire_time;
140   struct {
141     stats_t inprogress;
142     stats_t current;
143     stats_t previous;
144   } stats;
145   u_int32_t generation;        /* This can roll, we don't care */
146   void *closure;
147
148   mtev_skiplist *feeds;
149   char target_ip[INET6_ADDRSTRLEN];
150   void **module_metadata;
151   mtev_hash_table **module_configs;
152   struct timeval initial_schedule_time;
153 } noit_check_t;
154
155 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
156 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
157 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
158 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
159 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
160 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
161 /* It is resolved if it is resolved or never needed to be resolved */
162 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
163 #define NOIT_CHECK_PREFER_V6(a) ((a)->flags & NP_PREFER_IPV6)
164 #define NOIT_CHECK_SINGLE_RESOLVE(a) ((a)->flags & NP_SINGLE_RESOLVE)
165
166 API_EXPORT(void) noit_poller_init();
167 API_EXPORT(u_int64_t) noit_check_completion_count();
168 API_EXPORT(u_int64_t) noit_check_metric_count();
169 API_EXPORT(void) noit_check_metric_count_add(int);
170 API_EXPORT(int) noit_poller_check_count();
171 API_EXPORT(int) noit_poller_transient_check_count();
172 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
173 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
174 API_EXPORT(void) noit_poller_make_causal_map();
175 API_EXPORT(void) noit_check_dns_ignore_tld(const char* extension, const char* ignore);
176
177 API_EXPORT(void)
178   noit_check_fake_last_check(noit_check_t *check,
179                              struct timeval *lc, struct timeval *_now);
180
181 API_EXPORT(int)
182   noit_poller_schedule(const char *target,
183                        const char *module,
184                        const char *name,
185                        const char *filterset,
186                        mtev_hash_table *config,
187                        mtev_hash_table **mconfig,
188                        u_int32_t period,
189                        u_int32_t timeout,
190                        const char *oncheck,
191                        int flags,
192                        uuid_t in,
193                        uuid_t out);
194
195 API_EXPORT(int)
196   noit_check_resolve(noit_check_t *check);
197
198 API_EXPORT(int)
199   noit_check_update(noit_check_t *new_check,
200                     const char *target,
201                     const char *name,
202                     const char *filterset,
203                     mtev_hash_table *config,
204                     mtev_hash_table **mconfig,
205                     u_int32_t period,
206                     u_int32_t timeout,
207                     const char *oncheck,
208                     int flags);
209
210 API_EXPORT(mtev_boolean)
211   noit_check_is_valid_target(const char *str);
212
213 API_EXPORT(int)
214   noit_check_activate(noit_check_t *check);
215
216 API_EXPORT(int)
217   noit_poller_deschedule(uuid_t in);
218
219 API_EXPORT(noit_check_t *)
220   noit_poller_lookup(uuid_t in);
221
222 API_EXPORT(noit_check_t *)
223   noit_poller_lookup_by_name(char *target, char *name);
224
225 API_EXPORT(int)
226   noit_poller_lookup_by_ip_module(const char *ip, const char *mod,
227                                   noit_check_t **checks, int nchecks);
228
229 API_EXPORT(int)
230    noit_poller_target_ip_do(const char *target,
231                             int (*f)(noit_check_t *, void *),
232                             void *closure);
233
234 API_EXPORT(int)
235    noit_poller_target_do(const char *target,
236                          int (*f)(noit_check_t *, void *),
237                          void *closure);
238
239 API_EXPORT(int)
240    noit_poller_do(int (*f)(noit_check_t *, void *),
241                   void *closure);
242
243 API_EXPORT(int)
244   noit_check_xpath(char *xpath, int len,
245                    const char *base, const char *arg);
246
247 API_EXPORT(void)
248   noit_check_stats_clear(noit_check_t *check, stats_t *s);
249
250 struct _noit_module;
251 /* This if for modules (passive) than cannot be watched... */
252 API_EXPORT(void)
253   noit_check_passive_set_stats(noit_check_t *check,
254                                stats_t *newstate);
255 /* This is for normal (active) modules... */
256 API_EXPORT(void)
257   noit_check_set_stats(noit_check_t *check,
258                         stats_t *newstate);
259
260 API_EXPORT(metric_t *)
261   noit_stats_get_metric(noit_check_t *check, stats_t *, const char *);
262
263 API_EXPORT(void)
264   noit_stats_set_metric(noit_check_t *check,
265                         stats_t *, const char *, metric_type_t, const void *);
266
267 API_EXPORT(void)
268   noit_stats_set_metric_coerce(noit_check_t *check,
269                                stats_t *, const char *, metric_type_t,
270                                const char *);
271
272 API_EXPORT(void)
273   noit_stats_log_immediate_metric(noit_check_t *check,
274                                   const char *name, metric_type_t type,
275                                   void *value);
276
277 API_EXPORT(const char *)
278   noit_check_available_string(int16_t available);
279 API_EXPORT(const char *)
280   noit_check_state_string(int16_t state);
281 API_EXPORT(int)
282   noit_calc_rtype_flag(char *resolve_rtype);
283 API_EXPORT(int)
284   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
285 API_EXPORT(int)
286   noit_stats_snprint_metric(char *b, int l, metric_t *m);
287
288 API_EXPORT(noit_check_t *)
289   noit_check_clone(uuid_t in);
290 API_EXPORT(void)
291   noit_poller_free_check(noit_check_t *checker);
292 API_EXPORT(noit_check_t *)
293   noit_check_watch(uuid_t in, int period);
294 API_EXPORT(noit_check_t *)
295   noit_check_get_watch(uuid_t in, int period);
296 API_EXPORT(void)
297   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
298 API_EXPORT(void)
299   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
300
301 API_EXPORT(int)
302   noit_check_register_module(const char *);
303 API_EXPORT(int)
304   noit_check_registered_module_cnt();
305 API_EXPORT(const char *)
306   noit_check_registered_module(int);
307
308 API_EXPORT(int)
309   noit_check_validate_target(const char *);
310 API_EXPORT(int)
311   noit_check_validate_name(const char *);
312
313 API_EXPORT(void)
314   noit_check_set_module_metadata(noit_check_t *, int, void *, void (*freefunc)(void *));
315 API_EXPORT(void)
316   noit_check_set_module_config(noit_check_t *, int, mtev_hash_table *);
317 API_EXPORT(void *)
318   noit_check_get_module_metadata(noit_check_t *, int);
319 API_EXPORT(mtev_hash_table *)
320   noit_check_get_module_config(noit_check_t *, int);
321
322 /* These are from noit_check_log.c */
323 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
324 API_EXPORT(void) noit_filterset_log_auto_add(char *filter, noit_check_t *check,
325                                              metric_t *m, mtev_boolean allow);
326 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
327 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
328 API_EXPORT(void) noit_check_log_bundle(noit_check_t *check);
329 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
330 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
331                                        struct timeval *whence, metric_t *m);
332 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
333                                               char *target, int target_len,
334                                               char *module, int module_len,
335                                               char *name, int name_len,
336                                               char *uuid, int uuid_len);
337
338
339 API_EXPORT(char *)
340   noit_console_check_opts(mtev_console_closure_t ncct,
341                           mtev_console_state_stack_t *stack,
342                           mtev_console_state_t *dstate,
343                           int argc, char **argv, int idx);
344 API_EXPORT(char *)
345   noit_console_conf_check_opts(mtev_console_closure_t ncct,
346                                mtev_console_state_stack_t *stack,
347                                mtev_console_state_t *dstate,
348                                int argc, char **argv, int idx);
349
350 API_EXPORT(void) check_slots_inc_tv(struct timeval *tv);
351 API_EXPORT(void) check_slots_dec_tv(struct timeval *tv);
352
353 MTEV_HOOK_PROTO(check_config_fixup,
354                 (noit_check_t *check),
355                 void *, closure,
356                 (void *closure, noit_check_t *check))
357
358 MTEV_HOOK_PROTO(check_stats_set_metric,
359                 (noit_check_t *check, stats_t *stats, metric_t *m),
360                 void *, closure,
361                 (void *closure, noit_check_t *check, stats_t *stats, metric_t *m))
362
363 MTEV_HOOK_PROTO(check_stats_set_metric_coerce,
364                 (noit_check_t *check, stats_t *stats, const char *name,
365                  metric_type_t type, const char *v, mtev_boolean success),
366                 void *, closure,
367                 (void *closure, noit_check_t *check, stats_t *stats, const char *name,
368                  metric_type_t type, const char *v, mtev_boolean success))
369
370 MTEV_HOOK_PROTO(check_passive_log_stats,
371                 (noit_check_t *check),
372                 void *, closure,
373                 (void *closure, noit_check_t *check))
374
375 MTEV_HOOK_PROTO(check_log_stats,
376                 (noit_check_t *check),
377                 void *, closure,
378                 (void *closure, noit_check_t *check))
379
380 #endif
Note: See TracBrowser for help on using the browser.