[ZBXNEXT-656] New parameter for granularity in history.get Created: 2011 Feb 10  Updated: 2019 Feb 25

Status: Open
Project: ZABBIX FEATURE REQUESTS
Component/s: API (A)
Affects Version/s: 1.8.4
Fix Version/s: None

Type: Change Request Priority: Minor
Reporter: Jacobo Aragunde Pérez Assignee: Unassigned
Resolution: Unresolved Votes: 6
Labels: graphs, history, patch, trends
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File 0001-Added-a-new-parameter-samples_number-in-the-API-op.patch    

 Description   

When retrieving history data through the JSON-RPC API, dealing with data from a wide lapse of time is painful because all the samples are returned, but it's very likely that I don't need such degree of detail.

Take, for example, a use case where I want to draw a chart for one year history. I will need, at most, one sample for each pixel of the chart's width, and not all history.

I propose creating an additional parameter to express the number of samples you want to get. It would divide the history in N groups of the same time length and return an average value for each group. It's different from the limit parameter, which only returns the first N rows of the history.

Since it's an important feature for me, I've started working on a patch that I'll upload here soon. I'm taking inspiration from frontend/php/include/classes/class.cchart.php, function selectData(), which is used to gather history data to build charts in the web frontend.



 Comments   
Comment by richlv [ 2011 Feb 10 ]

first, ability to get trend data might be useful in some cases as well.
second, this vibes well with "data reduction" part in the utopian api wishlist - https://zabbix.org/wiki/Docs/specs/api

Comment by Jacobo Aragunde Pérez [ 2011 Feb 10 ]

Patch. Apply with -p1.

Comment by Jacobo Aragunde Pérez [ 2011 Feb 10 ]

I've just added a patch. I've followed the coding conventions but I'm not sure about the naming of the file and the format of the patch, so please correctly if I'm wrong. I used 1.8.4 version code as base.

What this patch does:

  • Add a new parameter called 'samples_number'. If this parameter is sent and time_from and time_till are sent too, the query will do samples_number groups with equal size and return the average value in each group.
  • I use the table history or trends depending on the degree of detail required and the availability of data. I've taken those conditions from class.cchart.php->selectData(). Not very sure about the second one: ($p / $i) > (ZBX_MAX_TREND_DIFF / ZBX_GRAPH_MAX_SKIP_CELL). Should I remove the division by ZBX_GRAPH_MAX_SKIP_CELL?
Comment by richlv [ 2011 Feb 11 ]

as far as i recall (as a noncoder), ZBX_GRAPH_MAX_SKIP_CELL was used to figure out how many values we may miss before having a gap in the graph, thus i suspect it would not be useful in this case

Comment by richlv [ 2011 Sep 12 ]

maybe this could at least somewhat help with ZBX-3851

Comment by richlv [ 2012 Apr 20 ]

ZBXNEXT-1192 seems to be very similar

Comment by Oleksii Zagorskyi [ 2015 Apr 30 ]

I recall long time ago I was surprised to see ZBX_GRAPH_MAX_SKIP_CELL in the function where we decide where get data from - history or trends.
I could not get why do we use ZBX_GRAPH_MAX_SKIP_CELL here.
This definition being used in another place too, where, IMO, it was implemented for - draw lines or gaps on graphs.

When commenting other issues (ZBXNEXT-2128, ZBX-7821) I again remembered about the unanswered question.
And it may become more important to be checked by devs, because of the issues I mentioned.

My feeling was and still is that we need to split ZBX_GRAPH_MAX_SKIP_CELL to two definitions and use new definition in the function where we select source of data - history or trends.

Comment by Andre Guilhon [ 2015 Jul 07 ]

I would appreciate this feature very much! I'm on 2.4 now, and I still miss this feature!

Generated at Sat Apr 12 19:45:58 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.