-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuma-calculator.js
141 lines (122 loc) · 4.92 KB
/
uma-calculator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// Step 1: change this regular expression to match your UMA daemonset agents
//
function getAgentRegex() {
return "(.*)\\|(.*)\\|(AppContainerMonitor|Kubernetes Agent)";
//return "(.*)\\|Kubernetes Agent";
}
function execute(metricData,javascriptResultSetHelper) {
// Step 2: do you want a summary logged at every calculator execution (every 15 seconds?)
var logSummary = true;
// Step 3: set to 1 to log debug messages at level DEBUG into IntroscopeEnterpriseManager.log
var DEBUG = 0;
//
// DO NOT CHANGE ANYTHING BELOW THIS LINE!
//
var memoryUsage = {};
var memoryRequest = {};
var memoryLimit = {};
var cpuUtilization = {};
var cpuRequest = {};
var cpuLimit = {};
var createdCount = 0;
if (logSummary) {
log.info("calculator uma-calculators.js started with " + metricData.length + " metrics");
}
// for every matching metric
for (var i = 0; i < metricData.length; i++) {
var metric = metricData[i].agentMetric.attributeURL;
var agent = metricData[i].agentName.processURL;
var value = metricData[i].timeslicedValue.value;
var frequency = metricData[i].frequency;
var indexOfColon = metric.indexOf(":");
var metricPath = metric.substring(0, indexOfColon);
var metricName = agent + "|" + metricPath;
if (DEBUG) { log.debug("init " + agent + "|" + metric + " = " + value); }
// store metric in appropriate set
if (metric.endsWith(":Memory Usage (Bytes)")) {
memoryUsage[metricName] = value;
} else if (metric.endsWith(":Memory Request (Bytes)")) {
memoryRequest[metricName] = value;
} else if (metric.endsWith(":Memory Limit (Bytes)")) {
memoryLimit[metricName] = value;
} else if (metric.endsWith(":CPU Utilization (mCore)")) {
cpuUtilization[metricName] = value;
} else if (metric.endsWith(":CPU Request (mCore)")) {
cpuRequest[metricName] = value;
} else if (metric.endsWith(":CPU Limit (mCore)")) {
cpuLimit[metricName] = value;
}
}
// create all memory % metrics
for (metricName in memoryUsage) {
value = 0;
if (memoryLimit[metricName] > 0) {
value = 100 * memoryUsage[metricName] / memoryLimit[metricName];
}
if (DEBUG) { log.debug("creating metric " + metricName + ":Memory Limit Used (%) = " + value); }
javascriptResultSetHelper.addMetric(
metricName + ":Memory Limit Used (%)",
value,
javascriptResultSetHelper.kIntegerPercentage,
frequency
);
createdCount++;
value = 0;
if (memoryRequest[metricName] > 0) {
value = 100 * memoryUsage[metricName] / memoryRequest[metricName];
}
if (DEBUG) { log.debug("creating metric " + metricName + ":Memory Request Used (%) = " + value); }
javascriptResultSetHelper.addMetric(
metricName + ":Memory Request Used (%)",
value,
javascriptResultSetHelper.kIntegerPercentage,
frequency
);
createdCount++;
}
// create all cpu % metrics
for (metricName in cpuUtilization) {
value = 0;
if (cpuLimit[metricName] > 0) {
value = 100 * cpuUtilization[metricName] / cpuLimit[metricName];
}
if (DEBUG) { log.debug("creating metric " + metricName + ":CPU Limit Used (%) = " + value); }
javascriptResultSetHelper.addMetric(
metricName + ":CPU Limit Used (%)",
value,
javascriptResultSetHelper.kIntegerPercentage,
frequency
);
createdCount++;
value = 0;
if (cpuRequest[metricName] > 0) {
value = 100 * cpuUtilization[metricName] / cpuRequest[metricName];
}
if (DEBUG) { log.debug("creating metric " + metricName + ":CPU Request Used (%) = " + value); }
javascriptResultSetHelper.addMetric(
metricName + ":CPU Request Used (%)",
value,
javascriptResultSetHelper.kIntegerPercentage,
frequency
);
createdCount++;
}
if (logSummary) {
log.info("calculator uma-calculators.js created " + createdCount + " metrics");
}
return javascriptResultSetHelper;
}
function getMetricRegex() {
// Include only Memory Usage, Memory Limit, Memory Request, CPU Utilization, CPU Limit, CPU Request of pods and containers
//Kubernetes|Namespaces|cppm10039-dev|Pods|clarity-adminsrv-deployment-5478999bdb-zmgxq|Containers|admin-container:Memory Limit (Bytes)
return "Kubernetes\\|Namespaces\\|.*\\|(Pods|Containers)\\|[^\\|]*:(Memory|CPU)\ (Usage|Utilization|Limit|Request)\ \\((Bytes|mCore)\\)";
}
// must return a multiple of default system frequency (currently 15 seconds)
function getFrequency() {
return 1 * Packages.com.wily.introscope.spec.metric.Frequency.kDefaultSystemFrequencyInSeconds;
}
// Always set to false in case of SaaS
function runOnMOM() {
return false;
}