Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions source/code/plugin/CAdvisorMetricsAPIClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class CAdvisorMetricsAPIClient
@@rxBytesTimeLast = nil
@@txBytesLast = nil
@@txBytesTimeLast = nil
@@nodeCpuUsageNanoSecondsLast = nil
@@nodeCpuUsageNanoSecondsTimeLast = nil
@@telemetryCpuMetricTimeTracker = DateTime.now.to_time.to_i
@@telemetryMemoryMetricTimeTracker = DateTime.now.to_time.to_i


def initialize
end
Expand Down Expand Up @@ -73,7 +76,7 @@ def getMetrics()
metricDataItems.concat(getContainerMemoryMetricItems(metricInfo, hostName, "rssBytes", "memoryRssBytes"))
metricDataItems.concat(getContainerStartTimeMetricItems(metricInfo, hostName, "restartTimeEpoch"))

metricDataItems.push(getNodeMetricItem(metricInfo, hostName, "cpu", "usageNanoCores", "cpuUsageNanoCores"))
metricDataItems.push(getNodeMetricItemRate(metricInfo, hostName, "cpu", "usageCoreNanoSeconds", "cpuUsageNanoCores"))
metricDataItems.push(getNodeMetricItem(metricInfo, hostName, "memory", "workingSetBytes", "memoryWorkingSetBytes"))
metricDataItems.push(getNodeMetricItem(metricInfo, hostName, "memory", "rssBytes", "memoryRssBytes"))
metricDataItems.push(getNodeMetricItem(metricInfo, hostName, "network", "rxBytes", "networkRxBytes"))
Expand Down Expand Up @@ -274,24 +277,41 @@ def getNodeMetricItemRate(metricJSON, hostName, metricCategory, metricNameToColl
metricValue = node[metricCategory][metricNameToCollect]
metricTime = node[metricCategory]['time']

if !(metricNameToCollect == "rxBytes" || metricNameToCollect == "txBytes" )
@Log.warn("getNodeMetricItemRate : rateMetric is supported only for rxBytes & txBytes and not for #{metricNameToCollect}")
if !(metricNameToCollect == "rxBytes" || metricNameToCollect == "txBytes" || metricNameToCollect == "usageCoreNanoSeconds" )
@Log.warn("getNodeMetricItemRate : rateMetric is supported only for rxBytes, txBytes & usageCoreNanoSeconds and not for #{metricNameToCollect}")
return nil
elsif metricNameToCollect == "rxBytes"
if @@rxBytesLast.nil? || @@rxBytesTimeLast.nil?
if @@rxBytesLast.nil? || @@rxBytesTimeLast.nil? || @@rxBytesLast > metricValue #when kubelet is restarted the last condition will be true
@@rxBytesLast = metricValue
@@rxBytesTimeLast = metricTime
return nil
else
metricValue = ((metricValue - @@rxBytesLast) * 1.0)/(DateTime.parse(metricTime).to_time - DateTime.parse(@@rxBytesTimeLast).to_time)
metricRateValue = ((metricValue - @@rxBytesLast) * 1.0)/(DateTime.parse(metricTime).to_time - DateTime.parse(@@rxBytesTimeLast).to_time)
@@rxBytesLast = metricValue
@@rxBytesTimeLast = metricTime
metricValue = metricRateValue
end
else
if @@txBytesLast.nil? || @@txBytesTimeLast.nil?
elsif metricNameToCollect == "txBytes"
if @@txBytesLast.nil? || @@txBytesTimeLast.nil? || @@txBytesLast > metricValue #when kubelet is restarted the last condition will be true
@@txBytesLast = metricValue
@@txBytesTimeLast = metricTime
return nil
else
metricValue = ((metricValue - @@txBytesLast) * 1.0)/(DateTime.parse(metricTime).to_time - DateTime.parse(@@txBytesTimeLast).to_time)
metricRateValue = ((metricValue - @@txBytesLast) * 1.0)/(DateTime.parse(metricTime).to_time - DateTime.parse(@@txBytesTimeLast).to_time)
@@txBytesLast = metricValue
@@txBytesTimeLast = metricTime
metricValue = metricRateValue
end
else
if @@nodeCpuUsageNanoSecondsLast.nil? || @@nodeCpuUsageNanoSecondsTimeLast.nil? || @@nodeCpuUsageNanoSecondsLast > metricValue #when kubelet is restarted the last condition will be true
@@nodeCpuUsageNanoSecondsLast = metricValue
@@nodeCpuUsageNanoSecondsTimeLast = metricTime
return nil
else
metricRateValue = ((metricValue - @@nodeCpuUsageNanoSecondsLast) * 1.0)/(DateTime.parse(metricTime).to_time - DateTime.parse(@@nodeCpuUsageNanoSecondsTimeLast).to_time)
@@nodeCpuUsageNanoSecondsLast = metricValue
@@nodeCpuUsageNanoSecondsTimeLast = metricTime
metricValue = metricRateValue
end
end

Expand Down