- update sla uptimes in a separate thread
authorAlex Kalimulin <alex@netxms.org>
Sat, 24 Sep 2011 20:25:29 +0000 (20:25 +0000)
committerAlex Kalimulin <alex@netxms.org>
Sat, 24 Sep 2011 20:25:29 +0000 (20:25 +0000)
src/server/core/bizsvcroot.cpp
src/server/core/main.cpp
src/server/core/nxcore.vcproj
src/server/core/svccontainer.cpp
src/server/include/nms_objects.h

index cddb698..1f72b25 100644 (file)
@@ -121,3 +121,23 @@ void BusinessServiceRoot::LinkChildObjects()
       DBFreeResult(hResult);
    }
 }
+
+//
+// Recalculate uptime for each service in the tree 
+//
+
+void BusinessServiceRoot::recalculateAllUptimes( time_t currentTime )
+{
+       updateUptimeStats(currentTime);
+
+       LockChildList(TRUE);
+
+       for (int i = 0; i < int(m_dwChildCount); i++)
+       {
+               NetObj *child = m_pChildList[i];
+               if (child->Type() == OBJECT_BUSINESSSERVICE || child->Type() == OBJECT_NODELINK)
+                       ((ServiceContainer*)child)->updateUptimeStats(currentTime);
+       }
+
+       UnlockChildList();
+}
\ No newline at end of file
index 2bd6790..4fe5d16 100644 (file)
@@ -97,7 +97,7 @@ THREAD_RESULT THREAD_CALL SNMPTrapReceiver(void *pArg);
 THREAD_RESULT THREAD_CALL SyslogDaemon(void *pArg);
 THREAD_RESULT THREAD_CALL BeaconPoller(void *pArg);
 THREAD_RESULT THREAD_CALL JobManagerThread(void *arg);
-THREAD_RESULT THREAD_CALL ServiceLevelMonitoring(void *arg);
+THREAD_RESULT THREAD_CALL UptimeCalculator(void *arg);
 
 
 //
@@ -793,6 +793,9 @@ retry_db_lock:
        ThreadCreate(ClientListenerIPv6, 0, NULL);
 #endif
 
+       // Start uptime calculator for SLM
+       ThreadCreate(UptimeCalculator, 0, NULL);
+
        g_dwFlags |= AF_SERVER_INITIALIZED;
        DbgPrintf(1, _T("Server initialization completed"));
        return TRUE;
index e417a6c..c95f844 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="windows-1251"?>\r
 <VisualStudioProject\r
        ProjectType="Visual C++"\r
-       Version="8.00"\r
+       Version="8,00"\r
        Name="nxcore"\r
        ProjectGUID="{3B172035-5EEC-45A3-8471-2C390B7ED683}"\r
        RootNamespace="nxcore"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Debug|x64"\r
-                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
-                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
                        ConfigurationType="2"\r
                        CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
-                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\..\include;..\include"\r
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;NXCORE_EXPORTS;_CRT_SECURE_NO_DEPRECATE"\r
-                               MinimalRebuild="true"\r
-                               BasicRuntimeChecks="3"\r
-                               RuntimeLibrary="3"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;NXCORE_EXPORTS;_CRT_SECURE_NO_DEPRECATE"\r
+                               RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
                                Detect64BitPortabilityProblems="false"\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                AdditionalDependencies="ws2_32.lib libeay32.lib iphlpapi.lib psapi.lib"\r
-                               LinkIncremental="2"\r
+                               LinkIncremental="1"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               TargetMachine="17"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Release|Win32"\r
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
-                       IntermediateDirectory="$(ConfigurationName)"\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
                        ConfigurationType="2"\r
                        CharacterSet="1"\r
-                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\..\include;..\include"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;NXCORE_EXPORTS;_CRT_SECURE_NO_DEPRECATE"\r
-                               RuntimeLibrary="2"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;NXCORE_EXPORTS;_CRT_SECURE_NO_DEPRECATE"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
                                Detect64BitPortabilityProblems="false"\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                AdditionalDependencies="ws2_32.lib libeay32.lib iphlpapi.lib psapi.lib"\r
-                               LinkIncremental="1"\r
+                               LinkIncremental="2"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               OptimizeReferences="2"\r
-                               EnableCOMDATFolding="2"\r
-                               TargetMachine="1"\r
+                               TargetMachine="17"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\bizservice.cpp"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath=".\bizsvcroot.cpp"\r
-                               >\r
-                       </File>\r
-                       <File\r
                                RelativePath=".\bridge.cpp"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\slmcheck.cpp"\r
-                               >\r
-                       </File>\r
-                       <File\r
                                RelativePath=".\smclp.cpp"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\svccontainer.cpp"\r
-                               >\r
-                       </File>\r
-                       <File\r
                                RelativePath=".\syncer.cpp"\r
                                >\r
                        </File>\r
                                RelativePath=".\zone.cpp"\r
                                >\r
                        </File>\r
+                       <Filter\r
+                               Name="SLM"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\bizservice.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\bizsvcroot.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\slmcheck.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\svccontainer.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\uptimecalc.cpp"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Header Files"\r
index 1eb84b7..0b00f3f 100644 (file)
@@ -145,6 +145,7 @@ void ServiceContainer::calculateCompoundStatus(BOOL bForcedRecalc)
        UnlockChildList();
 
        // A hack to make service root to recalculate uptime properly
+       /*
        for(i = 0; iOldStatus == m_iStatus && i < int(m_dwParentCount); i++)
        {
                if (m_pParentList[i]->Type() == OBJECT_BUSINESSSERVICEROOT)
@@ -152,7 +153,7 @@ void ServiceContainer::calculateCompoundStatus(BOOL bForcedRecalc)
                        ((BusinessServiceRoot*)m_pParentList[i])->updateUptimeStats();
                        break;
                }
-       }
+       }*/
 
        // Cause parent object(s) to recalculate it's status
        if ((iOldStatus != m_iStatus) || bForcedRecalc)
@@ -178,7 +179,7 @@ void ServiceContainer::calculateCompoundStatus(BOOL bForcedRecalc)
 void ServiceContainer::setStatus(int newStatus)
 {
        m_iStatus = newStatus;
-       updateUptimeStats();    
+       // updateUptimeStats(); 
 }
 
 
@@ -299,11 +300,13 @@ double ServiceContainer::getUptimeFromDBFor(Period period, LONG *downtime)
 // Update uptime counters 
 //
 
-void ServiceContainer::updateUptimeStats()
+void ServiceContainer::updateUptimeStats(time_t currentTime /* = 0*/)
 {
        LONG timediffTillNow;
        LONG downtimeBetweenPolls = 0;
-       time_t curTime = time(NULL);
+
+       if (currentTime == 0)
+               currentTime = time(NULL);
 
        LockData();
 
@@ -313,7 +316,7 @@ void ServiceContainer::updateUptimeStats()
 
        if (m_iStatus == STATUS_CRITICAL && m_prevUptimeUpdateStatus == STATUS_CRITICAL)
        {
-               downtimeBetweenPolls = LONG(curTime - m_prevUptimeUpdateTime);          
+               downtimeBetweenPolls = LONG(currentTime - m_prevUptimeUpdateTime);              
                DbgPrintf(7, _T("++++ ServiceContainer::updateUptimeStats() both statuses critical"));
        }
 
@@ -347,9 +350,9 @@ void ServiceContainer::updateUptimeStats()
        UnlockData();
 
        m_prevUptimeUpdateStatus = m_iStatus;
-       m_prevUptimeUpdateTime = curTime;
+       m_prevUptimeUpdateTime = currentTime;
 
-       DbgPrintf(7, _T("++++ ServiceContainer::updateUptimeStats() %lf %lf %lf"), m_uptimeDay, m_uptimeWeek, m_uptimeMonth);
+       DbgPrintf(7, _T("++++ ServiceContainer::updateUptimeStats() [%d] %lf %lf %lf"), int(m_dwId), m_uptimeDay, m_uptimeWeek, m_uptimeMonth);
 }
 
 
index 835727e..5932c1a 100644 (file)
@@ -1641,7 +1641,6 @@ protected:
        void initServiceContainer();
        BOOL addHistoryRecord();
        void initUptimeStats();
-       void updateUptimeStats();
        double getUptimeFromDBFor(Period period, LONG *downtime);
 
 public:
@@ -1657,6 +1656,7 @@ public:
 
        virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
        virtual void setStatus(int newStatus);
+       void updateUptimeStats(time_t currentTime = 0);
 };
 
 
@@ -1677,6 +1677,8 @@ public:
 
    void LinkChildObjects();
    void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
+
+   void recalculateAllUptimes(time_t currentTime);
 };