Add a CRASH event when the agent fails to properly shutdown (#10893)
Stelios Fragkakis committed
Apr 7, 2021 at 21:17 UTC
f800a4f3ac053d58817bccde15bbd4c83bb2be43
1 file changed
+14
daemon/main.c
+14
@@ -29,6 +29,10 @@ void netdata_cleanup_and_exit(int ret) {
29
30
send_statistics("EXIT", ret?"ERROR":"OK","-");
31
32
+ char agent_crash_file[FILENAME_MAX + 1];
33
+ snprintfz(agent_crash_file, FILENAME_MAX, "%s/.agent_crash", netdata_configured_varlib_dir);
34
+ (void) unlink(agent_crash_file);
35
+
36
// cleanup/save the database and exit
37
info("EXIT: cleaning up the database...");
38
rrdhost_cleanup_all();
@@ -1456,6 +1460,14 @@ int main(int argc, char **argv) {
1460
if(rrd_init(netdata_configured_hostname, system_info))
1461
fatal("Cannot initialize localhost instance with name '%s'.", netdata_configured_hostname);
1462
1463
+ char agent_crash_file[FILENAME_MAX + 1];
1464
+ snprintfz(agent_crash_file, FILENAME_MAX, "%s/.agent_crash", netdata_configured_varlib_dir);
1465
+ int crash_detected = (unlink(agent_crash_file) == 0);
1466
+ int fd = open(agent_crash_file, O_WRONLY | O_CREAT | O_TRUNC, 444);
1467
+ if (fd >= 0)
1468
+ close(fd);
1469
+
1470
+
1471
// ------------------------------------------------------------------------
1472
// Claim netdata agent to a cloud endpoint
1473
@@ -1498,6 +1510,8 @@ int main(int argc, char **argv) {
1510
netdata_ready = 1;
1511
1512
send_statistics("START", "-", "-");
1513
+ if (crash_detected)
1514
+ send_statistics("CRASH", "-", "-");
1515
1516
// ------------------------------------------------------------------------
1517
// Report ACLK build failure