add hostname to health errors
Costa Tsaousis (ktsaou) committed
Feb 24, 2017 at 23:33 UTC
1ecf7bf5ff6ff0878a69472305884325a018f5c7
1 file changed
+20
-20
src/health_log.c
+20
-20
@@ -13,11 +13,11 @@ inline int health_alarm_log_open(RRDHOST *host) {
13
14
if(host->health_log_fp) {
15
if (setvbuf(host->health_log_fp, NULL, _IOLBF, 0) != 0)
16
- error("Health: cannot set line buffering on health log file.");
16
+ error("HEALTH [%s]: cannot set line buffering on health log file '%s'.", host->hostname, host->health_log_filename);
17
return 0;
18
}
19
20
- error("Health: cannot open health log file '%s'. Health data will be lost in case of netdata or server crash.", host->health_log_filename);
20
+ error("HEALTH [%s]: cannot open health log file '%s'. Health data will be lost in case of netdata or server crash.", host->hostname, host->health_log_filename);
21
return -1;
22
}
23
@@ -43,13 +43,13 @@ inline void health_log_rotate(RRDHOST *host) {
43
snprintfz(old_filename, FILENAME_MAX, "%s.old", host->health_log_filename);
44
45
if(unlink(old_filename) == -1 && errno != ENOENT)
46
- error("Health: cannot remove old alarms log file '%s'", old_filename);
46
+ error("HEALTH [%s]: cannot remove old alarms log file '%s'", host->hostname, old_filename);
47
48
if(link(host->health_log_filename, old_filename) == -1 && errno != ENOENT)
49
- error("Health: cannot move file '%s' to '%s'.", host->health_log_filename, old_filename);
49
+ error("HEALTH [%s]: cannot move file '%s' to '%s'.", host->hostname, host->health_log_filename, old_filename);
50
51
if(unlink(host->health_log_filename) == -1 && errno != ENOENT)
52
- error("Health: cannot remove old alarms log file '%s'", host->health_log_filename);
52
+ error("HEALTH [%s]: cannot remove old alarms log file '%s'", host->hostname, host->health_log_filename);
53
54
// open it with truncate
55
host->health_log_fp = fopen(host->health_log_filename, "w");
@@ -57,7 +57,7 @@ inline void health_log_rotate(RRDHOST *host) {
57
if(host->health_log_fp)
58
fclose(host->health_log_fp);
59
else
60
- error("Health: cannot truncate health log '%s'", host->health_log_filename);
60
+ error("HEALTH [%s]: cannot truncate health log '%s'", host->hostname, host->health_log_filename);
61
62
host->health_log_fp = NULL;
63
@@ -112,7 +112,7 @@ inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae) {
112
, (long double)ae->new_value
113
, (long double)ae->old_value
114
) < 0))
115
- error("Health: failed to save alarm log entry. Health data may be lost in case of abnormal restart.");
115
+ error("HEALTH [%s]: failed to save alarm log entry to '%s'. Health data may be lost in case of abnormal restart.", host->hostname, host->health_log_filename);
116
else {
117
ae->flags |= HEALTH_ENTRY_FLAG_SAVED;
118
host->health_log_entries_written++;
@@ -144,7 +144,7 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
144
*s = '\0';
145
pointers[entries++] = ++s;
146
if(entries >= max_entries) {
147
- error("Health: line %zu of file '%s' has more than %d entries. Ignoring excessive entries.", line, filename, max_entries);
147
+ error("HEALTH [%s]: line %zu of file '%s' has more than %d entries. Ignoring excessive entries.", host->hostname, line, filename, max_entries);
148
break;
149
}
150
}
@@ -155,7 +155,7 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
155
ALARM_ENTRY *ae = NULL;
156
157
if(entries < 26) {
158
- error("Health: line %zu of file '%s' should have at least 26 entries, but it has %d. Ignoring it.", line, filename, entries);
158
+ error("HEALTH [%s]: line %zu of file '%s' should have at least 26 entries, but it has %d. Ignoring it.", host->hostname, line, filename, entries);
159
errored++;
160
continue;
161
}
@@ -163,14 +163,14 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
163
// check that we have valid ids
164
uint32_t unique_id = (uint32_t)strtoul(pointers[2], NULL, 16);
165
if(!unique_id) {
166
- error("Health: line %zu of file '%s' states alarm entry with invalid unique id %u (%s). Ignoring it.", line, filename, unique_id, pointers[2]);
166
+ error("HEALTH [%s]: line %zu of file '%s' states alarm entry with invalid unique id %u (%s). Ignoring it.", host->hostname, line, filename, unique_id, pointers[2]);
167
errored++;
168
continue;
169
}
170
171
uint32_t alarm_id = (uint32_t)strtoul(pointers[3], NULL, 16);
172
if(!alarm_id) {
173
- error("Health: line %zu of file '%s' states alarm entry for invalid alarm id %u (%s). Ignoring it.", line, filename, alarm_id, pointers[3]);
173
+ error("HEALTH [%s]: line %zu of file '%s' states alarm entry for invalid alarm id %u (%s). Ignoring it.", host->hostname, line, filename, alarm_id, pointers[3]);
174
errored++;
175
continue;
176
}
@@ -178,7 +178,7 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
178
if(unlikely(*pointers[0] == 'A')) {
179
// make sure it is properly numbered
180
if(unlikely(host->health_log.alarms && unique_id < host->health_log.alarms->unique_id)) {
181
- error("Health: line %zu of file '%s' has alarm log entry with %u in wrong order. Ignoring it.", line, filename, unique_id);
181
+ error("HEALTH [%s]: line %zu of file '%s' has alarm log entry %u in wrong order. Ignoring it.", host->hostname, line, filename, unique_id);
182
errored++;
183
continue;
184
}
@@ -190,8 +190,8 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
190
for(ae = host->health_log.alarms; ae; ae = ae->next) {
191
if(unlikely(unique_id == ae->unique_id)) {
192
if(unlikely(*pointers[0] == 'A')) {
193
- error("Health: line %zu of file '%s' adds duplicate alarm log entry with unique id %u. Using the later."
194
- , line, filename, unique_id);
193
+ error("HEALTH [%s]: line %zu of file '%s' adds duplicate alarm log entry %u. Using the later."
194
+ , host->hostname, line, filename, unique_id);
195
*pointers[0] = 'U';
196
duplicate++;
197
}
@@ -208,13 +208,13 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
208
209
// if not found, skip this line
210
if(unlikely(!ae)) {
211
- // error("Health: line %zu of file '%s' updates alarm log entry with unique id %u, but it is not found.", line, filename, unique_id);
211
+ // error("HEALTH [%s]: line %zu of file '%s' updates alarm log entry with unique id %u, but it is not found.", host->hostname, line, filename, unique_id);
212
continue;
213
}
214
215
// check for a possible host missmatch
216
//if(strcmp(pointers[1], host->hostname))
217
- // error("Health: line %zu of file '%s' provides an alarm for host '%s' but this is named '%s'.", line, filename, pointers[1], host->hostname);
217
+ // error("HEALTH [%s]: line %zu of file '%s' provides an alarm for host '%s' but this is named '%s'.", host->hostname, line, filename, pointers[1], host->hostname);
218
219
ae->unique_id = unique_id;
220
ae->alarm_id = alarm_id;
@@ -292,7 +292,7 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
292
max_alarm_id = ae->alarm_id;
293
}
294
else {
295
- error("Health: line %zu of file '%s' is invalid (unrecognized entry type '%s').", line, filename, pointers[0]);
295
+ error("HEALTH [%s]: line %zu of file '%s' is invalid (unrecognized entry type '%s').", host->hostname, line, filename, pointers[0]);
296
errored++;
297
}
298
}
@@ -307,7 +307,7 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
307
host->health_log.next_log_id = max_unique_id + 1;
308
host->health_log.next_alarm_id = max_alarm_id + 1;
309
310
- debug(D_HEALTH, "Health: loaded file '%s' with %zd new alarm entries, updated %zd alarms, errors %zd entries, duplicate %zd", filename, loaded, updated, errored, duplicate);
310
+ debug(D_HEALTH, "HEALTH [%s]: loaded file '%s' with %zd new alarm entries, updated %zd alarms, errors %zd entries, duplicate %zd", host->hostname, filename, loaded, updated, errored, duplicate);
311
return loaded;
312
}
313
@@ -318,7 +318,7 @@ inline void health_alarm_log_load(RRDHOST *host) {
318
snprintfz(filename, FILENAME_MAX, "%s.old", host->health_log_filename);
319
FILE *fp = fopen(filename, "r");
320
if(!fp)
321
- error("Health: cannot open health file: %s", filename);
321
+ error("HEALTH [%s]: cannot open health file: %s", host->hostname, filename);
322
else {
323
health_alarm_log_read(host, fp, filename);
324
fclose(fp);
@@ -327,7 +327,7 @@ inline void health_alarm_log_load(RRDHOST *host) {
327
host->health_log_entries_written = 0;
328
fp = fopen(host->health_log_filename, "r");
329
if(!fp)
330
- error("Health: cannot open health file: %s", host->health_log_filename);
330
+ error("HEALTH [%s]: cannot open health file: %s", host->hostname, host->health_log_filename);
331
else {
332
health_alarm_log_read(host, fp, host->health_log_filename);
333
fclose(fp);