| 1 |
/* |
|---|
| 2 |
* Copyright (c) 2007, OmniTI Computer Consulting, Inc. |
|---|
| 3 |
* All rights reserved. |
|---|
| 4 |
* |
|---|
| 5 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 6 |
* modification, are permitted provided that the following conditions are |
|---|
| 7 |
* met: |
|---|
| 8 |
* |
|---|
| 9 |
* * Redistributions of source code must retain the above copyright |
|---|
| 10 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 11 |
* * Redistributions in binary form must reproduce the above |
|---|
| 12 |
* copyright notice, this list of conditions and the following |
|---|
| 13 |
* disclaimer in the documentation and/or other materials provided |
|---|
| 14 |
* with the distribution. |
|---|
| 15 |
* * Neither the name OmniTI Computer Consulting, Inc. nor the names |
|---|
| 16 |
* of its contributors may be used to endorse or promote products |
|---|
| 17 |
* derived from this software without specific prior written |
|---|
| 18 |
* permission. |
|---|
| 19 |
* |
|---|
| 20 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 21 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 22 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 23 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 24 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 25 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 26 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 27 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 28 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 29 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 30 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 31 |
*/ |
|---|
| 32 |
|
|---|
| 33 |
#include "noit_defines.h" |
|---|
| 34 |
#include "dtrace_probes.h" |
|---|
| 35 |
|
|---|
| 36 |
#include <uuid/uuid.h> |
|---|
| 37 |
#include <netinet/in.h> |
|---|
| 38 |
|
|---|
| 39 |
#include "noit_check.h" |
|---|
| 40 |
#include "noit_filters.h" |
|---|
| 41 |
#include "utils/noit_log.h" |
|---|
| 42 |
#include "jlog/jlog.h" |
|---|
| 43 |
|
|---|
| 44 |
#include "bundle.pb-c.h" |
|---|
| 45 |
#include "noit_check_log_helpers.h" |
|---|
| 46 |
|
|---|
| 47 |
/* Log format is tab delimited: |
|---|
| 48 |
* NOIT CONFIG (implemented in noit_conf.c): |
|---|
| 49 |
* 'n' TIMESTAMP strlen(xmlconfig) base64(gzip(xmlconfig)) |
|---|
| 50 |
* |
|---|
| 51 |
* DELETE: |
|---|
| 52 |
* 'D' TIMESTAMP UUID NAME |
|---|
| 53 |
* |
|---|
| 54 |
* CHECK: |
|---|
| 55 |
* 'C' TIMESTAMP UUID TARGET MODULE NAME |
|---|
| 56 |
* |
|---|
| 57 |
* STATUS: |
|---|
| 58 |
* 'S' TIMESTAMP UUID STATE AVAILABILITY DURATION STATUS_MESSAGE |
|---|
| 59 |
* |
|---|
| 60 |
* METRICS: |
|---|
| 61 |
* 'M' TIMESTAMP UUID NAME TYPE VALUE |
|---|
| 62 |
* |
|---|
| 63 |
* BUNDLE |
|---|
| 64 |
* 'B#' TIMESTAMP UUID TARGET MODULE NAME strlen(base64(gzipped(payload))) base64(gzipped(payload)) |
|---|
| 65 |
* |
|---|
| 66 |
*/ |
|---|
| 67 |
|
|---|
| 68 |
static noit_log_stream_t check_log = NULL; |
|---|
| 69 |
static noit_log_stream_t status_log = NULL; |
|---|
| 70 |
static noit_log_stream_t metrics_log = NULL; |
|---|
| 71 |
static noit_log_stream_t delete_log = NULL; |
|---|
| 72 |
static noit_log_stream_t bundle_log = NULL; |
|---|
| 73 |
|
|---|
| 74 |
#define SECPART(a) ((unsigned long)(a)->tv_sec) |
|---|
| 75 |
#define MSECPART(a) ((unsigned long)((a)->tv_usec / 1000)) |
|---|
| 76 |
#define MAKE_CHECK_UUID_STR(uuid_str, len, ls, check) do { \ |
|---|
| 77 |
noit_boolean extended_id = noit_false; \ |
|---|
| 78 |
const char *v; \ |
|---|
| 79 |
v = noit_log_stream_get_property(ls, "extended_id"); \ |
|---|
| 80 |
if(v && !strcmp(v, "on")) extended_id = noit_true; \ |
|---|
| 81 |
uuid_str[0] = '\0'; \ |
|---|
| 82 |
if(extended_id) { \ |
|---|
| 83 |
strlcat(uuid_str, check->target, len-37); \ |
|---|
| 84 |
strlcat(uuid_str, "`", len-37); \ |
|---|
| 85 |
strlcat(uuid_str, check->module, len-37); \ |
|---|
| 86 |
strlcat(uuid_str, "`", len-37); \ |
|---|
| 87 |
strlcat(uuid_str, check->name, len-37); \ |
|---|
| 88 |
strlcat(uuid_str, "`", len-37); \ |
|---|
| 89 |
} \ |
|---|
| 90 |
uuid_unparse_lower(check->checkid, uuid_str + strlen(uuid_str)); \ |
|---|
| 91 |
} while(0) |
|---|
| 92 |
|
|---|
| 93 |
static void |
|---|
| 94 |
handle_extra_feeds(noit_check_t *check, |
|---|
| 95 |
int (*log_f)(noit_log_stream_t ls, noit_check_t *check)) { |
|---|
| 96 |
noit_log_stream_t ls; |
|---|
| 97 |
noit_skiplist_node *curr, *next; |
|---|
| 98 |
const char *feed_name; |
|---|
| 99 |
|
|---|
| 100 |
if(!check->feeds) return; |
|---|
| 101 |
curr = next = noit_skiplist_getlist(check->feeds); |
|---|
| 102 |
while(curr) { |
|---|
| 103 |
/* We advance next here (before we try to use curr). |
|---|
| 104 |
* We may need to remove the node we're looking at and that would |
|---|
| 105 |
* disturb the iterator, so advance in advance. */ |
|---|
| 106 |
noit_skiplist_next(check->feeds, &next); |
|---|
| 107 |
feed_name = (char *)curr->data; |
|---|
| 108 |
ls = noit_log_stream_find(feed_name); |
|---|
| 109 |
if(!ls || log_f(ls, check)) { |
|---|
| 110 |
noit_check_transient_remove_feed(check, feed_name); |
|---|
| 111 |
/* noit_skiplisti_remove(check->feeds, curr, free); */ |
|---|
| 112 |
} |
|---|
| 113 |
curr = next; |
|---|
| 114 |
} |
|---|
| 115 |
/* We're done... we may have destroyed the last feed. |
|---|
| 116 |
* that combined with transience means we should kill the check */ |
|---|
| 117 |
/* noit_check_transient_remove_feed(check, NULL); */ |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
static int |
|---|
| 121 |
_noit_check_log_delete(noit_log_stream_t ls, |
|---|
| 122 |
noit_check_t *check) { |
|---|
| 123 |
stats_t *c; |
|---|
| 124 |
char uuid_str[256*3+37]; |
|---|
| 125 |
SETUP_LOG(delete, ); |
|---|
| 126 |
MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), status_log, check); |
|---|
| 127 |
|
|---|
| 128 |
c = &check->stats.current; |
|---|
| 129 |
return noit_log(ls, &c->whence, __FILE__, __LINE__, |
|---|
| 130 |
"D\t%lu.%03lu\t%s\t%s\n", |
|---|
| 131 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, check->name); |
|---|
| 132 |
} |
|---|
| 133 |
void |
|---|
| 134 |
noit_check_log_delete(noit_check_t *check) { |
|---|
| 135 |
if(!(check->flags & NP_TRANSIENT)) { |
|---|
| 136 |
handle_extra_feeds(check, _noit_check_log_delete); |
|---|
| 137 |
SETUP_LOG(delete, return); |
|---|
| 138 |
_noit_check_log_delete(delete_log, check); |
|---|
| 139 |
} |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
static int |
|---|
| 143 |
_noit_check_log_check(noit_log_stream_t ls, |
|---|
| 144 |
noit_check_t *check) { |
|---|
| 145 |
struct timeval __now; |
|---|
| 146 |
char uuid_str[256*3+37]; |
|---|
| 147 |
SETUP_LOG(check, ); |
|---|
| 148 |
MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), check_log, check); |
|---|
| 149 |
|
|---|
| 150 |
gettimeofday(&__now, NULL); |
|---|
| 151 |
return noit_log(ls, &__now, __FILE__, __LINE__, |
|---|
| 152 |
"C\t%lu.%03lu\t%s\t%s\t%s\t%s\n", |
|---|
| 153 |
SECPART(&__now), MSECPART(&__now), |
|---|
| 154 |
uuid_str, check->target, check->module, check->name); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
void |
|---|
| 158 |
noit_check_log_check(noit_check_t *check) { |
|---|
| 159 |
if(!(check->flags & NP_TRANSIENT)) { |
|---|
| 160 |
handle_extra_feeds(check, _noit_check_log_check); |
|---|
| 161 |
SETUP_LOG(check, return); |
|---|
| 162 |
_noit_check_log_check(check_log, check); |
|---|
| 163 |
} |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
static int |
|---|
| 167 |
_noit_check_log_status(noit_log_stream_t ls, |
|---|
| 168 |
noit_check_t *check) { |
|---|
| 169 |
stats_t *c; |
|---|
| 170 |
char uuid_str[256*3+37]; |
|---|
| 171 |
SETUP_LOG(status, ); |
|---|
| 172 |
MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), status_log, check); |
|---|
| 173 |
|
|---|
| 174 |
c = &check->stats.current; |
|---|
| 175 |
return noit_log(ls, &c->whence, __FILE__, __LINE__, |
|---|
| 176 |
"S\t%lu.%03lu\t%s\t%c\t%c\t%d\t%s\n", |
|---|
| 177 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 178 |
(char)c->state, (char)c->available, c->duration, c->status); |
|---|
| 179 |
} |
|---|
| 180 |
void |
|---|
| 181 |
noit_check_log_status(noit_check_t *check) { |
|---|
| 182 |
handle_extra_feeds(check, _noit_check_log_status); |
|---|
| 183 |
if(!(check->flags & (NP_TRANSIENT | NP_SUPPRESS_STATUS))) { |
|---|
| 184 |
SETUP_LOG(status, return); |
|---|
| 185 |
_noit_check_log_status(status_log, check); |
|---|
| 186 |
} |
|---|
| 187 |
} |
|---|
| 188 |
static int |
|---|
| 189 |
_noit_check_log_metric(noit_log_stream_t ls, noit_check_t *check, |
|---|
| 190 |
const char *uuid_str, |
|---|
| 191 |
struct timeval *whence, metric_t *m) { |
|---|
| 192 |
char our_uuid_str[256*3+37]; |
|---|
| 193 |
int srv = 0; |
|---|
| 194 |
if(!noit_apply_filterset(check->filterset, check, m)) return 0; |
|---|
| 195 |
if(!ls->enabled) return 0; |
|---|
| 196 |
|
|---|
| 197 |
if(!uuid_str) { |
|---|
| 198 |
MAKE_CHECK_UUID_STR(our_uuid_str, sizeof(our_uuid_str), metrics_log, check); |
|---|
| 199 |
uuid_str = our_uuid_str; |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
if(!m->metric_value.s) { /* they are all null */ |
|---|
| 203 |
srv = noit_log(ls, whence, __FILE__, __LINE__, |
|---|
| 204 |
"M\t%lu.%03lu\t%s\t%s\t%c\t[[null]]\n", |
|---|
| 205 |
SECPART(whence), MSECPART(whence), uuid_str, |
|---|
| 206 |
m->metric_name, m->metric_type); |
|---|
| 207 |
} |
|---|
| 208 |
else { |
|---|
| 209 |
switch(m->metric_type) { |
|---|
| 210 |
case METRIC_INT32: |
|---|
| 211 |
srv = noit_log(ls, whence, __FILE__, __LINE__, |
|---|
| 212 |
"M\t%lu.%03lu\t%s\t%s\t%c\t%d\n", |
|---|
| 213 |
SECPART(whence), MSECPART(whence), uuid_str, |
|---|
| 214 |
m->metric_name, m->metric_type, *(m->metric_value.i)); |
|---|
| 215 |
break; |
|---|
| 216 |
case METRIC_UINT32: |
|---|
| 217 |
srv = noit_log(ls, whence, __FILE__, __LINE__, |
|---|
| 218 |
"M\t%lu.%03lu\t%s\t%s\t%c\t%u\n", |
|---|
| 219 |
SECPART(whence), MSECPART(whence), uuid_str, |
|---|
| 220 |
m->metric_name, m->metric_type, *(m->metric_value.I)); |
|---|
| 221 |
break; |
|---|
| 222 |
case METRIC_INT64: |
|---|
| 223 |
srv = noit_log(ls, whence, __FILE__, __LINE__, |
|---|
| 224 |
"M\t%lu.%03lu\t%s\t%s\t%c\t%lld\n", |
|---|
| 225 |
SECPART(whence), MSECPART(whence), uuid_str, |
|---|
| 226 |
m->metric_name, m->metric_type, |
|---|
| 227 |
(long long int)*(m->metric_value.l)); |
|---|
| 228 |
break; |
|---|
| 229 |
case METRIC_UINT64: |
|---|
| 230 |
srv = noit_log(ls, whence, __FILE__, __LINE__, |
|---|
| 231 |
"M\t%lu.%03lu\t%s\t%s\t%c\t%llu\n", |
|---|
| 232 |
SECPART(whence), MSECPART(whence), uuid_str, |
|---|
| 233 |
m->metric_name, m->metric_type, |
|---|
| 234 |
(long long unsigned int)*(m->metric_value.L)); |
|---|
| 235 |
break; |
|---|
| 236 |
case METRIC_DOUBLE: |
|---|
| 237 |
srv = noit_log(ls, whence, __FILE__, __LINE__, |
|---|
| 238 |
"M\t%lu.%03lu\t%s\t%s\t%c\t%.12e\n", |
|---|
| 239 |
SECPART(whence), MSECPART(whence), uuid_str, |
|---|
| 240 |
m->metric_name, m->metric_type, *(m->metric_value.n)); |
|---|
| 241 |
break; |
|---|
| 242 |
case METRIC_STRING: |
|---|
| 243 |
srv = noit_log(ls, whence, __FILE__, __LINE__, |
|---|
| 244 |
"M\t%lu.%03lu\t%s\t%s\t%c\t%s\n", |
|---|
| 245 |
SECPART(whence), MSECPART(whence), uuid_str, |
|---|
| 246 |
m->metric_name, m->metric_type, m->metric_value.s); |
|---|
| 247 |
break; |
|---|
| 248 |
default: |
|---|
| 249 |
noitL(noit_error, "Unknown metric type '%c' 0x%x\n", |
|---|
| 250 |
m->metric_type, m->metric_type); |
|---|
| 251 |
} |
|---|
| 252 |
} |
|---|
| 253 |
return srv; |
|---|
| 254 |
} |
|---|
| 255 |
static int |
|---|
| 256 |
_noit_check_log_metrics(noit_log_stream_t ls, noit_check_t *check) { |
|---|
| 257 |
int rv = 0; |
|---|
| 258 |
int srv; |
|---|
| 259 |
char uuid_str[256*3+37]; |
|---|
| 260 |
noit_hash_iter iter = NOIT_HASH_ITER_ZERO; |
|---|
| 261 |
const char *key; |
|---|
| 262 |
int klen; |
|---|
| 263 |
stats_t *c; |
|---|
| 264 |
void *vm; |
|---|
| 265 |
SETUP_LOG(metrics, ); |
|---|
| 266 |
MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), metrics_log, check); |
|---|
| 267 |
|
|---|
| 268 |
c = &check->stats.current; |
|---|
| 269 |
while(noit_hash_next(&c->metrics, &iter, &key, &klen, &vm)) { |
|---|
| 270 |
/* If we apply the filter set and it returns false, we don't log */ |
|---|
| 271 |
metric_t *m = (metric_t *)vm; |
|---|
| 272 |
srv = _noit_check_log_metric(ls, check, uuid_str, &c->whence, m); |
|---|
| 273 |
if(srv) rv = srv; |
|---|
| 274 |
} |
|---|
| 275 |
return rv; |
|---|
| 276 |
} |
|---|
| 277 |
void |
|---|
| 278 |
noit_check_log_metrics(noit_check_t *check) { |
|---|
| 279 |
handle_extra_feeds(check, _noit_check_log_metrics); |
|---|
| 280 |
if(!(check->flags & (NP_TRANSIENT | NP_SUPPRESS_METRICS))) { |
|---|
| 281 |
SETUP_LOG(metrics, return); |
|---|
| 282 |
_noit_check_log_metrics(metrics_log, check); |
|---|
| 283 |
} |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
static int |
|---|
| 288 |
_noit_check_log_bundle_metric(noit_log_stream_t ls, Metric *metric, metric_t *m) { |
|---|
| 289 |
metric->metrictype = (int)m->metric_type; |
|---|
| 290 |
|
|---|
| 291 |
metric->name = m->metric_name; |
|---|
| 292 |
if(m->metric_value.vp != NULL) { |
|---|
| 293 |
switch (m->metric_type) { |
|---|
| 294 |
case METRIC_INT32: |
|---|
| 295 |
metric->has_valuei32 = noit_true; |
|---|
| 296 |
metric->valuei32 = *(m->metric_value.i); break; |
|---|
| 297 |
case METRIC_UINT32: |
|---|
| 298 |
metric->has_valueui32 = noit_true; |
|---|
| 299 |
metric->valueui32 = *(m->metric_value.I); break; |
|---|
| 300 |
case METRIC_INT64: |
|---|
| 301 |
metric->has_valuei64 = noit_true; |
|---|
| 302 |
metric->valuei64 = *(m->metric_value.l); break; |
|---|
| 303 |
case METRIC_UINT64: |
|---|
| 304 |
metric->has_valueui64 = noit_true; |
|---|
| 305 |
metric->valueui64 = *(m->metric_value.L); break; |
|---|
| 306 |
case METRIC_DOUBLE: |
|---|
| 307 |
metric->has_valuedbl = noit_true; |
|---|
| 308 |
metric->valuedbl = *(m->metric_value.n); break; |
|---|
| 309 |
case METRIC_STRING: |
|---|
| 310 |
metric->valuestr = m->metric_value.s; break; |
|---|
| 311 |
default: |
|---|
| 312 |
return -1; |
|---|
| 313 |
} |
|---|
| 314 |
} |
|---|
| 315 |
return 0; |
|---|
| 316 |
} |
|---|
| 317 |
|
|---|
| 318 |
static int |
|---|
| 319 |
noit_check_log_bundle_serialize(noit_log_stream_t ls, noit_check_t *check) { |
|---|
| 320 |
int rv = 0; |
|---|
| 321 |
char uuid_str[256*3+37]; |
|---|
| 322 |
noit_hash_iter iter = NOIT_HASH_ITER_ZERO; |
|---|
| 323 |
noit_hash_iter iter2 = NOIT_HASH_ITER_ZERO; |
|---|
| 324 |
const char *key; |
|---|
| 325 |
int klen, i=0, size, j; |
|---|
| 326 |
unsigned int out_size; |
|---|
| 327 |
stats_t *c; |
|---|
| 328 |
void *vm; |
|---|
| 329 |
char *buf, *out_buf; |
|---|
| 330 |
noit_compression_type_t comp; |
|---|
| 331 |
Bundle bundle = BUNDLE__INIT; |
|---|
| 332 |
SETUP_LOG(bundle, ); |
|---|
| 333 |
MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), bundle_log, check); |
|---|
| 334 |
noit_boolean use_compression = noit_true; |
|---|
| 335 |
const char *v_comp; |
|---|
| 336 |
v_comp = noit_log_stream_get_property(ls, "compression"); |
|---|
| 337 |
if(v_comp && !strcmp(v_comp, "off")) use_compression = noit_false; |
|---|
| 338 |
|
|---|
| 339 |
// Get a bundle |
|---|
| 340 |
c = &check->stats.current; |
|---|
| 341 |
|
|---|
| 342 |
// Set attributes |
|---|
| 343 |
bundle.status = malloc(sizeof(Status)); |
|---|
| 344 |
status__init(bundle.status); |
|---|
| 345 |
bundle.status->available = c->available; |
|---|
| 346 |
bundle.status->state = c->state; |
|---|
| 347 |
bundle.status->duration = c->duration; |
|---|
| 348 |
bundle.status->status = c->status; |
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
// Just count |
|---|
| 352 |
while(noit_hash_next(&c->metrics, &iter, &key, &klen, &vm)) { |
|---|
| 353 |
bundle.n_metrics++; |
|---|
| 354 |
} |
|---|
| 355 |
|
|---|
| 356 |
if(bundle.n_metrics > 0) { |
|---|
| 357 |
bundle.metrics = malloc(bundle.n_metrics * sizeof(Metric*)); |
|---|
| 358 |
|
|---|
| 359 |
// Now convert |
|---|
| 360 |
while(noit_hash_next(&c->metrics, &iter2, &key, &klen, &vm)) { |
|---|
| 361 |
/* If we apply the filter set and it returns false, we don't log */ |
|---|
| 362 |
metric_t *m = (metric_t *)vm; |
|---|
| 363 |
if(!noit_apply_filterset(check->filterset, check, m)) continue; |
|---|
| 364 |
bundle.metrics[i] = malloc(sizeof(Metric)); |
|---|
| 365 |
metric__init(bundle.metrics[i]); |
|---|
| 366 |
_noit_check_log_bundle_metric(ls, bundle.metrics[i], m); |
|---|
| 367 |
if(NOIT_CHECK_METRIC_ENABLED()) { |
|---|
| 368 |
char buff[256]; |
|---|
| 369 |
noit_stats_snprint_metric(buff, sizeof(buff), m); |
|---|
| 370 |
NOIT_CHECK_METRIC(uuid_str, check->module, check->name, check->target, |
|---|
| 371 |
m->metric_name, m->metric_type, buff); |
|---|
| 372 |
} |
|---|
| 373 |
i++; |
|---|
| 374 |
} |
|---|
| 375 |
bundle.n_metrics = i; |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
size = bundle__get_packed_size(&bundle); |
|---|
| 379 |
buf = malloc(size); |
|---|
| 380 |
bundle__pack(&bundle, (uint8_t*)buf); |
|---|
| 381 |
|
|---|
| 382 |
// Compress + B64 |
|---|
| 383 |
comp = use_compression ? NOIT_COMPRESS_ZLIB : NOIT_COMPRESS_NONE; |
|---|
| 384 |
noit_check_log_bundle_compress_b64(comp, buf, size, &out_buf, &out_size); |
|---|
| 385 |
rv = noit_log(ls, &(c->whence), __FILE__, __LINE__, |
|---|
| 386 |
"B%c\t%lu.%03lu\t%s\t%s\t%s\t%s\t%d\t%.*s\n", |
|---|
| 387 |
use_compression ? '1' : '2', |
|---|
| 388 |
SECPART(&(c->whence)), MSECPART(&(c->whence)), |
|---|
| 389 |
uuid_str, check->target, check->module, check->name, size, |
|---|
| 390 |
(unsigned int)out_size, out_buf); |
|---|
| 391 |
|
|---|
| 392 |
free(buf); |
|---|
| 393 |
free(out_buf); |
|---|
| 394 |
// Free all the resources |
|---|
| 395 |
for (j=0; j<i; j++) { |
|---|
| 396 |
free(bundle.metrics[j]); |
|---|
| 397 |
} |
|---|
| 398 |
free(bundle.metrics); |
|---|
| 399 |
free(bundle.status); |
|---|
| 400 |
return rv; |
|---|
| 401 |
} |
|---|
| 402 |
|
|---|
| 403 |
void |
|---|
| 404 |
noit_check_log_bundle(noit_check_t *check) { |
|---|
| 405 |
handle_extra_feeds(check, noit_check_log_bundle_serialize); |
|---|
| 406 |
if(!(check->flags & (NP_TRANSIENT | NP_SUPPRESS_STATUS | NP_SUPPRESS_METRICS))) { |
|---|
| 407 |
SETUP_LOG(bundle, return); |
|---|
| 408 |
noit_check_log_bundle_serialize(bundle_log, check); |
|---|
| 409 |
} |
|---|
| 410 |
} |
|---|
| 411 |
|
|---|
| 412 |
void |
|---|
| 413 |
noit_check_log_metric(noit_check_t *check, struct timeval *whence, |
|---|
| 414 |
metric_t *m) { |
|---|
| 415 |
char uuid_str[256*3+37]; |
|---|
| 416 |
MAKE_CHECK_UUID_STR(uuid_str, sizeof(uuid_str), metrics_log, check); |
|---|
| 417 |
|
|---|
| 418 |
/* handle feeds -- hust like handle_extra_feeds, but this |
|---|
| 419 |
* is with different arguments. |
|---|
| 420 |
*/ |
|---|
| 421 |
if(check->feeds) { |
|---|
| 422 |
noit_skiplist_node *curr, *next; |
|---|
| 423 |
curr = next = noit_skiplist_getlist(check->feeds); |
|---|
| 424 |
while(curr) { |
|---|
| 425 |
const char *feed_name = (char *)curr->data; |
|---|
| 426 |
noit_log_stream_t ls = noit_log_stream_find(feed_name); |
|---|
| 427 |
noit_skiplist_next(check->feeds, &next); |
|---|
| 428 |
if(!ls || _noit_check_log_metric(ls, check, uuid_str, whence, m)) |
|---|
| 429 |
noit_check_transient_remove_feed(check, feed_name); |
|---|
| 430 |
curr = next; |
|---|
| 431 |
} |
|---|
| 432 |
} |
|---|
| 433 |
if(!(check->flags & NP_TRANSIENT)) { |
|---|
| 434 |
SETUP_LOG(metrics, return); |
|---|
| 435 |
_noit_check_log_metric(metrics_log, check, uuid_str, whence, m); |
|---|
| 436 |
if(NOIT_CHECK_METRIC_ENABLED()) { |
|---|
| 437 |
char buff[256]; |
|---|
| 438 |
noit_stats_snprint_metric(buff, sizeof(buff), m); |
|---|
| 439 |
NOIT_CHECK_METRIC(uuid_str, check->module, check->name, check->target, |
|---|
| 440 |
m->metric_name, m->metric_type, buff); |
|---|
| 441 |
} |
|---|
| 442 |
} |
|---|
| 443 |
} |
|---|
| 444 |
|
|---|
| 445 |
int |
|---|
| 446 |
noit_stats_snprint_metric(char *b, int l, metric_t *m) { |
|---|
| 447 |
int rv, nl; |
|---|
| 448 |
nl = snprintf(b, l, "%s[%c] = ", m->metric_name, m->metric_type); |
|---|
| 449 |
if(nl >= l || nl <= 0) return nl; |
|---|
| 450 |
rv = noit_stats_snprint_metric_value(b+nl, l-nl, m); |
|---|
| 451 |
if(rv == -1) |
|---|
| 452 |
rv = snprintf(b+nl, l-nl, "[[unknown type]]"); |
|---|
| 453 |
return rv + nl; |
|---|
| 454 |
} |
|---|
| 455 |
|
|---|