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(void) noit_poller_reload(const char *xpath); /* NULL for all */ |
---|
125 |
API_EXPORT(void) noit_poller_process_checks(const char *xpath); |
---|
126 |
API_EXPORT(void) noit_poller_make_causal_map(); |
---|
127 |
|
---|
128 |
API_EXPORT(void) |
---|
129 |
noit_check_fake_last_check(noit_check_t *check, |
---|
130 |
struct timeval *lc, struct timeval *_now); |
---|
131 |
API_EXPORT(int) noit_check_max_initial_stutter(); |
---|
132 |
|
---|
133 |
API_EXPORT(int) |
---|
134 |
noit_poller_schedule(const char *target, |
---|
135 |
const char *module, |
---|
136 |
const char *name, |
---|
137 |
const char *filterset, |
---|
138 |
noit_hash_table *config, |
---|
139 |
u_int32_t period, |
---|
140 |
u_int32_t timeout, |
---|
141 |
const char *oncheck, |
---|
142 |
int flags, |
---|
143 |
uuid_t in, |
---|
144 |
uuid_t out); |
---|
145 |
|
---|
146 |
API_EXPORT(int) |
---|
147 |
noit_check_update(noit_check_t *new_check, |
---|
148 |
const char *target, |
---|
149 |
const char *name, |
---|
150 |
const char *filterset, |
---|
151 |
noit_hash_table *config, |
---|
152 |
u_int32_t period, |
---|
153 |
u_int32_t timeout, |
---|
154 |
const char *oncheck, |
---|
155 |
int flags); |
---|
156 |
|
---|
157 |
API_EXPORT(int) |
---|
158 |
noit_check_activate(noit_check_t *check); |
---|
159 |
|
---|
160 |
API_EXPORT(int) |
---|
161 |
noit_poller_deschedule(uuid_t in); |
---|
162 |
|
---|
163 |
API_EXPORT(noit_check_t *) |
---|
164 |
noit_poller_lookup(uuid_t in); |
---|
165 |
|
---|
166 |
API_EXPORT(noit_check_t *) |
---|
167 |
noit_poller_lookup_by_name(char *target, char *name); |
---|
168 |
|
---|
169 |
API_EXPORT(void) |
---|
170 |
noit_check_stats_clear(stats_t *s); |
---|
171 |
|
---|
172 |
struct _noit_module; |
---|
173 |
API_EXPORT(void) |
---|
174 |
noit_check_set_stats(struct _noit_module *self, noit_check_t *check, |
---|
175 |
stats_t *newstate); |
---|
176 |
|
---|
177 |
API_EXPORT(void) |
---|
178 |
noit_stats_set_metric(stats_t *, const char *, metric_type_t, void *); |
---|
179 |
|
---|
180 |
API_EXPORT(const char *) |
---|
181 |
noit_check_available_string(int16_t available); |
---|
182 |
API_EXPORT(const char *) |
---|
183 |
noit_check_state_string(int16_t state); |
---|
184 |
API_EXPORT(int) |
---|
185 |
noit_stats_snprint_metric(char *b, int l, metric_t *m); |
---|
186 |
|
---|
187 |
API_EXPORT(noit_check_t *) |
---|
188 |
noit_check_clone(uuid_t in); |
---|
189 |
API_EXPORT(noit_check_t *) |
---|
190 |
noit_check_watch(uuid_t in, int period); |
---|
191 |
API_EXPORT(noit_check_t *) |
---|
192 |
noit_check_get_watch(uuid_t in, int period); |
---|
193 |
API_EXPORT(void) |
---|
194 |
noit_check_transient_add_feed(noit_check_t *check, const char *feed); |
---|
195 |
API_EXPORT(void) |
---|
196 |
noit_check_transient_remove_feed(noit_check_t *check, const char *feed); |
---|
197 |
|
---|
198 |
/* These are from noit_check_log.c */ |
---|
199 |
API_EXPORT(void) noit_check_log_check(noit_check_t *check); |
---|
200 |
API_EXPORT(void) noit_check_log_status(noit_check_t *check); |
---|
201 |
API_EXPORT(void) noit_check_log_metrics(noit_check_t *check); |
---|
202 |
|
---|
203 |
#endif |
---|