Ad Widget

Collapse

Average speed extracted from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcmyst
    Member
    • Feb 2012
    • 72

    #1

    Average speed extracted from database

    Hi,

    I need to extract from database or via API (but I don't see any function to do it via API) the average value of one item in an elapsed time : one month.

    The idea is to have for some network interfaces the average InOctet of the current month, in order to generate billing for our customers.

    Here is what I have done:
    - Select the itemid of the InOctet wanted : 97674

    - Select first 2 values of the months about this item:
    mysql> select * from trends_uint where itemid=97674 AND MONTH(FROM_UNIXTIME(clock))=MONTH(NOW()) LIMIT 0,2;
    +--------+------------+-----+-----------+-----------+-----------+
    | itemid | clock | num | value_min | value_avg | value_max |
    +--------+------------+-----+-----------+-----------+-----------+
    | 97674 | 1377986400 | 60 | 3800 | 4630 | 7144 |
    | 97674 | 1377990000 | 59 | 832 | 4177 | 7720 |
    +--------+------------+-----+-----------+-----------+-----------+


    - Then, average the value_avg of these first 2 items:
    mysql> select ROUND(AVG(value_avg)) from trends_uint where itemid=97674 AND MONTH(FROM_UNIXTIME(clock))=MONTH(NOW()) GROUP BY itemid LIMIT 0,2;
    +-----------------------+
    | ROUND(AVG(value_avg)) |
    +-----------------------+
    | 53063 |
    +-----------------------+


    Could someone tell me here I am wrong ?
    Because my average value should be 4403 and I am getting 53063 ...

    Thank youu

    Regards
    Last edited by mcmyst; 12-09-2013, 11:13.
  • mcmyst
    Member
    • Feb 2012
    • 72

    #2
    I found the solution right after posting...
    It is my LIMIT 0,2 which has no efect on the AVG because it is limiting the rows AFTER having done the AVG. So the AVG was already calculating the average value on the total month and not on only on the to first items.

    Comment

    Working...