root/src/noit_check.h

Revision 646e6d20498ab1b500fe30137a5541534219618b, 4.3 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

change the availability stuff to be characters

  • 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 struct {
48   char *metric_name;
49   enum { METRIC_INT, METRIC_FLOAT, METRIC_STRING } metric_type;
50   union {
51     float *f;
52     int *i;
53     char *s;
54   } metric_value;
55 } metric_t;
56
57 typedef struct {
58   struct timeval whence;
59   int8_t available;
60   int8_t state;
61   u_int32_t duration;
62   char *status;
63   noit_hash_table metrics;
64 } stats_t;
65
66 typedef struct dep_list {
67   struct noit_check *check;
68   struct dep_list *next;
69 } dep_list_t;
70
71 typedef struct noit_check {
72   uuid_t checkid;
73   int8_t target_family;
74   union {
75     struct in_addr addr;
76     struct in6_addr addr6;
77   } target_addr;
78   char *target;
79   char *module;
80   char *name;
81   noit_hash_table *config;
82   char *oncheck;               /* target`name of the check that fires us */
83   u_int32_t period;            /* period of checks in milliseconds */
84   u_int32_t timeout;           /* timeout of check in milliseconds */
85   u_int32_t flags;             /* NP_KILLED, NP_RUNNING */
86
87   dep_list_t *causal_checks;
88   eventer_t fire_event;
89   struct timeval last_fire_time;
90   struct {
91     stats_t current;
92     stats_t previous;
93   } stats;
94   u_int32_t generation;        /* This can roll, we don't care */
95   void *closure;
96 } noit_check_t;
97
98 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
99 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
100 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
101 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
102 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
103
104 API_EXPORT(void) noit_poller_init();
105 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
106 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
107 API_EXPORT(void) noit_poller_make_causal_map();
108
109 API_EXPORT(void)
110   noit_check_fake_last_check(noit_check_t *check,
111                              struct timeval *lc, struct timeval *_now);
112 API_EXPORT(int) noit_check_max_initial_stutter();
113
114 API_EXPORT(int)
115   noit_poller_schedule(const char *target,
116                        const char *module,
117                        const char *name,
118                        noit_hash_table *config,
119                        u_int32_t period,
120                        u_int32_t timeout,
121                        const char *oncheck,
122                        int flags,
123                        uuid_t in,
124                        uuid_t out);
125
126 API_EXPORT(int)
127   noit_check_update(noit_check_t *new_check,
128                     const char *target,
129                     const char *name,
130                     noit_hash_table *config,
131                     u_int32_t period,
132                     u_int32_t timeout,
133                     const char *oncheck,
134                     int flags);
135
136 API_EXPORT(int)
137   noit_poller_deschedule(uuid_t in);
138
139 API_EXPORT(noit_check_t *)
140   noit_poller_lookup(uuid_t in);
141
142 API_EXPORT(noit_check_t *)
143   noit_poller_lookup_by_name(char *target, char *name);
144
145 API_EXPORT(void)
146   noit_check_stats_clear(stats_t *s);
147
148 struct _noit_module;
149 API_EXPORT(void)
150   noit_check_set_stats(struct _noit_module *self, noit_check_t *check,
151                         stats_t *newstate);
152
153 API_EXPORT(void)
154   noit_stats_set_metric_int(stats_t *newstate, char *name, int *value);
155 API_EXPORT(void)
156   noit_stats_set_metric_float(stats_t *newstate, char *name, float *value);
157 API_EXPORT(void)
158   noit_stats_set_metric_string(stats_t *newstate, char *name, char *value);
159
160 #endif
Note: See TracBrowser for help on using the browser.