| 1 |
/* |
|---|
| 2 |
* Copyright (c) 2007, OmniTI Computer Consulting, Inc. |
|---|
| 3 |
* All rights reserved. |
|---|
| 4 |
*/ |
|---|
| 5 |
|
|---|
| 6 |
#include "noit_defines.h" |
|---|
| 7 |
|
|---|
| 8 |
#include <uuid/uuid.h> |
|---|
| 9 |
#include <netinet/in.h> |
|---|
| 10 |
|
|---|
| 11 |
#include "noit_check.h" |
|---|
| 12 |
#include "utils/noit_log.h" |
|---|
| 13 |
#include "jlog/jlog.h" |
|---|
| 14 |
|
|---|
| 15 |
/* Log format is tab delimited: |
|---|
| 16 |
* |
|---|
| 17 |
* CHECK: |
|---|
| 18 |
* 'C' TIMESTAMP UUID TARGET MODULE NAME |
|---|
| 19 |
* |
|---|
| 20 |
* STATUS: |
|---|
| 21 |
* 'S' TIMESTAMP UUID STATE AVAILABILITY DURATION STATUS_MESSAGE |
|---|
| 22 |
* |
|---|
| 23 |
* METRICS: |
|---|
| 24 |
* 'M' TIMESTAMP UUID NAME TYPE VALUE |
|---|
| 25 |
*/ |
|---|
| 26 |
|
|---|
| 27 |
static noit_log_stream_t check_log = NULL; |
|---|
| 28 |
static noit_log_stream_t status_log = NULL; |
|---|
| 29 |
static noit_log_stream_t metrics_log = NULL; |
|---|
| 30 |
#define SETUP_LOG(a) do { if(!a##_log) a##_log = noit_log_stream_find(#a); \ |
|---|
| 31 |
if(!a##_log) return; } while(0) |
|---|
| 32 |
#define SECPART(a) ((unsigned long)(a)->tv_sec) |
|---|
| 33 |
#define MSECPART(a) ((unsigned long)((a)->tv_usec / 1000)) |
|---|
| 34 |
void |
|---|
| 35 |
noit_check_log_check(noit_check_t *check) { |
|---|
| 36 |
struct timeval __now; |
|---|
| 37 |
char uuid_str[37]; |
|---|
| 38 |
SETUP_LOG(check); |
|---|
| 39 |
|
|---|
| 40 |
gettimeofday(&__now, NULL); |
|---|
| 41 |
uuid_unparse_lower(check->checkid, uuid_str); |
|---|
| 42 |
noitL(check_log, "C\t%lu.%03lu\t%s\t%s\t%s\t%s\n", |
|---|
| 43 |
SECPART(&__now), MSECPART(&__now), uuid_str, |
|---|
| 44 |
check->target, check->module, check->name); |
|---|
| 45 |
} |
|---|
| 46 |
void |
|---|
| 47 |
noit_check_log_status(noit_check_t *check) { |
|---|
| 48 |
char uuid_str[37]; |
|---|
| 49 |
stats_t *c; |
|---|
| 50 |
SETUP_LOG(status); |
|---|
| 51 |
|
|---|
| 52 |
uuid_unparse_lower(check->checkid, uuid_str); |
|---|
| 53 |
c = &check->stats.current; |
|---|
| 54 |
noitL(status_log, "S\t%lu.%03lu\t%s\t%c\t%c\t%d\t%s\n", |
|---|
| 55 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 56 |
(char)c->state, (char)c->available, c->duration, c->status); |
|---|
| 57 |
} |
|---|
| 58 |
void |
|---|
| 59 |
noit_check_log_metrics(noit_check_t *check) { |
|---|
| 60 |
char uuid_str[37]; |
|---|
| 61 |
noit_hash_iter iter = NOIT_HASH_ITER_ZERO; |
|---|
| 62 |
const char *key; |
|---|
| 63 |
int klen; |
|---|
| 64 |
metric_t *m; |
|---|
| 65 |
stats_t *c; |
|---|
| 66 |
SETUP_LOG(metrics); |
|---|
| 67 |
|
|---|
| 68 |
uuid_unparse_lower(check->checkid, uuid_str); |
|---|
| 69 |
c = &check->stats.current; |
|---|
| 70 |
while(noit_hash_next(&c->metrics, &iter, &key, &klen, (void **)&m)) { |
|---|
| 71 |
if(!m->metric_value.s) { /* they are all null */ |
|---|
| 72 |
noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t[[null]]\n", |
|---|
| 73 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 74 |
m->metric_name, m->metric_type); |
|---|
| 75 |
} |
|---|
| 76 |
else { |
|---|
| 77 |
switch(m->metric_type) { |
|---|
| 78 |
case METRIC_INT32: |
|---|
| 79 |
noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%d\n", |
|---|
| 80 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 81 |
m->metric_name, m->metric_type, *(m->metric_value.i)); |
|---|
| 82 |
break; |
|---|
| 83 |
case METRIC_UINT32: |
|---|
| 84 |
noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%u\n", |
|---|
| 85 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 86 |
m->metric_name, m->metric_type, *(m->metric_value.I)); |
|---|
| 87 |
break; |
|---|
| 88 |
case METRIC_INT64: |
|---|
| 89 |
noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%lld\n", |
|---|
| 90 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 91 |
m->metric_name, m->metric_type, *(m->metric_value.l)); |
|---|
| 92 |
break; |
|---|
| 93 |
case METRIC_UINT64: |
|---|
| 94 |
noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%llu\n", |
|---|
| 95 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 96 |
m->metric_name, m->metric_type, *(m->metric_value.L)); |
|---|
| 97 |
break; |
|---|
| 98 |
case METRIC_DOUBLE: |
|---|
| 99 |
noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%.12e\n", |
|---|
| 100 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 101 |
m->metric_name, m->metric_type, *(m->metric_value.n)); |
|---|
| 102 |
break; |
|---|
| 103 |
case METRIC_STRING: |
|---|
| 104 |
noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%s\n", |
|---|
| 105 |
SECPART(&c->whence), MSECPART(&c->whence), uuid_str, |
|---|
| 106 |
m->metric_name, m->metric_type, m->metric_value.s); |
|---|
| 107 |
break; |
|---|
| 108 |
default: |
|---|
| 109 |
noitL(noit_error, "Unknown metric type '%c' 0x%x\n", |
|---|
| 110 |
m->metric_type, m->metric_type); |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|