Skip to content

Commit

Permalink
update perSecond to return float values
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCech committed Nov 10, 2017
1 parent 75f0048 commit ea4974a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions webapp/graphite/render/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,8 @@ def perSecond(requestContext, seriesList, maxValue=None):
&target=perSecond(company.server.application01.ifconfig.TXPackets)
Each time you run ifconfig, the RX and TXPackets are higher (assuming there
is network traffic.) By applying the nonNegativeDerivative function, you can get an
idea of the packets per minute sent or received, even though you're only
is network traffic.) By applying the perSecond function, you can get an
idea of the packets per second sent or received, even though you're only
recording the total.
"""
results = []
Expand All @@ -1607,9 +1607,9 @@ def perSecond(requestContext, seriesList, maxValue=None):

diff = val - prev
if diff >= 0:
newValues.append(diff // step)
newValues.append(round(diff / step, 6))
elif maxValue is not None and maxValue >= val:
newValues.append( ((maxValue - prev) + val + 1) // step )
newValues.append(round((maxValue + diff) / step, 6))
else:
newValues.append(None)

Expand Down
7 changes: 7 additions & 0 deletions webapp/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,13 @@ def test_perSecond(self):
self.assertEqual(list(expected[0]), list(result[0]))
self.assertEqual(expected, result)

def test_perSecond_float(self):
seriesList = self._gen_series_list_with_data(key='test',start=0,end=600,step=60,data=[0, 90, 186, 291, 411, 561, 747, 939, 137, 337])
expected = [TimeSeries('perSecond(test)', 0, 600, 60, [None, 1.5, 1.6, 1.75, 2, 2.5, 3.1, 3.2, 3.3, 3.333333])]
result = functions.perSecond({}, seriesList, maxValue=1000)
self.assertEqual(list(expected[0]), list(result[0]))
self.assertEqual(expected, result)

def test_perSecond_nones(self):
seriesList = self._gen_series_list_with_data(key='test',start=0,end=600,step=60,data=[0, 60, None, 180, None, None, None, 420, None, 540])
expected = [TimeSeries('perSecond(test)', 0, 600, 60, [None, 1, None, 1, None, None, None, 1, None, 1])]
Expand Down

0 comments on commit ea4974a

Please sign in to comment.