@@ -930,7 +930,6 @@ function analyse_tree_host_graph($panel, $user_id) {
930
930
}
931
931
}
932
932
933
-
934
933
$ data = db_fetch_assoc ('SELECT
935
934
gt.id, gt.name, COUNT(DISTINCT graphs.local_graph_id) AS graphs,
936
935
graphs.items AS graph_items, templates.items AS template_items
@@ -962,7 +961,6 @@ function analyse_tree_host_graph($panel, $user_id) {
962
961
$ panel ['data ' ] .= '<span class="inpa_sq color_red"></span> ' . __ ('Graph items/template items issue: %s ' , $ sql_count , 'intropage ' ) . '<br/> ' ;
963
962
}
964
963
965
-
966
964
if (api_plugin_is_enabled ('monitor ' )) {
967
965
if ($ allowed_devices !== false || $ simple_perms ) {
968
966
if (!$ simple_perms ) {
@@ -990,6 +988,56 @@ function analyse_tree_host_graph($panel, $user_id) {
990
988
}
991
989
}
992
990
991
+ $ cpu_cores = 0 ;
992
+ if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
993
+ $ output = shell_exec ('wmic cpu get NumberOfCores ' );
994
+ if (!is_null ($ output ) && $ output !== false ) {
995
+ $ lines = preg_split ('/\r\n|\r|\n/ ' , $ output );
996
+ $ cpu_cores = $ lines [1 ];
997
+ }
998
+ } elseif (substr_count (strtolower (PHP_OS ), 'darwin ' )) {
999
+ $ cpu_cores = shell_exec ('sysctl -n hw.ncpu ' );
1000
+ } else {
1001
+ if (file_exists ('/usr/bin/nproc ' )) {
1002
+ $ cpu_cores = shell_exec ('/usr/bin/nproc ' );
1003
+ } elseif (file_exists ('/bin/nproc ' )) {
1004
+ $ cpu_cores = shell_exec ('/bin/nproc ' );
1005
+ } else {
1006
+ $ output = shell_exec ('nproc ' );
1007
+ if (!is_null ($ output ) && $ output !== false ) {
1008
+ $ cpu_cores = $ output ;
1009
+ }
1010
+ }
1011
+ }
1012
+ $ cpu_cores = trim ($ cpu_cores );
1013
+
1014
+ $ sett = db_fetch_row ('SELECT processes, threads FROM poller WHERE id = 1 ' );
1015
+ $ color = 'green ' ;
1016
+ $ text = __ ('OK ' );
1017
+
1018
+ if ($ cpu_cores == 0 ) {
1019
+ if ($ sett ['processes ' ] == 1 || $ sett ['threads ' ] == 1 ) {
1020
+ $ color = 'yellow ' ;
1021
+ $ text = 'Cannot determine number of CPU cores. You have set only 1 process or thread for poller. You may have performance problems. ' ;
1022
+ }
1023
+ } elseif ($ cpu_cores == 1 && ($ sett ['processes ' ] == 1 || $ sett ['threads ' ] == 1 )) {
1024
+ $ color = 'yellow ' ;
1025
+ $ text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads. ' ;
1026
+ $ total_errors ++;
1027
+ } elseif ($ cpu_cores > 1 ) {
1028
+ if ($ sett ['processes ' ] == 1 || $ sett ['threads ' ] == 1 ) {
1029
+ $ color = 'red ' ;
1030
+ $ text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads. ' ;
1031
+ $ total_errors ++;
1032
+ } elseif ($ sett ['processes ' ]/$ cpu_cores < 0.4 || $ sett ['threads ' ]/$ cpu_cores < 0.4 ) {
1033
+ $ color = 'yellow ' ;
1034
+ $ text = 'You are using less than half of CPU cores. For better performance, consider increasing poller processes or threads. ' ;
1035
+ }
1036
+ }
1037
+
1038
+ $ panel ['data ' ] .= '<span class="inpa_sq color_ ' . $ color . '"></span> ' . __ ('Server CPU cores / processes / threads: %s / %s / %s ' , $ cpu_cores , $ sett ['processes ' ], $ sett ['threads ' ], 'intropage ' );
1039
+ $ panel ['data ' ] .= display_tooltip ($ text ) . '<br/> ' ;
1040
+
993
1041
if ($ total_errors > 0 ) {
994
1042
$ panel ['data ' ] = '<table class="cactiTable">
995
1043
<tr>
@@ -1950,6 +1998,57 @@ function analyse_tree_host_graph_detail() {
1950
1998
}
1951
1999
}
1952
2000
2001
+ $ cpu_cores = 0 ;
2002
+ if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
2003
+ $ output = shell_exec ('wmic cpu get NumberOfCores ' );
2004
+ if (!is_null ($ output ) && $ output !== false ) {
2005
+ $ lines = preg_split ('/\r\n|\r|\n/ ' , $ output );
2006
+ $ cpu_cores = $ lines [1 ];
2007
+ }
2008
+ } elseif (substr_count (strtolower (PHP_OS ), 'darwin ' )) {
2009
+ $ cpu_cores = shell_exec ('sysctl -n hw.ncpu ' );
2010
+ } else {
2011
+ if (file_exists ('/usr/bin/nproc ' )) {
2012
+ $ cpu_cores = shell_exec ('/usr/bin/nproc ' );
2013
+ } elseif (file_exists ('/bin/nproc ' )) {
2014
+ $ cpu_cores = shell_exec ('/bin/nproc ' );
2015
+ } else {
2016
+ $ output = shell_exec ('nproc ' );
2017
+ if (!is_null ($ output ) && $ output !== false ) {
2018
+ $ cpu_cores = $ output ;
2019
+ }
2020
+ }
2021
+ }
2022
+ $ cpu_cores = trim ($ cpu_cores );
2023
+
2024
+ $ sett = db_fetch_row ('SELECT processes, threads FROM poller WHERE id = 1 ' );
2025
+ $ color = 'green ' ;
2026
+ $ text = __ ('OK ' );
2027
+
2028
+ if ($ cpu_cores == 0 ) {
2029
+ if ($ sett ['processes ' ] == 1 || $ sett ['threads ' ] == 1 ) {
2030
+ $ color = 'yellow ' ;
2031
+ $ text = 'Cannot determine number of CPU cores. You have set only 1 process or thread for poller. You may have performance problems. ' ;
2032
+ }
2033
+ } elseif ($ cpu_cores == 1 && ($ sett ['processes ' ] == 1 || $ sett ['threads ' ] == 1 )) {
2034
+ $ color = 'yellow ' ;
2035
+ $ text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads. ' ;
2036
+ $ total_errors ++;
2037
+ } elseif ($ cpu_cores > 1 ) {
2038
+ if ($ sett ['processes ' ] == 1 || $ sett ['threads ' ] == 1 ) {
2039
+ $ color = 'red ' ;
2040
+ $ text = 'You have set only 1 process or thread for poller. You may have performance problems. Try to increase poller processes or threads. ' ;
2041
+ $ total_errors ++;
2042
+ } elseif ($ sett ['processes ' ]/$ cpu_cores < 0.4 || $ sett ['threads ' ]/$ cpu_cores < 0.4 ) {
2043
+ $ color = 'yellow ' ;
2044
+ $ text = 'You are using less than half of CPU cores. For better performance, consider increasing poller processes or threads. ' ;
2045
+ }
2046
+ }
2047
+
2048
+ $ panel ['detail ' ] .= '<span class="inpa_sq color_ ' . $ color . '"></span> ' . __ ('Server CPU cores / processes / threads: %s / %s / %s ' , $ cpu_cores , $ sett ['processes ' ], $ sett ['threads ' ], 'intropage ' );
2049
+ $ panel ['detail ' ] .= display_tooltip ($ text ) . '<br/> ' ;
2050
+
2051
+
1953
2052
if ($ total_errors > 0 ) {
1954
2053
$ panel ['detail ' ] = '<span class="txt_big"> ' . __ ('Found %s problems ' , $ total_errors , 'intropage ' ) . '</span><br/> ' . $ panel ['detail ' ];
1955
2054
} else {
0 commit comments