root/src/noit_check_tools.h

Revision 304ec80b8cf842fc0abe5f9029790908b6455957, 6.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 2 months 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) 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_TOOLS_H
35 #define _NOIT_CHECK_TOOLS_H
36
37 #include <mtev_defines.h>
38 #include <eventer/eventer.h>
39 #include <mtev_hash.h>
40 #include <mtev_hooks.h>
41 #include "noit_module.h"
42 #include "noit_check.h"
43 #include "noit_check_tools_shared.h"
44
45 typedef int (*dispatch_func_t)(noit_module_t *, noit_check_t *,
46                                noit_check_t *);
47
48 API_EXPORT(void)
49   noit_check_tools_init();
50
51 API_EXPORT(int)
52   noit_check_schedule_next(noit_module_t *self,
53                            struct timeval *last_check, noit_check_t *check,
54                            struct timeval *now, dispatch_func_t recur,
55                            noit_check_t *cause);
56
57 API_EXPORT(void)
58   noit_check_run_full_asynch_opts(noit_check_t *check, eventer_func_t callback,
59                                   int mask);
60 API_EXPORT(void)
61   noit_check_run_full_asynch(noit_check_t *check, eventer_func_t callback);
62
63 API_EXPORT(int)
64   noit_check_stats_from_json_str(noit_check_t *check, stats_t *s,
65                                  const char *json_str, int len);
66
67 API_EXPORT(void)
68   noit_check_make_attrs(noit_check_t *check, mtev_hash_table *attrs);
69
70 #define CHOOSE_EVENTER_THREAD_FOR_CHECK(check) \
71   eventer_choose_owner(((int)(((vpsized_int)(check))/sizeof(*(check))))*2654435761)
72
73 /*#* DOCBOOK
74  * <section><title>Check Hooks</title>
75  *   <section><title>check_stats_set_metric</title>
76  *   <programlisting>
77  *     noit_hook_return_t (*f)(void *closure, noit_check_t *check, metric_t *m);
78  *   </programlisting>
79  *   <para>the check_stats_set_metric hook is invoked each time a check is
80  *   run and an individual metric is identified and inserted into
81  *   the running status.
82  *   </para>
83  *   </section>
84  *   <section><title>check_preflight</title>
85  *   <programlisting>
86  *     noit_hook_return_t (*f)(void *closure, noit_module_t *self,
87  *                             noit_check_t *check, noit_check_t *cause);
88  *   </programlisting>
89  *   <para>the check_preflight hook is invoked immediately prior to every
90  *   check being performed.  The actual invocation of the check can be
91  *   avoided by returning MTEV_HOOK_DONE instead of MTEV_HOOK_CONTINUE.
92  *   </para>
93  *   <para>The arguments to this function are the module of the check
94  *   the check itself and the causal check (NULL if this check was not
95  *   induced by the completion of another check), respectively.</para>
96  *   <para>This instrumentation point can be used to audit intended check
97  *   activity or prevent a check from running (such as an ACL).</para>
98  *   </section>
99  *   <section><title>check_postflight</title>
100  *   <programlisting>
101  *     noit_hook_return_t (*f)(void *closure, noit_module_t *self,
102  *                             noit_check_t *check, noit_check_t *cause);
103  *   </programlisting>
104  *   <para>The check_postflight hook is invoked immediately subsequent to
105  *   a check being commenced.  Note that due to the asynchronous nature
106  *   of Reconnoiter, it is highly unlikely that the check will have
107  *   completed by this time.</para>
108  *   <para>The arguments to this function are the module of the check,
109  *   the check itself and the causal check (NULL if this check was not
110  *   induced by the completion of another check), respectively.</para>
111  *   <para>Returning MTEV_HOOK_CONTINUE and MTEV_HOOK_DONE have the same
112  *   effect for this instrumentation point.</para>
113  *   </section>
114  *   <section><title>check_log_stats</title>
115  *   <programlisting>
116  *     noit_hook_return_t (*f)(void *closure, noit_check_t *check);
117  *   </programlisting>
118  *   <para>The check_log_stats is called when a check logs a metrics
119  *   bundle.</para>
120  *   <para>If MTEV_HOOK_DONE is returned, normal logging is averted.</para>
121  *   </section>
122  *   <section><title>check_passive_log_stats</title>
123  *   <programlisting>
124  *     noit_hook_return_t (*f)(void *closure, noit_check_t *check);
125  *   </programlisting>
126  *   <para>The check_passive_log_stats is called when a check logs a
127  *   metric immediately.</para>
128  *   <para>If MTEV_HOOK_DONE is returned, normal logging is averted.</para>
129  *   </section>
130  * </section>
131  */
132 MTEV_HOOK_PROTO(check_preflight,
133                 (noit_module_t *self, noit_check_t *check, noit_check_t *cause),
134                 void *, closure,
135                 (void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause))
136 MTEV_HOOK_PROTO(check_postflight,
137                 (noit_module_t *self, noit_check_t *check, noit_check_t *cause),
138                 void *, closure,
139                 (void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause))
140
141 #define BAIL_ON_RUNNING_CHECK(check) do { \
142   if(check->flags & NP_RUNNING) { \
143     mtevL(noit_error, "Check %s is still running!\n", check->name); \
144     return -1; \
145   } \
146 } while(0)
147
148 #define INITIATE_CHECK(func, self, check, cause) do { \
149   if(once) { \
150     if(MTEV_HOOK_CONTINUE == \
151        check_preflight_hook_invoke(self, check, cause)) \
152       func(self, check, cause); \
153     check_postflight_hook_invoke(self, check, cause); \
154   } \
155   else if(!check->fire_event) { \
156     struct timeval epoch = { 0L, 0L }; \
157     noit_check_fake_last_check(check, &epoch, NULL); \
158     noit_check_schedule_next(self, &epoch, check, NULL, func, cause); \
159   } \
160 } while(0)
161
162 #endif
163
Note: See TracBrowser for help on using the browser.