root/src/noit_check.h

Revision d10f13b10b05856e66c66dc5f7efb410316d9d6d, 9.5 kB (checked in by Dan Di Spaltro <dan@cloudkick.com>, 3 years ago)

Add Delete messages to noit so we get a message when we deschedule a check

  • 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 "noit_conf.h"
45 #include "noit_console.h"
46
47 /*
48  * Checks:
49  *  attrs:
50  *   UUID
51  *   host (target)
52  *   check (module)
53  *   name (identifying the check to the user if
54  *         multiple checks of the same module are specified)
55  *   config (params for the module)
56  *   period (ms)
57  *   timeout (ms)
58  *  transient:
59  *   eventer_t (fire)
60  *   stats_t [inprogress, last]
61  *   closure
62  */
63
64 #define NP_RUNNING   0x00000001
65 #define NP_KILLED    0x00000002
66 #define NP_DISABLED  0x00000004
67 #define NP_UNCONFIG  0x00000008
68 #define NP_TRANSIENT 0x00000010
69 #define NP_RESOLVE   0x00000020
70 #define NP_RESOLVED  0x00000040
71
72 #define NP_SUPPRESS_STATUS  0x00001000
73 #define NP_SUPPRESS_METRICS 0x00002000
74
75 #define NP_UNKNOWN '0'             /* stats_t.{available,state} */
76 #define NP_AVAILABLE 'A'           /* stats_t.available */
77 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
78 #define NP_BAD 'B'                 /* stats_t.state */
79 #define NP_GOOD 'G'                /* stats_t.state */
80
81 typedef enum {
82   METRIC_GUESS = '0',
83   METRIC_INT32 = 'i',
84   METRIC_UINT32 = 'I',
85   METRIC_INT64 = 'l',
86   METRIC_UINT64 = 'L',
87   METRIC_DOUBLE = 'n',
88   METRIC_STRING = 's'
89 } metric_type_t;
90
91 typedef struct {
92   char *metric_name;
93   metric_type_t metric_type;
94   union {
95     double *n;
96     int32_t *i;
97     u_int32_t *I;
98     int64_t *l;
99     u_int64_t *L;
100     char *s;
101     void *vp; /* used for clever assignments */
102   } metric_value;
103 } metric_t;
104
105 typedef struct {
106   struct timeval whence;
107   int8_t available;
108   int8_t state;
109   u_int32_t duration;
110   char *status;
111   noit_hash_table metrics;
112 } stats_t;
113
114 typedef struct dep_list {
115   struct noit_check *check;
116   struct dep_list *next;
117 } dep_list_t;
118
119 typedef struct noit_check {
120   uuid_t checkid;
121   int8_t target_family;
122   union {
123     struct in_addr addr;
124     struct in6_addr addr6;
125   } target_addr;
126   char *target;
127   char *module;
128   char *name;
129   char *filterset;
130   noit_hash_table *config;
131   char *oncheck;               /* target`name of the check that fires us */
132   u_int32_t period;            /* period of checks in milliseconds */
133   u_int32_t timeout;           /* timeout of check in milliseconds */
134   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
135
136   dep_list_t *causal_checks;
137   eventer_t fire_event;
138   struct timeval last_fire_time;
139   struct {
140     stats_t current;
141     stats_t previous;
142   } stats;
143   u_int32_t generation;        /* This can roll, we don't care */
144   void *closure;
145
146   noit_skiplist *feeds;
147   char target_ip[INET6_ADDRSTRLEN];
148 } noit_check_t;
149
150 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
151 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
152 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
153 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
154 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
155 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
156 /* It is resolved if it is resolved or never needed to be resolved */
157 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
158
159 API_EXPORT(void) noit_poller_init();
160 API_EXPORT(u_int64_t) noit_check_completion_count();
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
167 API_EXPORT(void)
168   noit_check_fake_last_check(noit_check_t *check,
169                              struct timeval *lc, struct timeval *_now);
170 API_EXPORT(int) noit_check_max_initial_stutter();
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                        noit_hash_table *config,
178                        u_int32_t period,
179                        u_int32_t timeout,
180                        const char *oncheck,
181                        int flags,
182                        uuid_t in,
183                        uuid_t out);
184
185 API_EXPORT(int)
186   noit_check_resolve(noit_check_t *check);
187
188 API_EXPORT(int)
189   noit_check_update(noit_check_t *new_check,
190                     const char *target,
191                     const char *name,
192                     const char *filterset,
193                     noit_hash_table *config,
194                     u_int32_t period,
195                     u_int32_t timeout,
196                     const char *oncheck,
197                     int flags);
198
199 API_EXPORT(noit_boolean)
200   noit_check_is_valid_target(const char *str);
201
202 API_EXPORT(int)
203   noit_check_activate(noit_check_t *check);
204
205 API_EXPORT(int)
206   noit_poller_deschedule(uuid_t in);
207
208 API_EXPORT(noit_check_t *)
209   noit_poller_lookup(uuid_t in);
210
211 API_EXPORT(noit_check_t *)
212   noit_poller_lookup_by_name(char *target, char *name);
213
214 API_EXPORT(int)
215    noit_poller_target_do(char *target, int (*f)(noit_check_t *, void *),
216                          void *closure);
217
218 API_EXPORT(int)
219   noit_check_xpath(char *xpath, int len,
220                    const char *base, const char *arg);
221
222 API_EXPORT(void)
223   noit_check_stats_clear(stats_t *s);
224
225 struct _noit_module;
226 /* This if for modules (passive) than cannot be watched... */
227 API_EXPORT(void)
228   noit_check_passive_set_stats(struct _noit_module *self, noit_check_t *check,
229                                stats_t *newstate);
230 /* This is for normal (active) modules... */
231 API_EXPORT(void)
232   noit_check_set_stats(struct _noit_module *self, noit_check_t *check,
233                         stats_t *newstate);
234
235 API_EXPORT(void)
236   noit_stats_set_metric(stats_t *, const char *, metric_type_t, void *);
237
238 API_EXPORT(void)
239   noit_stats_log_immediate_metric(noit_check_t *check,
240                                   const char *name, metric_type_t type,
241                                   void *value);
242
243 API_EXPORT(const char *)
244   noit_check_available_string(int16_t available);
245 API_EXPORT(const char *)
246   noit_check_state_string(int16_t state);
247 API_EXPORT(int)
248   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
249 API_EXPORT(int)
250   noit_stats_snprint_metric(char *b, int l, metric_t *m);
251
252 API_EXPORT(noit_check_t *)
253   noit_check_clone(uuid_t in);
254 API_EXPORT(void)
255   noit_poller_free_check(noit_check_t *checker);
256 API_EXPORT(noit_check_t *)
257   noit_check_watch(uuid_t in, int period);
258 API_EXPORT(noit_check_t *)
259   noit_check_get_watch(uuid_t in, int period);
260 API_EXPORT(void)
261   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
262 API_EXPORT(void)
263   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
264
265 /* These are from noit_check_log.c */
266 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
267 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
268 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
269 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
270 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
271                                        struct timeval *whence, metric_t *m);
272 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
273                                               char *target, int target_len,
274                                               char *module, int module_len,
275                                               char *name, int name_len,
276                                               char *uuid, int uuid_len);
277
278
279 API_EXPORT(char *)
280   noit_console_check_opts(noit_console_closure_t ncct,
281                           noit_console_state_stack_t *stack,
282                           noit_console_state_t *dstate,
283                           int argc, char **argv, int idx);
284 API_EXPORT(char *)
285   noit_console_conf_check_opts(noit_console_closure_t ncct,
286                                noit_console_state_stack_t *stack,
287                                noit_console_state_t *dstate,
288                                int argc, char **argv, int idx);
289
290 #endif
Note: See TracBrowser for help on using the browser.