root/src/noit_check.h

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

support 'no check' on console to delete checks as well as 'reload' on console (currently only reloads checks)

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