@cryptotaxi247 / netdata-1 / commits / 261858b85

Add an event when an incomplete agent shutdown is detected #11078

Stelios Fragkakis committed May 5, 2021 at 18:26 UTC 261858b8529efaceab2c7fe75ac80ba6660466dc
1 file changed +9 -1
daemon/main.c
+9 -1
@@ -31,8 +31,10 @@ void netdata_cleanup_and_exit(int ret) {
31 analytics_free_data();
32
33 char agent_crash_file[FILENAME_MAX + 1];
34 + char agent_incomplete_shutdown_file[FILENAME_MAX + 1];
35 snprintfz(agent_crash_file, FILENAME_MAX, "%s/.agent_crash", netdata_configured_varlib_dir);
35 - (void) unlink(agent_crash_file);
36 + snprintfz(agent_incomplete_shutdown_file, FILENAME_MAX, "%s/.agent_incomplete_shutdown", netdata_configured_varlib_dir);
37 + (void) rename(agent_crash_file, agent_incomplete_shutdown_file);
38
39 // cleanup/save the database and exit
40 info("EXIT: cleaning up the database...");
@@ -68,6 +70,7 @@ void netdata_cleanup_and_exit(int ret) {
70 security_clean_openssl();
71 #endif
72 info("EXIT: all done - netdata is now exiting - bye bye...");
73 + (void) unlink(agent_incomplete_shutdown_file);
74 exit(ret);
75 }
76
@@ -1271,6 +1274,9 @@ int main(int argc, char **argv) {
1274 fatal("Cannot initialize localhost instance with name '%s'.", netdata_configured_hostname);
1275
1276 char agent_crash_file[FILENAME_MAX + 1];
1277 + char agent_incomplete_shutdown_file[FILENAME_MAX + 1];
1278 + snprintfz(agent_incomplete_shutdown_file, FILENAME_MAX, "%s/.agent_incomplete_shutdown", netdata_configured_varlib_dir);
1279 + int incomplete_shutdown_detected = (unlink(agent_incomplete_shutdown_file) == 0);
1280 snprintfz(agent_crash_file, FILENAME_MAX, "%s/.agent_crash", netdata_configured_varlib_dir);
1281 int crash_detected = (unlink(agent_crash_file) == 0);
1282 int fd = open(agent_crash_file, O_WRONLY | O_CREAT | O_TRUNC, 444);
@@ -1324,6 +1330,8 @@ int main(int argc, char **argv) {
1330 send_statistics("START", "-", "-");
1331 if (crash_detected)
1332 send_statistics("CRASH", "-", "-");
1333 + if (incomplete_shutdown_detected)
1334 + send_statistics("INCOMPLETE_SHUTDOWN", "-", "-");
1335
1336 //check if ANALYTICS needs to start
1337 if (netdata_anonymous_statistics_enabled == 1) {