Uploaded image for project: 'ZABBIX FEATURE REQUESTS'
  1. ZABBIX FEATURE REQUESTS
  2. ZBXNEXT-8131

Add ability to Suppress / Hide metrics with all 0 values in Graph Widget

    XMLWordPrintable

Details

    • New Feature Request
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 6.0.10
    • None
    • Frontend (F)
    • None

    Description

      I recently had some users ask if it was possible to hide items in the graph widget if the values for that item were all 0. Their use case made sense and it seems that Grafana and Kibana have this feature out of the box. It does appear to have some utility. I looked through the code and was able to create a mock-up that is also functional. I haven't submitted a pull request because I'm not sure that my changes fully fit the Zabbix coding style. But I've attached a screenshot of what it could look like along with the changes to the frontend code. Could this be implemented?

       

       
      include/classes/widgets/forms/CWidgetFormSvgGraph.php
      63                 $field_exclude_zeros = (new CWidgetFieldCheckBox('suppress_zero_values', _('Suppress Zero Values')))->setDefault(SVG_GRAPH_SUPPRESS_ZEROS_FALSE);
       64
       65                 if (array_key_exists('suppress_zero_values', $this->data))

      {  66                         $field_exclude_zeros->setValue($this->data['suppress_zero_values']);  67                 }

       68
       69                 $this->fields[$field_exclude_zeros->getName()] = $field_exclude_zeros;
       
       
      include/classes/helpers/CSvgGraphHelper.php
      62                 if ($options['suppress_zero_values'] == SVG_GRAPH_SUPPRESS_ZEROS_TRUE) {
       63                         foreach ($metrics as $data => $metric) {
       64                                 $all_zero = true;
       65                                 foreach ($metric['points'] as $point) {
       66                                         if (array_key_exists('value', $point)) {
       67                                                 if ($point['value'] != 0 && $point['value'] != 0.0)

      {  68                                                         $all_zero = false;  69                                                         break;  70                                                 }

       71                                         }
       72                                 }
       73                                 if ($all_zero)

      {  74                                         unset($metrics[$data]);  75                                 }

       76                         }
       77                 }
       
       
      include/classes/widgets/views/widget.svggraph.form.view.php216 $tab_displaying_opt = (new CFormList())
      217         ->addRow(CWidgetHelper::getLabel($fields['source'], null,
      218                                         "when choosing 'Trends', aggregation interval must be minimum of 1h if using aggregation functions"),
      219                 CWidgetHelper::getRadioButtonList($fields['source'], $form_name)
      220         )
      221         ->addRow(CWidgetHelper::getLabel($fields['suppress_zero_values'], null,
      222                                         "selecting this option will remove metrics where all values are 0 for the selected time-picker period"),
      223                 CWidgetHelper::getCheckBox($fields['suppress_zero_values'])

      224         );
       
       
      include/defines.inc.php
      define('SVG_GRAPH_SUPPRESS_ZEROS_TRUE',     1);
      define('SVG_GRAPH_SUPPRESS_ZEROS_FALSE',    0);
       
       
      app/controllers/CControllerWidgetSvgGraphView.php
      63                         'suppress_zero_values' => $fields['suppress_zero_values'],
       
       
      js/class.tab-indicators.js
      1233 class GraphOptionsTabIndicatorItem extends TabIndicatorItem {
      1234
      1235         constructor()

      { 1236                 super(TAB_INDICATOR_TYPE_MARK); 1237         }

      1238
      1239         getValue() {
      1240                 const element = document.querySelector("[name='source']:checked");
      1241                 const suppress_zero_values = document.getElementById('suppress_zero_values');
      1242
      1243                 if (element !== null && element.value > 0)

      { 1244                         return true; 1245                 }

      1246
      1247                 if (suppress_zero_values !== null && suppress_zero_values.checked)

      { 1248                         return true; 1249                 }

      1250
      1251                 return false;
      1252         }
      1253
      1254         initObserver() {
      1255                 document.getElementById('tabs').addEventListener(TAB_INDICATOR_UPDATE_EVENT, () =>

      { 1256                         this.addAttributes(); 1257                 }

      );
      1258         }
       

      Attachments

        Activity

          People

            vmurzins Valdis Murzins
            GRyan337 Ryan Eberly
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: