root/src/noit_check.h

Revision 7b927621aa1d1fb7e9e915e74ab2a86ce90f73ac, 4.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

make the metrics stuff more flexible, setup check/status/metrics logging.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _NOIT_POLLER_H
7 #define _NOIT_POLLER_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   noit_hash_table *config;
96   char *oncheck;               /* target`name of the check that fires us */
97   u_int32_t period;            /* period of checks in milliseconds */
98   u_int32_t timeout;           /* timeout of check in milliseconds */
99   u_int32_t flags;             /* NP_KILLED, NP_RUNNING */
100
101   dep_list_t *causal_checks;
102   eventer_t fire_event;
103   struct timeval last_fire_time;
104   struct {
105     stats_t current;
106     stats_t previous;
107   } stats;
108   u_int32_t generation;        /* This can roll, we don't care */
109   void *closure;
110 } noit_check_t;
111
112 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
113 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
114 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
115 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
116 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
117
118 API_EXPORT(void) noit_poller_init();
119 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
120 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
121 API_EXPORT(void) noit_poller_make_causal_map();
122
123 API_EXPORT(void)
124   noit_check_fake_last_check(noit_check_t *check,
125                              struct timeval *lc, struct timeval *_now);
126 API_EXPORT(int) noit_check_max_initial_stutter();
127
128 API_EXPORT(int)
129   noit_poller_schedule(const char *target,
130                        const char *module,
131                        const char *name,
132                        noit_hash_table *config,
133                        u_int32_t period,
134                        u_int32_t timeout,
135                        const char *oncheck,
136                        int flags,
137                        uuid_t in,
138                        uuid_t out);
139
140 API_EXPORT(int)
141   noit_check_update(noit_check_t *new_check,
142                     const char *target,
143                     const char *name,
144                     noit_hash_table *config,
145                     u_int32_t period,
146                     u_int32_t timeout,
147                     const char *oncheck,
148                     int flags);
149
150 API_EXPORT(int)
151   noit_poller_deschedule(uuid_t in);
152
153 API_EXPORT(noit_check_t *)
154   noit_poller_lookup(uuid_t in);
155
156 API_EXPORT(noit_check_t *)
157   noit_poller_lookup_by_name(char *target, char *name);
158
159 API_EXPORT(void)
160   noit_check_stats_clear(stats_t *s);
161
162 struct _noit_module;
163 API_EXPORT(void)
164   noit_check_set_stats(struct _noit_module *self, noit_check_t *check,
165                         stats_t *newstate);
166
167 API_EXPORT(void)
168   noit_stats_set_metric(stats_t *, char *, metric_type_t, void *);
169
170 /* These are from noit_check_log.c */
171 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
172 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
173 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
174
175 #endif
Note: See TracBrowser for help on using the browser.