]> granicus.if.org Git - icinga2/commitdiff
Enhance client connect/sync logging and include bytes/zone in logs
authorMichael Friedrich <michael.friedrich@icinga.com>
Mon, 21 Aug 2017 09:08:13 +0000 (11:08 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Wed, 30 Aug 2017 13:13:08 +0000 (15:13 +0200)
refs #5513

refs #5523

lib/remote/apilistener-filesync.cpp
lib/remote/apilistener.cpp

index d4a4a21da6905623233be9be33dcc7680636cca0..84c443ba7dbf53a56c1987225f4e2e645843d2a9 100644 (file)
@@ -109,13 +109,7 @@ bool ApiListener::UpdateConfigDir(const ConfigDirInformation& oldConfigInfo, con
                return false;
        }
 
-       Log(LogInformation, "ApiListener")
-           << "Applying configuration file update for path '" << configDir << "'. Received timestamp '"
-           << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", newTimestamp) << "' ("
-           << std::fixed << std::setprecision(6) << newTimestamp
-           << ") is more recent than current timestamp '"
-           << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", oldTimestamp) << "' ("
-           << oldTimestamp << ").";
+       size_t numBytes = 0;
 
        {
                ObjectLock olock(newConfig);
@@ -128,15 +122,28 @@ bool ApiListener::UpdateConfigDir(const ConfigDirInformation& oldConfigInfo, con
                                Log(LogInformation, "ApiListener")
                                    << "Updating configuration file: " << path;
 
-                               //pass the directory and generate a dir tree, if not existing already
+                               /* Sync string content only. */
+                               String content = kv.second;
+
+                               /* Generate a directory tree (zones/1/2/3 might not exist yet). */
                                Utility::MkDirP(Utility::DirName(path), 0755);
                                std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
-                               fp << kv.second;
+                               fp << content;
                                fp.close();
+
+                               numBytes += content.GetLength();
                        }
                }
        }
 
+       Log(LogInformation, "ApiListener")
+           << "Applying configuration file update for path '" << configDir << "' (" << numBytes << " Bytes). Received timestamp '"
+           << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", newTimestamp) << "' ("
+           << std::fixed << std::setprecision(6) << newTimestamp
+           << "), Current timestamp '"
+           << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", oldTimestamp) << "' ("
+           << oldTimestamp << ").";
+
        ObjectLock xlock(oldConfig);
        for (const Dictionary::Pair& kv : oldConfig) {
                if (!newConfig->Contains(kv.first)) {
index dbc6ea3f983428604e4dfabd85e7670002b91ebd..fd348edd909c73cf916441fcfa68dd1354103a3a 100644 (file)
@@ -294,7 +294,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
        String port = endpoint->GetPort();
 
        Log(LogInformation, "ApiListener")
-           << "Reconnecting to API endpoint '" << endpoint->GetName() << "' via host '" << host << "' and port '" << port << "'";
+           << "Reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host << "' and port '" << port << "'";
 
        TcpSocket::Ptr client = new TcpSocket();
 
@@ -313,6 +313,9 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
                Log(LogDebug, "ApiListener")
                    << info.str() << "\n" << DiagnosticInformation(ex);
        }
+
+       Log(LogInformation, "ApiListener")
+           << "Finished reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host << "' and port '" << port << "'";
 }
 
 void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role)
@@ -321,6 +324,9 @@ void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& host
                NewClientHandlerInternal(client, hostname, role);
        } catch (const std::exception& ex) {
                Log(LogCritical, "ApiListener")
+                   << "Exception while handling new API client connection: " << DiagnosticInformation(ex, false);
+
+               Log(LogDebug, "ApiListener")
                    << "Exception while handling new API client connection: " << DiagnosticInformation(ex);
        }
 }
@@ -463,6 +469,8 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
 
 void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync)
 {
+       Zone::Ptr eZone = endpoint->GetZone();
+
        try {
                {
                        ObjectLock olock(endpoint);
@@ -475,15 +483,19 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
                 */
 
                Log(LogInformation, "ApiListener")
-                   << "Sending config updates for endpoint '" << endpoint->GetName() << "'.";
+                   << "Sending config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
 
                /* sync zone file config */
                SendConfigUpdate(aclient);
+
+               Log(LogInformation, "ApiListener")
+                   << "Finished sending config file updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
+
                /* sync runtime config */
                SendRuntimeConfigObjects(aclient);
 
                Log(LogInformation, "ApiListener")
-                   << "Finished sending config updates for endpoint '" << endpoint->GetName() << "'.";
+                   << "Finished sending runtime config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
 
                if (!needSync) {
                        ObjectLock olock2(endpoint);
@@ -492,22 +504,30 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
                }
 
                Log(LogInformation, "ApiListener")
-                   << "Sending replay log for endpoint '" << endpoint->GetName() << "'.";
+                   << "Sending replay log for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
 
                ReplayLog(aclient);
 
-               if (endpoint->GetZone() == Zone::GetLocalZone())
+               if (eZone == Zone::GetLocalZone())
                        UpdateObjectAuthority();
 
                Log(LogInformation, "ApiListener")
-                   << "Finished sending replay log for endpoint '" << endpoint->GetName() << "'.";
+                   << "Finished sending replay log for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
        } catch (const std::exception& ex) {
-               ObjectLock olock2(endpoint);
-               endpoint->SetSyncing(false);
+               {
+                       ObjectLock olock2(endpoint);
+                       endpoint->SetSyncing(false);
+               }
 
                Log(LogCritical, "ApiListener")
+                   << "Error while syncing endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex, false);
+
+               Log(LogDebug, "ApiListener")
                    << "Error while syncing endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
        }
+
+       Log(LogInformation, "ApiListener")
+           << "Finished syncing endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
 }
 
 void ApiListener::ApiTimerHandler(void)
@@ -1011,7 +1031,11 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
                                        count++;
                                } catch (const std::exception& ex) {
                                        Log(LogWarning, "ApiListener")
+                                           << "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex, false);
+
+                                       Log(LogDebug, "ApiListener")
                                            << "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
+
                                        break;
                                }