-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
1563 lines (1368 loc) · 60 KB
/
index.html
File metadata and controls
1563 lines (1368 loc) · 60 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CircleCI Usage Report with Resource Utilization Analysis</title>
<!-- Include Tailwind CSS via CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- PapaParse for CSV parsing -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.2/papaparse.min.js"></script>
<!-- Lodash for data manipulation -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<!-- Chart.js for visualizations -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
</head>
<body class="bg-gray-50">
<div class="container mx-auto p-4">
<!-- Timeframe Banner -->
<div class="bg-blue-50 border-l-4 border-blue-500 text-blue-700 p-4 mb-6 rounded-md">
<p class="font-medium">The data displayed reflects the timeframe selected in the uploaded dataset</p>
</div>
<header class="mb-8">
<h1 class="text-3xl font-bold text-gray-800">CircleCI Usage Report</h1>
<p class="text-gray-600 mt-2">Analyze your CircleCI usage patterns, cost distributions, and resource utilization</p>
</header>
<div id="file-upload" class="mb-8 p-6 bg-white rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Upload CircleCI Usage Report</h2>
<div class="flex flex-col space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">
Select CircleCI Usage Report CSV File
</label>
<input
type="file"
id="csv-file"
accept=".csv"
class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100 cursor-pointer"
>
</div>
<div id="error-message" class="hidden p-4 bg-red-100 text-red-700 rounded-md"></div>
</div>
</div>
<div id="loading" class="hidden mb-8 p-6 bg-white rounded-lg shadow flex items-center justify-center">
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-700"></div>
<span class="ml-3 text-lg">Analyzing your data...</span>
</div>
<div id="results" class="hidden">
<!-- Summary Stats -->
<div class="mb-8 grid grid-cols-1 md:grid-cols-4 gap-4">
<div class="p-4 bg-white rounded-lg shadow">
<h3 class="text-sm font-medium text-gray-500">Total Jobs Analyzed</h3>
<p id="total-jobs" class="mt-1 text-2xl font-semibold text-gray-900">0</p>
</div>
<div class="p-4 bg-white rounded-lg shadow">
<h3 class="text-sm font-medium text-gray-500">Total Credits Used</h3>
<p id="total-credits" class="mt-1 text-2xl font-semibold text-gray-900">0</p>
</div>
<div class="p-4 bg-white rounded-lg shadow">
<h3 class="text-sm font-medium text-gray-500">Success Rate (Jobs)</h3>
<p id="success-rate" class="mt-1 text-2xl font-semibold text-gray-900">0%</p>
</div>
<div class="p-4 bg-white rounded-lg shadow">
<h3 class="text-sm font-medium text-gray-500">Avg. Job Duration</h3>
<p id="avg-duration" class="mt-1 text-2xl font-semibold text-gray-900">0s</p>
</div>
</div>
<!-- NEW: Resource Utilization Insights -->
<div class="mb-8 p-6 bg-white rounded-lg shadow" id="resource-utilization-section">
<h2 class="text-2xl font-bold text-gray-800 mb-4">Resource Utilization Insights</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
<div class="p-4 bg-blue-50 rounded-lg shadow-sm">
<h3 class="text-lg font-medium text-blue-700">Underutilized Jobs</h3>
<p id="underutilized-count" class="mt-1 text-3xl font-semibold text-blue-900">0</p>
<p class="text-sm text-blue-600 mt-1">Jobs with CPU & RAM utilization ≤ 40%</p>
</div>
<div class="p-4 bg-green-50 rounded-lg shadow-sm">
<h3 class="text-lg font-medium text-green-700">Potential Credit Savings</h3>
<p id="potential-savings" class="mt-1 text-3xl font-semibold text-green-900">0</p>
<p class="text-sm text-green-600 mt-1">Estimated savings by right-sizing</p>
</div>
<div class="p-4 bg-amber-50 rounded-lg shadow-sm">
<h3 class="text-lg font-medium text-amber-700">Underprovisioned Jobs</h3>
<p id="overprovisioned-count" class="mt-1 text-3xl font-semibold text-amber-900">0</p>
<p class="text-sm text-amber-600 mt-1">Jobs with CPU or RAM utilization ≥ 80%</p>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-6">
<!-- CPU Utilization Distribution -->
<div class="p-4 bg-white rounded-lg shadow-sm border border-gray-200">
<h3 class="text-lg font-medium text-gray-700 mb-2">CPU Utilization Distribution</h3>
<canvas id="cpu-utilization-chart" height="250"></canvas>
</div>
<!-- RAM Utilization Distribution -->
<div class="p-4 bg-white rounded-lg shadow-sm border border-gray-200">
<h3 class="text-lg font-medium text-gray-700 mb-2">RAM Utilization Distribution</h3>
<canvas id="ram-utilization-chart" height="250"></canvas>
</div>
</div>
<!-- Tabs for Underutilized and Underprovisioned Jobs -->
<div class="mb-6">
<div class="border-b border-gray-200 mb-4">
<nav class="-mb-px flex space-x-8">
<button id="underutilized-tab" class="px-1 py-4 text-sm font-medium text-blue-600 border-b-2 border-blue-600">
Underutilized Jobs
</button>
<button id="overprovisioned-tab" class="px-1 py-4 text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 border-b-2 border-transparent">
Underprovisioned Jobs
</button>
</nav>
</div>
<!-- Underutilized Jobs Tab Content -->
<div id="underutilized-jobs-content">
<h3 class="text-lg font-medium text-gray-700 mb-2">Top 10 Underutilized Jobs (By Total Credits)</h3>
<div id="no-underutilized-message" class="hidden p-4 bg-gray-50 rounded-md text-gray-600">
No jobs found with both CPU and RAM utilization ≤ 40%.
</div>
<div class="overflow-x-auto">
<table id="underutilized-jobs-table" class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Job Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Project</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Resource Class</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Avg. CPU %</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Avg. RAM %</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total Credits</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Suggested Class</th>
</tr>
</thead>
<tbody id="underutilized-jobs-body" class="bg-white divide-y divide-gray-200">
<!-- Table will be populated by JavaScript -->
</tbody>
</table>
</div>
</div>
<!-- Underprovisioned Jobs Tab Content -->
<div id="overprovisioned-jobs-content" class="hidden">
<h3 class="text-lg font-medium text-gray-700 mb-2">Top 10 Underprovisioned Jobs (By High Utilization)</h3>
<div id="no-overprovisioned-message" class="hidden p-4 bg-gray-50 rounded-md text-gray-600">
No jobs found with CPU or RAM utilization ≥ 80%.
</div>
<div class="overflow-x-auto">
<table id="overprovisioned-jobs-table" class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Job Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Project</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Resource Class</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Avg. CPU %</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Avg. RAM %</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total Credits</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Suggested Class</th>
</tr>
</thead>
<tbody id="overprovisioned-jobs-body" class="bg-white divide-y divide-gray-200">
<!-- Table will be populated by JavaScript -->
</tbody>
</table>
</div>
</div>
</div>
<!-- Download Buttons -->
<div class="flex justify-end space-x-4">
<button id="download-overprovisioned-report" class="px-4 py-2 bg-amber-600 text-white text-sm font-medium rounded-md hover:bg-amber-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-amber-500 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
Download Underprovisioned Report
</button>
<button id="download-utilization-report" class="px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
Download Underutilized Report
</button>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
<!-- Top 10 Credit Consuming Projects -->
<div class="p-6 bg-white rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Top 10 Credit Consuming Projects</h2>
<canvas id="projects-credits-chart" height="300"></canvas>
</div>
<!-- Top 10 Credit Consuming Workflows -->
<div class="p-6 bg-white rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Top 10 Credit Consuming Workflows</h2>
<canvas id="workflows-credits-chart" height="300"></canvas>
</div>
<div class="mb-8 p-6 bg-white rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Top 10 Credit Consuming Jobs</h2>
<canvas id="jobs-credits-chart" height="300"></canvas>
</div>
<!-- Daily/Weekly Credit Burn Rate -->
<div class="p-6 bg-white rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Credit Burn Rate</h2>
<div class="flex justify-end mb-2">
<button id="daily-toggle" class="px-3 py-1 bg-blue-600 text-white text-sm font-medium rounded-l-md hover:bg-blue-700">Daily</button>
<button id="weekly-toggle" class="px-3 py-1 bg-gray-200 text-gray-700 text-sm font-medium rounded-r-md hover:bg-gray-300">Weekly</button>
</div>
<canvas id="burn-rate-chart" height="300"></canvas>
</div>
<!-- Credit Usage by Resource Class -->
<div class="p-6 bg-white rounded-lg shadow mt-8">
<h2 class="text-xl font-semibold mb-4">Credit Usage by Resource Class</h2>
<canvas id="resource-class-chart" height="300"></canvas>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
<!-- Actionable Insights Section -->
<div class="mb-8">
<h2 class="text-2xl font-bold text-gray-800 mb-4">Actionable Insights</h2>
<!-- Top 10 Failed Jobs by Credit Cost -->
<div class="p-6 bg-white rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Top 10 Failed Jobs by Credit Cost</h2>
<canvas id="failed-jobs-chart" height="300"></canvas>
</div>
</div>
<!-- Top 10 Longest Running Jobs -->
<div class="p-6 bg-white rounded-lg shadow mb-8">
<h2 class="text-xl font-semibold mb-4">Top 10 Longest Running Jobs</h2>
<canvas id="longest-jobs-chart" height="300"></canvas>
</div>
</div>
<!-- Download Report Button -->
<div class="flex justify-center mt-6 mb-12">
<button id="download-report" class="px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
Download Detailed Report (CSV)
</button>
</div>
</div>
</div>
<script>
// Global variables
let parsedData = [];
let projectsCreditsChart = null;
let workflowsCreditsChart = null;
let longestJobsChart = null;
let resourceClassChart = null;
let burnRateChart = null;
let jobsCreditsChart = null;
let failedJobsChart = null;
let cpuUtilizationChart = null;
let ramUtilizationChart = null;
let showDaily = true;
// Resource utilization thresholds
const UNDERUTILIZATION_THRESHOLD = 40;
const OVERPROVISIONING_THRESHOLD = 80;
// Default branch name - change this as needed
const defaultBranchName = "main";
// Initialize the page
document.addEventListener('DOMContentLoaded', function() {
// Set up file input listener
document.getElementById('csv-file').addEventListener('change', handleFileUpload);
// Set up burn rate toggle buttons
document.getElementById('daily-toggle').addEventListener('click', function() {
showDaily = true;
updateBurnRateToggle();
if (parsedData.length > 0) {
updateBurnRateChart();
}
});
document.getElementById('weekly-toggle').addEventListener('click', function() {
showDaily = false;
updateBurnRateToggle();
if (parsedData.length > 0) {
updateBurnRateChart();
}
});
// Set up utilization tabs
document.getElementById('underutilized-tab').addEventListener('click', function() {
showUnderutilizedTab();
});
document.getElementById('overprovisioned-tab').addEventListener('click', function() {
showOverprovisionedTab();
});
// Set up download buttons
document.getElementById('download-report').addEventListener('click', downloadReport);
document.getElementById('download-utilization-report').addEventListener('click', downloadUtilizationReport);
document.getElementById('download-overprovisioned-report').addEventListener('click', downloadOverprovisionedReport);
});
function showUnderutilizedTab() {
// Update tab styling
document.getElementById('underutilized-tab').classList.add('text-blue-600', 'border-blue-600');
document.getElementById('underutilized-tab').classList.remove('text-gray-500', 'border-transparent');
document.getElementById('overprovisioned-tab').classList.remove('text-blue-600', 'border-blue-600');
document.getElementById('overprovisioned-tab').classList.add('text-gray-500', 'border-transparent');
// Show/hide content
document.getElementById('underutilized-jobs-content').classList.remove('hidden');
document.getElementById('overprovisioned-jobs-content').classList.add('hidden');
}
function showOverprovisionedTab() {
// Update tab styling
document.getElementById('overprovisioned-tab').classList.add('text-blue-600', 'border-blue-600');
document.getElementById('overprovisioned-tab').classList.remove('text-gray-500', 'border-transparent');
document.getElementById('underutilized-tab').classList.remove('text-blue-600', 'border-blue-600');
document.getElementById('underutilized-tab').classList.add('text-gray-500', 'border-transparent');
// Show/hide content
document.getElementById('overprovisioned-jobs-content').classList.remove('hidden');
document.getElementById('underutilized-jobs-content').classList.add('hidden');
}
function handleFileUpload(event) {
const file = event.target.files[0];
if (!file) return;
// Show loading state
document.getElementById('loading').classList.remove('hidden');
document.getElementById('results').classList.add('hidden');
document.getElementById('error-message').classList.add('hidden');
// Parse CSV file
Papa.parse(file, {
header: true,
dynamicTyping: true,
skipEmptyLines: true,
complete: function(results) {
if (results.data.length === 0 || !results.meta.fields) {
showError("The file appears to be empty or invalid");
return;
}
// Basic required columns for the original functionality
const requiredColumns = [
'PROJECT_NAME', 'JOB_NAME', 'WORKFLOW_NAME', 'RESOURCE_CLASS',
'JOB_BUILD_STATUS', 'JOB_RUN_SECONDS', 'TOTAL_CREDITS',
'JOB_RUN_DATE', 'PIPELINE_CREATED_AT', 'VCS_BRANCH'
];
const missingBasicColumns = requiredColumns.filter(col => !results.meta.fields.includes(col));
if (missingBasicColumns.length > 0) {
showError(`Missing required columns: ${missingBasicColumns.join(', ')}`);
return;
}
// Check for resource utilization columns
const utilizationColumns = [
'MEDIAN_CPU_UTILIZATION_PCT', 'MEDIAN_RAM_UTILIZATION_PCT'
];
const missingUtilizationColumns = utilizationColumns.filter(col => !results.meta.fields.includes(col));
// Process data
parsedData = cleanData(results.data);
analyzeData();
// Show/hide resource utilization section based on data availability
if (missingUtilizationColumns.length > 0) {
document.getElementById('resource-utilization-section').classList.add('hidden');
console.warn(`Missing utilization columns: ${missingUtilizationColumns.join(', ')}. Resource utilization analysis will be skipped.`);
} else {
document.getElementById('resource-utilization-section').classList.remove('hidden');
// Update resource utilization analysis
updateResourceUtilizationAnalysis();
}
// Hide loading state
document.getElementById('loading').classList.add('hidden');
document.getElementById('results').classList.remove('hidden');
},
error: function(error) {
showError(`Error parsing CSV: ${error.message}`);
}
});
}
function cleanData(data) {
return data.map(row => {
// Convert string percentages to numbers if needed
if (typeof row.JOB_RUN_SECONDS === 'string') {
row.JOB_RUN_SECONDS = parseFloat(row.JOB_RUN_SECONDS);
}
if (typeof row.TOTAL_CREDITS === 'string') {
row.TOTAL_CREDITS = parseFloat(row.TOTAL_CREDITS);
}
// Clean utilization data
if (typeof row.MEDIAN_CPU_UTILIZATION_PCT === 'string') {
row.MEDIAN_CPU_UTILIZATION_PCT = parseFloat(row.MEDIAN_CPU_UTILIZATION_PCT);
}
if (typeof row.MEDIAN_RAM_UTILIZATION_PCT === 'string') {
row.MEDIAN_RAM_UTILIZATION_PCT = parseFloat(row.MEDIAN_RAM_UTILIZATION_PCT);
}
// Ensure date fields are parsed correctly
if (row.JOB_RUN_DATE && typeof row.JOB_RUN_DATE === 'string') {
row.JOB_RUN_DATE = new Date(row.JOB_RUN_DATE);
}
if (row.PIPELINE_CREATED_AT && typeof row.PIPELINE_CREATED_AT === 'string') {
row.PIPELINE_CREATED_AT = new Date(row.PIPELINE_CREATED_AT);
}
// Ensure VCS_BRANCH exists
if (!row.VCS_BRANCH) {
row.VCS_BRANCH = "unknown";
}
return row;
}).filter(row => {
// Filter out rows with missing essential data
return row.PROJECT_NAME &&
row.JOB_NAME &&
row.WORKFLOW_NAME &&
!isNaN(row.TOTAL_CREDITS) &&
!isNaN(row.JOB_RUN_SECONDS) &&
row.JOB_BUILD_STATUS;
});
}
function analyzeData() {
// Update summary statistics
updateSummaryStats();
// Update all charts
updateProjectsCreditsChart();
updateWorkflowsCreditsChart();
updateLongestJobsChart();
updateResourceClassChart();
updateJobsCreditsChart();
updateBurnRateChart();
updateFailedJobsChart();
}
function updateResourceUtilizationAnalysis() {
// Identify underutilized jobs (both CPU and RAM <= 40%)
const underutilizedJobs = parsedData.filter(job => {
return job.MEDIAN_CPU_UTILIZATION_PCT <= UNDERUTILIZATION_THRESHOLD &&
job.MEDIAN_RAM_UTILIZATION_PCT <= UNDERUTILIZATION_THRESHOLD;
});
// Identify Underprovisioned jobs (either CPU or RAM >= 80%)
const overprovisionedJobs = parsedData.filter(job => {
return job.MEDIAN_CPU_UTILIZATION_PCT >= OVERPROVISIONING_THRESHOLD ||
job.MEDIAN_RAM_UTILIZATION_PCT >= OVERPROVISIONING_THRESHOLD;
});
// Update underutilized count
document.getElementById('underutilized-count').textContent = underutilizedJobs.length.toLocaleString();
// Update overprovisioned count
document.getElementById('overprovisioned-count').textContent = overprovisionedJobs.length.toLocaleString();
// Calculate potential savings
// Assuming we could save ~50% of credits for underutilized jobs by right-sizing
const potentialSavings = Math.round(underutilizedJobs.reduce((sum, job) => sum + (job.TOTAL_CREDITS * 0.5), 0));
document.getElementById('potential-savings').textContent = potentialSavings.toLocaleString();
// Update utilization distribution charts
updateUtilizationCharts();
// Update underutilized jobs table
updateUnderutilizedJobsTable(underutilizedJobs);
// Update overprovisioned jobs table
updateOverprovisionedJobsTable(overprovisionedJobs);
// Enable/disable download buttons
document.getElementById('download-utilization-report').disabled = underutilizedJobs.length === 0;
document.getElementById('download-overprovisioned-report').disabled = overprovisionedJobs.length === 0;
}
function updateOverprovisionedJobsTable(overprovisionedJobs) {
const tableBody = document.getElementById('overprovisioned-jobs-body');
const noJobsMessage = document.getElementById('no-overprovisioned-message');
// Clear existing rows
tableBody.innerHTML = '';
if (overprovisionedJobs.length === 0) {
// Show "no jobs" message
noJobsMessage.classList.remove('hidden');
document.getElementById('overprovisioned-jobs-table').classList.add('hidden');
return;
}
// Hide "no jobs" message and show table
noJobsMessage.classList.add('hidden');
document.getElementById('overprovisioned-jobs-table').classList.remove('hidden');
// Group overprovisioned jobs by name/project to calculate averages
const jobGroups = {};
overprovisionedJobs.forEach(job => {
const key = `${job.JOB_NAME}|${job.PROJECT_NAME}|${job.RESOURCE_CLASS}`;
if (!jobGroups[key]) {
jobGroups[key] = {
job_name: job.JOB_NAME,
project_name: job.PROJECT_NAME,
resource_class: job.RESOURCE_CLASS,
total_credits: 0,
cpuValues: [],
ramValues: [],
count: 0
};
}
jobGroups[key].total_credits += job.TOTAL_CREDITS;
jobGroups[key].cpuValues.push(job.MEDIAN_CPU_UTILIZATION_PCT);
jobGroups[key].ramValues.push(job.MEDIAN_RAM_UTILIZATION_PCT);
jobGroups[key].count++;
});
// Calculate averages
Object.values(jobGroups).forEach(group => {
group.avg_cpu = _.mean(group.cpuValues);
group.avg_ram = _.mean(group.ramValues);
// Determine suggested resource class based on utilization
group.suggested_class = getUpgradedResourceClass(group.resource_class, group.avg_cpu, group.avg_ram);
});
// Sort by highest utilization (using max of CPU and RAM) and get top 10
const sortedGroups = Object.values(jobGroups)
.sort((a, b) => Math.max(b.avg_cpu, b.avg_ram) - Math.max(a.avg_cpu, a.avg_ram))
.slice(0, 10);
// Add rows to table
sortedGroups.forEach(group => {
const row = document.createElement('tr');
// Highlight high utilization values
const cpuClass = group.avg_cpu >= OVERPROVISIONING_THRESHOLD ? 'text-amber-600 font-medium' : 'text-gray-500';
const ramClass = group.avg_ram >= OVERPROVISIONING_THRESHOLD ? 'text-amber-600 font-medium' : 'text-gray-500';
// Add cells
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${group.job_name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.project_name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.resource_class}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm ${cpuClass}">${group.avg_cpu.toFixed(1)}%</td>
<td class="px-6 py-4 whitespace-nowrap text-sm ${ramClass}">${group.avg_ram.toFixed(1)}%</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.total_credits.toFixed(0)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm ${group.suggested_class !== group.resource_class ? 'text-amber-600 font-medium' : 'text-gray-500'}">${group.suggested_class}</td>
`;
tableBody.appendChild(row);
});
}
function getUpgradedResourceClass(currentClass, cpuUtil, ramUtil) {
// Only suggest upgrade if clearly overprovisioned
if (cpuUtil < OVERPROVISIONING_THRESHOLD && ramUtil < OVERPROVISIONING_THRESHOLD) {
return currentClass;
}
// Very high utilization (90%+)
const isHighUtil = cpuUtil >= 90 || ramUtil >= 90;
// For Docker and machine executors
if (currentClass.includes('small')) {
return 'medium';
} else if (currentClass.includes('medium') && !currentClass.includes('medium+')) {
return isHighUtil ? 'large' : currentClass + '+';
} else if (currentClass.includes('medium+')) {
return 'large';
} else if (currentClass.includes('large')) {
return isHighUtil ? '2xlarge' : 'xlarge';
} else if (currentClass.includes('xlarge')) {
return '2xlarge';
} else if (currentClass.includes('2xlarge') && !currentClass.includes('2xlarge+')) {
return '2xlarge+';
}
// If already at largest size or can't determine pattern
return currentClass;
}
function downloadOverprovisionedReport() {
// Identify overprovisioned jobs
const overprovisionedJobs = parsedData.filter(job => {
return job.MEDIAN_CPU_UTILIZATION_PCT >= OVERPROVISIONING_THRESHOLD ||
job.MEDIAN_RAM_UTILIZATION_PCT >= OVERPROVISIONING_THRESHOLD;
});
if (overprovisionedJobs.length === 0) {
alert('No Underprovisioned jobs found.');
return;
}
// Group by job name and project
const jobGroups = {};
overprovisionedJobs.forEach(job => {
const key = `${job.JOB_NAME}|${job.PROJECT_NAME}|${job.RESOURCE_CLASS}`;
if (!jobGroups[key]) {
jobGroups[key] = {
job_name: job.JOB_NAME,
project_name: job.PROJECT_NAME,
workflow_name: job.WORKFLOW_NAME,
resource_class: job.RESOURCE_CLASS,
total_credits: 0,
total_runs: 0,
total_seconds: 0,
cpuValues: [],
ramValues: [],
suggested_class: ''
};
}
jobGroups[key].total_credits += job.TOTAL_CREDITS;
jobGroups[key].total_runs += 1;
jobGroups[key].total_seconds += job.JOB_RUN_SECONDS;
jobGroups[key].cpuValues.push(job.MEDIAN_CPU_UTILIZATION_PCT);
jobGroups[key].ramValues.push(job.MEDIAN_RAM_UTILIZATION_PCT);
});
// Calculate averages and suggested classes
const reportData = Object.values(jobGroups).map(group => {
const avg_cpu = _.mean(group.cpuValues);
const avg_ram = _.mean(group.ramValues);
const suggested_class = getUpgradedResourceClass(group.resource_class, avg_cpu, avg_ram);
return {
job_name: group.job_name,
project_name: group.project_name,
workflow_name: group.workflow_name,
resource_class: group.resource_class,
avg_cpu_pct: avg_cpu.toFixed(1),
avg_ram_pct: avg_ram.toFixed(1),
total_credits: group.total_credits.toFixed(0),
total_runs: group.total_runs,
avg_seconds_per_run: (group.total_seconds / group.total_runs).toFixed(1),
suggested_class: suggested_class,
bottleneck: avg_cpu > avg_ram ? 'CPU' : 'RAM'
};
});
// Sort by highest utilization
reportData.sort((a, b) => {
const maxA = Math.max(parseFloat(a.avg_cpu_pct), parseFloat(a.avg_ram_pct));
const maxB = Math.max(parseFloat(b.avg_cpu_pct), parseFloat(b.avg_ram_pct));
return maxB - maxA;
});
// Convert to CSV
const csv = Papa.unparse(reportData);
// Create download link
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'circleci-overprovisioned-jobs.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function updateUtilizationCharts() {
// CPU Utilization Distribution
updateUtilizationDistributionChart('cpu-utilization-chart', 'MEDIAN_CPU_UTILIZATION_PCT', 'CPU Utilization %', 'rgba(59, 130, 246, 0.6)', 'rgba(59, 130, 246, 1)');
// RAM Utilization Distribution
updateUtilizationDistributionChart('ram-utilization-chart', 'MEDIAN_RAM_UTILIZATION_PCT', 'RAM Utilization %', 'rgba(16, 185, 129, 0.6)', 'rgba(16, 185, 129, 1)');
}
function updateUtilizationDistributionChart(chartId, dataField, label, backgroundColor, borderColor) {
const ctx = document.getElementById(chartId).getContext('2d');
// Create distribution buckets (0-10%, 10-20%, etc.)
const buckets = [
{ min: 0, max: 10, label: '0-10%' },
{ min: 10, max: 20, label: '10-20%' },
{ min: 20, max: 30, label: '20-30%' },
{ min: 30, max: 40, label: '30-40%' },
{ min: 40, max: 50, label: '40-50%' },
{ min: 50, max: 60, label: '50-60%' },
{ min: 60, max: 70, label: '60-70%' },
{ min: 70, max: 80, label: '70-80%' },
{ min: 80, max: 90, label: '80-90%' },
{ min: 90, max: 100, label: '90-100%' }
];
// Count jobs in each bucket
const counts = Array(buckets.length).fill(0);
parsedData.forEach(job => {
const value = job[dataField];
if (value !== undefined && value !== null) {
for (let i = 0; i < buckets.length; i++) {
if (value > buckets[i].min && value <= buckets[i].max) {
counts[i]++;
break;
}
// Handle special case for 0
if (value === 0 && buckets[i].min === 0) {
counts[i]++;
break;
}
}
}
});
// Destroy existing chart if it exists
if (chartId === 'cpu-utilization-chart' && cpuUtilizationChart) {
cpuUtilizationChart.destroy();
} else if (chartId === 'ram-utilization-chart' && ramUtilizationChart) {
ramUtilizationChart.destroy();
}
// Create new chart
const chart = new Chart(ctx, {
type: 'bar',
data: {
labels: buckets.map(b => b.label),
datasets: [{
label: label,
data: counts,
backgroundColor: backgroundColor,
borderColor: borderColor,
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: false
},
tooltip: {
callbacks: {
label: function(context) {
return `Jobs: ${context.raw}`;
}
}
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Number of Jobs'
}
}
}
}
});
// Store chart reference
if (chartId === 'cpu-utilization-chart') {
cpuUtilizationChart = chart;
} else if (chartId === 'ram-utilization-chart') {
ramUtilizationChart = chart;
}
}
function updateUnderutilizedJobsTable(underutilizedJobs) {
const tableBody = document.getElementById('underutilized-jobs-body');
const noJobsMessage = document.getElementById('no-underutilized-message');
// Clear existing rows
tableBody.innerHTML = '';
if (underutilizedJobs.length === 0) {
// Show "no jobs" message
noJobsMessage.classList.remove('hidden');
document.getElementById('underutilized-jobs-table').classList.add('hidden');
return;
}
// Hide "no jobs" message and show table
noJobsMessage.classList.add('hidden');
document.getElementById('underutilized-jobs-table').classList.remove('hidden');
// Group underutilized jobs by name/project to calculate averages
const jobGroups = {};
underutilizedJobs.forEach(job => {
const key = `${job.JOB_NAME}|${job.PROJECT_NAME}|${job.RESOURCE_CLASS}`;
if (!jobGroups[key]) {
jobGroups[key] = {
job_name: job.JOB_NAME,
project_name: job.PROJECT_NAME,
resource_class: job.RESOURCE_CLASS,
total_credits: 0,
cpuValues: [],
ramValues: [],
count: 0
};
}
jobGroups[key].total_credits += job.TOTAL_CREDITS;
jobGroups[key].cpuValues.push(job.MEDIAN_CPU_UTILIZATION_PCT);
jobGroups[key].ramValues.push(job.MEDIAN_RAM_UTILIZATION_PCT);
jobGroups[key].count++;
});
// Calculate averages
Object.values(jobGroups).forEach(group => {
group.avg_cpu = _.mean(group.cpuValues);
group.avg_ram = _.mean(group.ramValues);
// Determine suggested resource class based on utilization
group.suggested_class = getSuggestedResourceClass(group.resource_class, group.avg_cpu, group.avg_ram);
});
// Sort by total credits (highest first) and get top 10
const sortedGroups = Object.values(jobGroups)
.sort((a, b) => b.total_credits - a.total_credits)
.slice(0, 10);
// Add rows to table
sortedGroups.forEach(group => {
const row = document.createElement('tr');
// Add cells
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${group.job_name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.project_name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.resource_class}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.avg_cpu.toFixed(1)}%</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.avg_ram.toFixed(1)}%</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${group.total_credits.toFixed(0)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm ${group.suggested_class !== group.resource_class ? 'text-green-600 font-medium' : 'text-gray-500'}">${group.suggested_class}</td>
`;
tableBody.appendChild(row);
});
}
function isMacOSResourceClass(resourceClass) {
return resourceClass.includes('m4pro') ||
resourceClass.includes('m2pro') ||
resourceClass.includes('macos.m1');
}
function getSuggestedResourceClass(currentClass, cpuUtil, ramUtil) {
// Only suggest downgrade if clearly underutilized
if (cpuUtil > UNDERUTILIZATION_THRESHOLD || ramUtil > UNDERUTILIZATION_THRESHOLD) {
return currentClass;
}
// Check if this is a macOS resource class
if (isMacOSResourceClass(currentClass)) {
// macOS only has .medium and .large sizes (no .small)
// Only suggest downsizing from large to medium
if (currentClass.includes('.large')) {
// Very underutilized - suggest medium
if (cpuUtil <= 30 && ramUtil <= 30) {
return currentClass.replace('.large', '.medium');
}
}
// Already on medium or smallest available - no downsize possible
return currentClass;
}
// Very underutilized resources
const isVeryUnderutilized = cpuUtil <= 30 && ramUtil <= 30;
// For Docker and machine executors
if (currentClass.includes('2xlarge+')) {
return isVeryUnderutilized ? 'xlarge' : '2xlarge';
} else if (currentClass.includes('2xlarge')) {
return isVeryUnderutilized ? 'large' : 'xlarge';
} else if (currentClass.includes('xlarge')) {
return isVeryUnderutilized ? 'medium' : 'large';
} else if (currentClass.includes('large')) {
return 'medium';
} else if (currentClass.includes('medium+')) {
return 'medium';
} else if (currentClass.includes('medium')) {
return 'small';
}
// If we can't determine a better class or already at smallest size
return currentClass;
}
function downloadUtilizationReport() {
// Identify underutilized jobs
const underutilizedJobs = parsedData.filter(job => {
return job.MEDIAN_CPU_UTILIZATION_PCT <= UNDERUTILIZATION_THRESHOLD &&
job.MEDIAN_RAM_UTILIZATION_PCT <= UNDERUTILIZATION_THRESHOLD;
});
if (underutilizedJobs.length === 0) {
alert('No underutilized jobs found.');
return;
}
// Group by job name and project
const jobGroups = {};
underutilizedJobs.forEach(job => {
const key = `${job.JOB_NAME}|${job.PROJECT_NAME}|${job.RESOURCE_CLASS}`;
if (!jobGroups[key]) {
jobGroups[key] = {
job_name: job.JOB_NAME,
project_name: job.PROJECT_NAME,
workflow_name: job.WORKFLOW_NAME,
resource_class: job.RESOURCE_CLASS,
total_credits: 0,
total_runs: 0,
total_seconds: 0,
cpuValues: [],
ramValues: [],
suggested_class: ''
};
}
jobGroups[key].total_credits += job.TOTAL_CREDITS;
jobGroups[key].total_runs += 1;
jobGroups[key].total_seconds += job.JOB_RUN_SECONDS;
jobGroups[key].cpuValues.push(job.MEDIAN_CPU_UTILIZATION_PCT);
jobGroups[key].ramValues.push(job.MEDIAN_RAM_UTILIZATION_PCT);
});
// Calculate averages and suggested classes
const reportData = Object.values(jobGroups).map(group => {
const avg_cpu = _.mean(group.cpuValues);
const avg_ram = _.mean(group.ramValues);
const suggested_class = getSuggestedResourceClass(group.resource_class, avg_cpu, avg_ram);
const estimated_savings = suggested_class !== group.resource_class ?
Math.round(group.total_credits * 0.5) : 0;
return {
job_name: group.job_name,
project_name: group.project_name,
workflow_name: group.workflow_name,
resource_class: group.resource_class,
avg_cpu_pct: avg_cpu.toFixed(1),
avg_ram_pct: avg_ram.toFixed(1),
total_credits: group.total_credits.toFixed(0),
total_runs: group.total_runs,
avg_seconds_per_run: (group.total_seconds / group.total_runs).toFixed(1),
suggested_class: suggested_class,
estimated_credit_savings: estimated_savings
};
});
// Sort by potential savings
reportData.sort((a, b) => parseFloat(b.total_credits) - parseFloat(a.total_credits));
// Convert to CSV
const csv = Papa.unparse(reportData);
// Create download link
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'circleci-underutilized-jobs.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function updateSummaryStats() {
// Total jobs
document.getElementById('total-jobs').textContent = parsedData.length.toLocaleString();
// Total credits
const totalCredits = parsedData.reduce((sum, job) => sum + (job.TOTAL_CREDITS || 0), 0);
document.getElementById('total-credits').textContent = totalCredits.toLocaleString(undefined, {
minimumFractionDigits: 0,
maximumFractionDigits: 0
});
// Success rate
const successfulJobs = parsedData.filter(job => job.JOB_BUILD_STATUS === 'success').length;
const successRate = (successfulJobs / parsedData.length) * 100;
document.getElementById('success-rate').textContent = successRate.toFixed(1) + '%';
// Average duration
const avgDuration = _.meanBy(parsedData, 'JOB_RUN_SECONDS');
document.getElementById('avg-duration').textContent = formatDuration(avgDuration);
}
function updateProjectsCreditsChart() {
const ctx = document.getElementById('projects-credits-chart').getContext('2d');
// Calculate credits by project
const creditsByProject = {};
parsedData.forEach(job => {