[ZBX-6006] Web-interface requests many redundant data from API classes Created: 2012 Dec 16  Updated: 2017 May 30  Resolved: 2013 Feb 04

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Frontend (F)
Affects Version/s: 2.0.5rc1, 2.1.0
Fix Version/s: 2.0.5rc1, 2.1.0

Type: Incident report Priority: Major
Reporter: Alexey Pustovalov Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: performance, redundancy
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

please look comment for getting more info:



 Comments   
Comment by Alexey Pustovalov [ 2012 Dec 16 ]

(1) Widget "Host Status":

Index: include/blocks.inc.php
===================================================================
--- include/blocks.inc.php      (revision 32148)
+++ include/blocks.inc.php      (working copy)
@@ -353,7 +353,7 @@
                'nodeids' => get_current_nodeid(),
                'groupids' => $filter['groupids'],
                'monitored_hosts' => 1,
-               'output' => API_OUTPUT_EXTEND
+               'output' => array('groupid', 'name')
        );
        $groups = API::HostGroup()->get($options);
        $groups = zbx_toHash($groups, 'groupid');
@@ -392,7 +392,7 @@
                        'priority' => $filter['severity'],
                        'value' => TRIGGER_VALUE_TRUE
                ),
-               'output' => API_OUTPUT_EXTEND
+               'output' => array('triggerid', 'priority')
        );
        $triggers = API::Trigger()->get($options);

In function make_hoststat_summary we get API_OUTPUT_EXTEND for HostGroups and for Triggers (for triggers we need only triggerid and priority).

tomtom RESOLVED
Eduards CLOSED

Comment by Alexey Pustovalov [ 2012 Dec 16 ]

(3) Favorite widgets:

Index: include/blocks.inc.php
===================================================================
--- include/blocks.inc.php      (revision 32148)
+++ include/blocks.inc.php      (working copy)
@@ -39,22 +39,26 @@
                }
        }

-       $options = array(
-               'graphids' => $graphids,
-               'selectHosts' => API_OUTPUT_EXTEND,
-               'output' => API_OUTPUT_EXTEND
-       );
-       $graphs = API::Graph()->get($options);
-       $graphs = zbx_toHash($graphs, 'graphid');
+       if (count($graphids)) {
+               $options = array(
+                       'graphids' => $graphids,
+                       'selectHosts' => array('hostid', 'name'),
+                       'output' => array('graphid', 'name')
+               );
+               $graphs = API::Graph()->get($options);
+               $graphs = zbx_toHash($graphs, 'graphid');
+       }

-       $options = array(
-               'itemids' => $itemids,
-               'selectHosts' => API_OUTPUT_EXTEND,
-               'output' => API_OUTPUT_EXTEND,
-               'webitems' => 1
-       );
-       $items = API::Item()->get($options);
-       $items = zbx_toHash($items, 'itemid');
+       if (count($itemids)) {
+               $options = array(
+                       'itemids' => $itemids,
+                       'selectHosts' => array('hostid', 'name'),
+                       'output' => array('itemid', 'name', 'key_'),
+                       'webitems' => 1
+               );
+               $items = API::Item()->get($options);
+               $items = zbx_toHash($items, 'itemid');
+       }

        foreach ($fav_graphs as $favorite) {
                $sourceid = $favorite['value'];
@@ -95,12 +99,14 @@
                }
        }

-       $options = array(
-               'screenids' => $screenids,
-               'output' => API_OUTPUT_EXTEND
-       );
-       $screens = API::Screen()->get($options);
-       $screens = zbx_toHash($screens, 'screenid');
+       if (count($screenids)) {
+               $options = array(
+                       'screenids' => $screenids,
+                       'output' => array('screenid', 'name')
+               );
+               $screens = API::Screen()->get($options);
+               $screens = zbx_toHash($screens, 'screenid');
+       }

        foreach ($fav_screens as $favorite) {
                $source = $favorite['source'];
@@ -142,7 +148,7 @@

        $sysmaps = API::Map()->get(array(
                'sysmapids' => $sysmapids,
-               'output' => API_OUTPUT_EXTEND
+               'output' => array('sysmapid', 'name')
        ));
        foreach ($sysmaps as $sysmap) {
                $sysmapid = $sysmap['sysmapid'];
@@ -1133,22 +1139,26 @@
                }
        }

-       $options = array(
-               'graphids' => $graphids,
-               'selectHosts' => array('hostid', 'host'),
-               'output' => API_OUTPUT_EXTEND
-       );
-       $graphs = API::Graph()->get($options);
-       $graphs = zbx_toHash($graphs, 'graphid');
+       if(count($graphids)) {
+               $options = array(
+                       'graphids' => $graphids,
+                       'selectHosts' => array('hostid', 'host'),
+                       'output' => array('graphid', 'name'),
+               );
+               $graphs = API::Graph()->get($options);
+               $graphs = zbx_toHash($graphs, 'graphid');
+       }

-       $options = array(
-               'itemids' => $itemids,
-               'selectHosts' => array('hostid', 'host'),
-               'output' => API_OUTPUT_EXTEND,
-               'webitems' => 1
-       );
-       $items = API::Item()->get($options);
-       $items = zbx_toHash($items, 'itemid');
+       if (count($itemids)) {
+               $options = array(
+                       'itemids' => $itemids,
+                       'selectHosts' => array('hostid', 'host'),
+                       'output' => array('itemid', 'name', 'key_'),
+                       'webitems' => 1
+               );
+               $items = API::Item()->get($options);
+               $items = zbx_toHash($items, 'itemid');
+       }

        $favGraphs = array();
        foreach ($fav_graphs as $favorite) {
@@ -1228,7 +1238,7 @@

        $options = array(
                'sysmapids' => $sysmapids,
-               'output' => API_OUTPUT_EXTEND
+               'output' => array('sysmapid', 'name')
        );
        $sysmaps = API::Map()->get($options);
        foreach ($sysmaps as $sysmap) {
@@ -1278,12 +1288,15 @@
                }
        }

-       $options = array(
-               'screenids' => $screenids,
-               'output' => API_OUTPUT_EXTEND
-       );
-       $screens = API::Screen()->get($options);
-       $screens = zbx_toHash($screens, 'screenid');
+       if (count($screenids)) {
+               $options = array(
+                       'screenids' => $screenids,
+                       'output' => array('screenid', 'name')
+               );
+               $screens = API::Screen()->get($options);
+               $screens = zbx_toHash($screens, 'screenid');
+       }
+
        $favScreens = array();
        foreach ($fav_screens as $favorite) {
                $source = $favorite['source'];

For all these API queries we get all data while we need only id and name. It is favourite widgets.

tomtom RESOLVED
Eduards REOPENED,

  • if $graphids is empty (in make_favorite_graphs()) we can fire return and don't do useless work. Same for make_favorite_screens(), make_favorite_maps(), make_graph_submenu(), make_screen_submenu().
    tomtom No, there is still possible that $itemids is not empty. But added extra check to prevent useless API call.
  • it will be better order output fields array, first define ids and after names
    'output' => array('name', 'screenid') change to 'output' => array('screenid', 'name')
  • please define obviously "id" field in output (this actual for many places)..

tomtom RESOLVED in r32581
Eduards CLOSED

Comment by Toms (Inactive) [ 2012 Dec 17 ]

http://www.zabbix.com/documentation/internal/coding_guidelines#creating_an_issue

When support engineers create an issue (either a new one or duplicating a customer issue), they still have to describe what the actual problem is, assuming that the reader has no access to customer projects and mind reading capabilities.
dotneft that is no a customer bug.

Comment by Alexey Pustovalov [ 2012 Dec 17 ]

(4) Maps configuration page (maps list):

Index: sysmaps.php
===================================================================
--- sysmaps.php (revision 32146)
+++ sysmaps.php (working copy)
@@ -273,7 +273,7 @@

        $maps = API::Map()->get(array(
                'editable' => true,
-               'output' => API_OUTPUT_EXTEND,
+               'output' => array('sysmapid', 'name', 'width', 'height'),
                'sortfield' => $sortfield,
                'sortorder' => $sortorder,
                'limit' => $config['search_limit'] + 1

Eduards REOPEN, please define obviously "sysmapid" in output. P.S. array('sysmapid', 'name', 'width', 'height')

tomtom RESOLVED in r32584

Eduards CLOSED

(5) A map configuration form:

Index: sysmaps.php
===================================================================
--- sysmaps.php (revision 32146)
+++ sysmaps.php (working copy)
@@ -80,6 +80,7 @@
 check_fields($fields);
 validate_sort_and_sortorder('name', ZBX_SORT_UP);

+$sysmap = array();
 if (isset($_REQUEST['sysmapid'])) {
        $maps = API::Map()->get(array(
                'sysmapids' => $_REQUEST['sysmapid'],
@@ -212,9 +213,7 @@
 $mapWidget->addPageHeader(_('CONFIGURATION OF NETWORK MAPS'), $form);

 if (isset($_REQUEST['form'])) {
-       $sysmap = array();
-
-       if (isset($_REQUEST['sysmapid'])) {
+       if (isset($_REQUEST['sysmapid']) and !isset($sysmap)) {
                $sysmaps = API::Map()->get(array(
                        'sysmapids' => $_REQUEST['sysmapid'],
                        'output' => API_OUTPUT_EXTEND,

tomtom RESOLVED
Eduards CLOSED

Comment by Alexey Pustovalov [ 2012 Dec 17 ]

(6) Configuration of network maps:

Index: maps.inc.php
===================================================================
--- maps.inc.php        (revision 32146)
+++ maps.inc.php        (working copy)
@@ -532,46 +532,55 @@
                }
        }

-       $hosts = API::Host()->get(array(
-               'hostids' => $hostids,
-               'output' => array('name'),
-               'nopermissions' => true,
-               'nodeids' => get_current_nodeid(true),
-               'preservekeys' => true
-       ));
+       if (count($hostids)) {
+               $hosts = API::Host()->get(array(
+                       'hostids' => array_unique($hostids),
+                       'output' => array('name'),
+                       'nopermissions' => true,
+                       'nodeids' => get_current_nodeid(true),
+                       'preservekeys' => true
+               ));
+       }

-       $maps = API::Map()->get(array(
-               'mapids' => $mapids,
-               'output' => array('name'),
-               'nopermissions' => true,
-               'nodeids' => get_current_nodeid(true),
-               'preservekeys' => true
-       ));
+       if (count($mapids)) {
+               $maps = API::Map()->get(array(
+                       'mapids' => array_unique($mapids),
+                       'output' => array('name'),
+                       'nopermissions' => true,
+                       'nodeids' => get_current_nodeid(true),
+                       'preservekeys' => true
+               ));
+       }

-       $triggers = API::Trigger()->get(array(
-               'triggerids' => $triggerids,
-               'output' => API_OUTPUT_EXTEND,
-               'selectHosts' => array('name'),
-               'nopermissions' => true,
-               'nodeids' => get_current_nodeid(true),
-               'preservekeys' => true
-       ));
+       if (count($triggerids)) {
+               $triggers = API::Trigger()->get(array(
+                       'triggerids' => array_unique($triggerids),
+                       'output' => array('expression'),
+                       'nopermissions' => true,
+                       'nodeids' => get_current_nodeid(true),
+                       'preservekeys' => true
+               ));
+       }

-       $hostgroups = API::HostGroup()->get(array(
-               'hostgroupids' => $hostgroupids,
-               'output' => array('name'),
-               'nopermissions' => true,
-               'nodeids' => get_current_nodeid(true),
-               'preservekeys' => true
-       ));
+       if (count($hostgroupids)) {
+               $hostgroups = API::HostGroup()->get(array(
+                       'hostgroupids' => array_unique($hostgroupids),
+                       'output' => array('name'),
+                       'nopermissions' => true,
+                       'nodeids' => get_current_nodeid(true),
+                       'preservekeys' => true
+               ));
+       }

-       $images = API::image()->get(array(
-               'imageids' => $imageids,
-               'output' => API_OUTPUT_EXTEND,
-               'nopermissions' => true,
-               'nodeids' => get_current_nodeid(true),
-               'preservekeys' => true
-       ));
+       if (count($imageids)) {
+               $images = API::image()->get(array(
+                       'imageids' => array_unique($imageids),
+                       'output' => array('name'),
+                       'nopermissions' => true,
+                       'nodeids' => get_current_nodeid(true),
+                       'preservekeys' => true
+               ));
+       }

        foreach ($selements as $snum => $selement) {
                switch ($selement['elementtype']) {
@@ -592,12 +601,11 @@
                        case SYSMAP_ELEMENT_TYPE_IMAGE:
                                $selements[$snum]['elementName'] = $images[$selement['iconid_off']]['name'];
                                break;
+                       case SYSMAP_ELEMENT_TYPE_TRIGGER:
+                               $selements[$snum]['elementExpressionTrigger'] = $triggers[$selement['elementid']]['expression'];
+                               break;
                }
        }
-
-       if (!empty($triggers)) {
-               add_triggerExpressions($selements, $triggers);
-       }
 }

 function add_triggerExpressions(&$selements, $triggers = array()) {

When we open map for configuring frontend gets all data placed on map.

tomtom RESOLVED
Eduards CLOSED, in this situation API process empty id arrays itself.

Comment by Alexey Pustovalov [ 2012 Dec 18 ]

(7) Monitoring->Events:

4. trigger->get [events.php:339]
Parameters:
Array
(
    [triggerids] => 454202
    [output] => Array
        (
            [0] => description
            [1] => expression
        )

    [selectHosts] => extend
    [preservekeys] => 1
    [expandDescription] => 1
)

We can select for hosts only array('hostid', 'name').

9. trigger->get [events.php:652]
Parameters:
Array
(
    [triggerids] => Array
        (
            [0] => 454202
        )

    [selectHosts] => Array
        (
            [0] => hostid
        )

    [selectTriggers] => extend
    [selectItems] => extend
    [output] => extend
)

selectTriggers is dummy. For items we can use 'selectItems' => array('itemid', 'name', 'value_type'),. For triggers only 'output' => array('triggerid','description', 'expression', 'priority'),.

2. trigger->get [events.php:142]Parameters:
Array
(
    [output] => Array
        (
            [0] => triggerid
            [1] => description
            [2] => expression
        )

    [selectHosts] => Array
        (
            [0] => hostid
            [1] => host
        )

    [selectItems] => extend
    [selectFunctions] => extend
    [triggerids] => 454202
)

Is also calls for Monitoring->Events->Discovery page.

tomtom RESOLVED
Eduards CLOSED

Comment by Alexey Pustovalov [ 2012 Dec 19 ]

(8) Monitoring->Triggers:

5. trigger->get [tr_status.php:357]
Parameters:
Array
(
    [nodeids] => 0
    [triggerids] => Array
        (
            [0] => 399433
        )

    [output] => extend
    [selectHosts] => Array
        (
            [0] => hostid
            [1] => name
            [2] => maintenance_status
            [3] => maintenance_type
            [4] => maintenanceid
            [5] => description
        )

    [selectItems] => extend
    [selectDependencies] => extend
    [expandDescription] => 1
)

We can replace 'selectItems' => API_OUTPUT_EXTEND by 'selectItems' => array('itemid', 'name', 'key_', 'value_type'),

tomtom RESOLVED
Eduards CLOSED

Comment by Alexey Pustovalov [ 2012 Dec 19 ]

(9) Configuration->Templates:

4. template->get [templates.php:510]Parameters:
Array
(
    [templateids] => Array
        (
            [0] => 98367
        )

    [editable] => 1
    [output] => extend
    [selectHosts] => Array
        (
            [0] => hostid
            [1] => name
            [2] => status
        )

    [selectTemplates] => Array
        (
            [0] => hostid
            [1] => name
            [2] => status
        )

    [selectParentTemplates] => Array
        (
            [0] => hostid
            [1] => name
            [2] => status
        )

    [selectItems] => count
    [selectTriggers] => count
    [selectGraphs] => count
    [selectApplications] => count
    [selectDiscoveries] => count
    [selectScreens] => count
    [nopermissions] => 1
)

We can replace [output] => extend by 'output' => array('hostid', 'name', 'status', 'proxy_hostid'),

tomtom RESOLVED
Eduards CLOSED

Comment by Toms (Inactive) [ 2012 Dec 20 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-6006

Comment by Alexey Pustovalov [ 2012 Dec 20 ]

(10)

7. image->get [maps.inc.php:574]Parameters:
Array
(
    [imageids] => Array
        (
            [0] => 31
            [1] => 52
            [2] => 31
            [3] => 31
            [4] => 31
            [5] => 31
            [6] => 31
...
            [368] => 31
        )

    [output] => extend
    [nopermissions] => 1
    [nodeids] => Array
        (
        )

    [preservekeys] => 1
)

imageids array should be unique. Also all other map element arrays should be unique also. It is function: add_elementNames in maps.inc.php file.

tomtom RESOLVED in r32582
Eduards CLOSED

Comment by Eduards Samersovs (Inactive) [ 2013 Jan 09 ]

Tested!

Comment by Toms (Inactive) [ 2013 Jan 09 ]

Fixed in 2.0.5rc1 r32599, 2.1.0 r32600

Comment by Ronald Schaten [ 2013 Jan 11 ]

In blocks.inc.php, make_latest_issues(): 'expandDescription' can be set true when getting the triggers. You wouldn't need the CEventHelper::expandDescription() later on, which seems to be kind of faulty.

We use

{ITEM.VALUE}

in a trigger description, and expanding with CEventHelper::expandDescription() it always shows '6d 23h 57m'. The API returns the right description, though.

Comment by richlv [ 2013 Jan 17 ]

ronald, could you please create a new issue about that ? thanks

Comment by Alexander Vladishev [ 2013 Feb 04 ]

(11) broken configuration of maps: cannot save map global urls

tomtom
Only in trunk.
Unsuccessful merge to trunk.
Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-6006 r33394

oleg.egorov CLOSED

Comment by Oleg Egorov (Inactive) [ 2013 Feb 05 ]

TESTED.

Comment by Toms (Inactive) [ 2013 Feb 07 ]

Fixed in 2.1.0 r33462

Generated at Fri Apr 19 18:18:52 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.