| 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 "noit_conf.h" |
|---|
| 17 |
#include "noit_console.h" |
|---|
| 18 |
|
|---|
| 19 |
/* |
|---|
| 20 |
* Checks: |
|---|
| 21 |
* attrs: |
|---|
| 22 |
* UUID |
|---|
| 23 |
* host (target) |
|---|
| 24 |
* check (module) |
|---|
| 25 |
* name (identifying the check to the user if |
|---|
| 26 |
* multiple checks of the same module are specified) |
|---|
| 27 |
* config (params for the module) |
|---|
| 28 |
* period (ms) |
|---|
| 29 |
* timeout (ms) |
|---|
| 30 |
* transient: |
|---|
| 31 |
* eventer_t (fire) |
|---|
| 32 |
* stats_t [inprogress, last] |
|---|
| 33 |
* closure |
|---|
| 34 |
*/ |
|---|
| 35 |
|
|---|
| 36 |
#define NP_RUNNING 0x00000001 |
|---|
| 37 |
#define NP_KILLED 0x00000002 |
|---|
| 38 |
#define NP_DISABLED 0x00000004 |
|---|
| 39 |
#define NP_UNCONFIG 0x00000008 |
|---|
| 40 |
|
|---|
| 41 |
#define NP_UNKNOWN '0' /* stats_t.{available,state} */ |
|---|
| 42 |
#define NP_AVAILABLE 'A' /* stats_t.available */ |
|---|
| 43 |
#define NP_UNAVAILABLE 'U' /* stats_t.available */ |
|---|
| 44 |
#define NP_BAD 'B' /* stats_t.state */ |
|---|
| 45 |
#define NP_GOOD 'G' /* stats_t.state */ |
|---|
| 46 |
|
|---|
| 47 |
typedef enum { |
|---|
| 48 |
METRIC_GUESS = '0', |
|---|
| 49 |
METRIC_INT32 = 'i', |
|---|
| 50 |
METRIC_UINT32 = 'I', |
|---|
| 51 |
METRIC_INT64 = 'l', |
|---|
| 52 |
METRIC_UINT64 = 'L', |
|---|
| 53 |
METRIC_DOUBLE = 'n', |
|---|
| 54 |
METRIC_STRING = 's' |
|---|
| 55 |
} metric_type_t; |
|---|
| 56 |
|
|---|
| 57 |
typedef struct { |
|---|
| 58 |
char *metric_name; |
|---|
| 59 |
metric_type_t metric_type; |
|---|
| 60 |
union { |
|---|
| 61 |
double *n; |
|---|
| 62 |
int32_t *i; |
|---|
| 63 |
u_int32_t *I; |
|---|
| 64 |
int64_t *l; |
|---|
| 65 |
u_int64_t *L; |
|---|
| 66 |
char *s; |
|---|
| 67 |
void *vp; /* used for clever assignments */ |
|---|
| 68 |
} metric_value; |
|---|
| 69 |
} metric_t; |
|---|
| 70 |
|
|---|
| 71 |
typedef struct { |
|---|
| 72 |
struct timeval whence; |
|---|
| 73 |
int8_t available; |
|---|
| 74 |
int8_t state; |
|---|
| 75 |
u_int32_t duration; |
|---|
| 76 |
char *status; |
|---|
| 77 |
noit_hash_table metrics; |
|---|
| 78 |
} stats_t; |
|---|
| 79 |
|
|---|
| 80 |
typedef struct dep_list { |
|---|
| 81 |
struct noit_check *check; |
|---|
| 82 |
struct dep_list *next; |
|---|
| 83 |
} dep_list_t; |
|---|
| 84 |
|
|---|
| 85 |
typedef struct noit_check { |
|---|
| 86 |
uuid_t checkid; |
|---|
| 87 |
int8_t target_family; |
|---|
| 88 |
union { |
|---|
| 89 |
struct in_addr addr; |
|---|
| 90 |
struct in6_addr addr6; |
|---|
| 91 |
} target_addr; |
|---|
| 92 |
char *target; |
|---|
| 93 |
char *module; |
|---|
| 94 |
char *name; |
|---|
| 95 |
char *filterset; |
|---|
| 96 |
noit_hash_table *config; |
|---|
| 97 |
char *oncheck; /* target`name of the check that fires us */ |
|---|
| 98 |
u_int32_t period; /* period of checks in milliseconds */ |
|---|
| 99 |
u_int32_t timeout; /* timeout of check in milliseconds */ |
|---|
| 100 |
u_int32_t flags; /* NP_KILLED, NP_RUNNING */ |
|---|
| 101 |
|
|---|
| 102 |
dep_list_t *causal_checks; |
|---|
| 103 |
eventer_t fire_event; |
|---|
| 104 |
struct timeval last_fire_time; |
|---|
| 105 |
struct { |
|---|
| 106 |
stats_t current; |
|---|
| 107 |
stats_t previous; |
|---|
| 108 |
} stats; |
|---|
| 109 |
u_int32_t generation; /* This can roll, we don't care */ |
|---|
| 110 |
void *closure; |
|---|
| 111 |
} noit_check_t; |
|---|
| 112 |
|
|---|
| 113 |
#define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL) |
|---|
| 114 |
#define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED) |
|---|
| 115 |
#define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0) |
|---|
| 116 |
#define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING) |
|---|
| 117 |
#define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED) |
|---|
| 118 |
|
|---|
| 119 |
API_EXPORT(void) noit_poller_init(); |
|---|
| 120 |
API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */ |
|---|
| 121 |
API_EXPORT(void) noit_poller_process_checks(const char *xpath); |
|---|
| 122 |
API_EXPORT(void) noit_poller_make_causal_map(); |
|---|
| 123 |
|
|---|
| 124 |
API_EXPORT(void) |
|---|
| 125 |
noit_check_fake_last_check(noit_check_t *check, |
|---|
| 126 |
struct timeval *lc, struct timeval *_now); |
|---|
| 127 |
API_EXPORT(int) noit_check_max_initial_stutter(); |
|---|
| 128 |
|
|---|
| 129 |
API_EXPORT(int) |
|---|
| 130 |
noit_poller_schedule(const char *target, |
|---|
| 131 |
const char *module, |
|---|
| 132 |
const char *name, |
|---|
| 133 |
const char *filterset, |
|---|
| 134 |
noit_hash_table *config, |
|---|
| 135 |
u_int32_t period, |
|---|
| 136 |
u_int32_t timeout, |
|---|
| 137 |
const char *oncheck, |
|---|
| 138 |
int flags, |
|---|
| 139 |
uuid_t in, |
|---|
| 140 |
uuid_t out); |
|---|
| 141 |
|
|---|
| 142 |
API_EXPORT(int) |
|---|
| 143 |
noit_check_update(noit_check_t *new_check, |
|---|
| 144 |
const char *target, |
|---|
| 145 |
const char *name, |
|---|
| 146 |
const char *filterset, |
|---|
| 147 |
noit_hash_table *config, |
|---|
| 148 |
u_int32_t period, |
|---|
| 149 |
u_int32_t timeout, |
|---|
| 150 |
const char *oncheck, |
|---|
| 151 |
int flags); |
|---|
| 152 |
|
|---|
| 153 |
API_EXPORT(int) |
|---|
| 154 |
noit_poller_deschedule(uuid_t in); |
|---|
| 155 |
|
|---|
| 156 |
API_EXPORT(noit_check_t *) |
|---|
| 157 |
noit_poller_lookup(uuid_t in); |
|---|
| 158 |
|
|---|
| 159 |
API_EXPORT(noit_check_t *) |
|---|
| 160 |
noit_poller_lookup_by_name(char *target, char *name); |
|---|
| 161 |
|
|---|
| 162 |
API_EXPORT(void) |
|---|
| 163 |
noit_check_stats_clear(stats_t *s); |
|---|
| 164 |
|
|---|
| 165 |
struct _noit_module; |
|---|
| 166 |
API_EXPORT(void) |
|---|
| 167 |
noit_check_set_stats(struct _noit_module *self, noit_check_t *check, |
|---|
| 168 |
stats_t *newstate); |
|---|
| 169 |
|
|---|
| 170 |
API_EXPORT(void) |
|---|
| 171 |
noit_stats_set_metric(stats_t *, const char *, metric_type_t, void *); |
|---|
| 172 |
|
|---|
| 173 |
API_EXPORT(const char *) |
|---|
| 174 |
noit_check_available_string(int16_t available); |
|---|
| 175 |
API_EXPORT(const char *) |
|---|
| 176 |
noit_check_state_string(int16_t state); |
|---|
| 177 |
API_EXPORT(int) |
|---|
| 178 |
noit_stats_snprint_metric(char *b, int l, metric_t *m); |
|---|
| 179 |
|
|---|
| 180 |
/* These are from noit_check_log.c */ |
|---|
| 181 |
API_EXPORT(void) noit_check_log_check(noit_check_t *check); |
|---|
| 182 |
API_EXPORT(void) noit_check_log_status(noit_check_t *check); |
|---|
| 183 |
API_EXPORT(void) noit_check_log_metrics(noit_check_t *check); |
|---|
| 184 |
|
|---|
| 185 |
#endif |
|---|