Skip to content

Instantly share code, notes, and snippets.

@avivl
Last active Feb 4, 2018
Embed
What would you like to do?
def calc_slope(self, minuets):
"""
Calculate the slope of available memory change.
:param: minuets how long to go back in time
"""
met = metrics.Metrics(self.cluster_name)
series = met.read_timeseries('YARNMemoryAvailablePercentage', minuets)
retlist = []
x = []
y = []
retlist.extend(series[0]['points'])
i = len(retlist)
for rl in retlist:
x.insert(0, rl['value']['doubleValue'])
y.insert(0, i)
i = i - 1
try:
slope, intercept = np.polyfit(x, y, 1)
logging.debug('Slope is %s', slope)
except np.RankWarning:
# not enough data so add remove by 2
if self.scaling_direction == 'up':
slope = 1
else:
slope = -1
logging.debug('No Data slope is %s', slope)
return slope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment