root/src/noit_check.h

Revision fc52ce1c8e051b2acc414eb64b229b43f8329b20, 6.1 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

more complete tab completion, refs #37

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _NOIT_CHECK_H
7 #define _NOIT_CHECK_H
8
9 #include "noit_defines.h"
10
11 #include <uuid/uuid.h>
12 #include <netinet/in.h>
13
14 #include "eventer/eventer.h"
15 #include "utils/noit_hash.h"
16 #include "utils/noit_skiplist.h"
17 #include "noit_conf.h"
18 #include "noit_console.h"
19
20 /*
21  * Checks:
22  *  attrs:
23  *   UUID
24  *   host (target)
25  *   check (module)
26  *   name (identifying the check to the user if
27  *         multiple checks of the same module are specified)
28  *   config (params for the module)
29  *   period (ms)
30  *   timeout (ms)
31  *  transient:
32  *   eventer_t (fire)
33  *   stats_t [inprogress, last]
34  *   closure
35  */
36
37 #define NP_RUNNING   0x00000001
38 #define NP_KILLED    0x00000002
39 #define NP_DISABLED  0x00000004
40 #define NP_UNCONFIG  0x00000008
41 #define NP_TRANSIENT 0x00000010
42
43 #define NP_UNKNOWN '0'             /* stats_t.{available,state} */
44 #define NP_AVAILABLE 'A'           /* stats_t.available */
45 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
46 #define NP_BAD 'B'                 /* stats_t.state */
47 #define NP_GOOD 'G'                /* stats_t.state */
48
49 typedef enum {
50   METRIC_GUESS = '0',
51   METRIC_INT32 = 'i',
52   METRIC_UINT32 = 'I',
53   METRIC_INT64 = 'l',
54   METRIC_UINT64 = 'L',
55   METRIC_DOUBLE = 'n',
56   METRIC_STRING = 's'
57 } metric_type_t;
58
59 typedef struct {
60   char *metric_name;
61   metric_type_t metric_type;
62   union {
63     double *n;
64     int32_t *i;
65     u_int32_t *I;
66     int64_t *l;
67     u_int64_t *L;
68     char *s;
69     void *vp; /* used for clever assignments */
70   } metric_value;
71 } metric_t;
72
73 typedef struct {
74   struct timeval whence;
75   int8_t available;
76   int8_t state;
77   u_int32_t duration;
78   char *status;
79   noit_hash_table metrics;
80 } stats_t;
81
82 typedef struct dep_list {
83   struct noit_check *check;
84   struct dep_list *next;
85 } dep_list_t;
86
87 typedef struct noit_check {
88   uuid_t checkid;
89   int8_t target_family;
90   union {
91     struct in_addr addr;
92     struct in6_addr addr6;
93   } target_addr;
94   char *target;
95   char *module;
96   char *name;
97   char *filterset;
98   noit_hash_table *config;
99   char *oncheck;               /* target`name of the check that fires us */
100   u_int32_t period;            /* period of checks in milliseconds */
101   u_int32_t timeout;           /* timeout of check in milliseconds */
102   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
103
104   dep_list_t *causal_checks;
105   eventer_t fire_event;
106   struct timeval last_fire_time;
107   struct {
108     stats_t current;
109     stats_t previous;
110   } stats;
111   u_int32_t generation;        /* This can roll, we don't care */
112   void *closure;
113
114   noit_skiplist *feeds;
115 } noit_check_t;
116
117 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
118 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
119 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
120 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
121 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
122
123 API_EXPORT(void) noit_poller_init();
124 API_EXPORT(int) noit_poller_check_count();
125 API_EXPORT(int) noit_poller_transient_check_count();
126 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
127 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
128 API_EXPORT(void) noit_poller_make_causal_map();
129
130 API_EXPORT(void)
131   noit_check_fake_last_check(noit_check_t *check,
132                              struct timeval *lc, struct timeval *_now);
133 API_EXPORT(int) noit_check_max_initial_stutter();
134
135 API_EXPORT(int)
136   noit_poller_schedule(const char *target,
137                        const char *module,
138                        const char *name,
139                        const char *filterset,
140                        noit_hash_table *config,
141                        u_int32_t period,
142                        u_int32_t timeout,
143                        const char *oncheck,
144                        int flags,
145                        uuid_t in,
146                        uuid_t out);
147
148 API_EXPORT(int)
149   noit_check_update(noit_check_t *new_check,
150                     const char *target,
151                     const char *name,
152                     const char *filterset,
153                     noit_hash_table *config,
154                     u_int32_t period,
155                     u_int32_t timeout,
156                     const char *oncheck,
157                     int flags);
158
159 API_EXPORT(int)
160   noit_check_activate(noit_check_t *check);
161
162 API_EXPORT(int)
163   noit_poller_deschedule(uuid_t in);
164
165 API_EXPORT(noit_check_t *)
166   noit_poller_lookup(uuid_t in);
167
168 API_EXPORT(noit_check_t *)
169   noit_poller_lookup_by_name(char *target, char *name);
170
171 API_EXPORT(void)
172   noit_check_stats_clear(stats_t *s);
173
174 struct _noit_module;
175 API_EXPORT(void)
176   noit_check_set_stats(struct _noit_module *self, noit_check_t *check,
177                         stats_t *newstate);
178
179 API_EXPORT(void)
180   noit_stats_set_metric(stats_t *, const char *, metric_type_t, void *);
181
182 API_EXPORT(const char *)
183   noit_check_available_string(int16_t available);
184 API_EXPORT(const char *)
185   noit_check_state_string(int16_t state);
186 API_EXPORT(int)
187   noit_stats_snprint_metric(char *b, int l, metric_t *m);
188
189 API_EXPORT(noit_check_t *)
190   noit_check_clone(uuid_t in);
191 API_EXPORT(noit_check_t *)
192   noit_check_watch(uuid_t in, int period);
193 API_EXPORT(noit_check_t *)
194   noit_check_get_watch(uuid_t in, int period);
195 API_EXPORT(void)
196   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
197 API_EXPORT(void)
198   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
199
200 /* These are from noit_check_log.c */
201 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
202 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
203 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
204
205 API_EXPORT(char *)
206   noit_console_check_opts(noit_console_closure_t ncct,
207                           noit_console_state_stack_t *stack,
208                           noit_console_state_t *dstate,
209                           int argc, char **argv, int idx);
210 API_EXPORT(char *)
211   noit_console_conf_check_opts(noit_console_closure_t ncct,
212                                noit_console_state_stack_t *stack,
213                                noit_console_state_t *dstate,
214                                int argc, char **argv, int idx);
215
216 #endif
Note: See TracBrowser for help on using the browser.