Guest User

Untitled

a guest
Dec 16th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. Namespace: env-demo
  2. Resource Used Hard
  3. -------- ---- ----
  4. cpu 14500m 16
  5. memory 16857746636800m 32Gi
  6. persistentvolumeclaims 7 9
  7. pods 12 24
  8. replicationcontrollers 31 36
  9. resourcequotas 1 10
  10. secrets 12 18
  11. services 17 24
  12.  
  13.  
  14. ********************
  15. Name: 2xlarge
  16. Namespace: env-stg
  17. Resource Used Hard
  18. -------- ---- ----
  19. cpu 12 16
  20. memory 28306127360 32Gi
  21. persistentvolumeclaims 8 9
  22. pods 17 24
  23. replicationcontrollers 34 40
  24. resourcequotas 1 10
  25. secrets 13 18
  26. services 20 24
  27.  
  28. ********************
  29.  
  30. import groovy.transform.Field
  31.  
  32. //reading the data file
  33. File result = new File("data")
  34. //writes required information to a new file
  35. def output = new File("output")
  36. def line
  37. @Field def Threshold = 0.8
  38.  
  39. resource_list = [
  40. "cpu","memory", "persistentvolumeclaims", "pods",
  41. "replicationcontrollers", "resourcequotas", "secrets", "services"
  42. ]
  43.  
  44. //method to process the data and returns only if a resource usage is
  45. //above threshold
  46. def process_data(resource){
  47. //check if the resource is part of either cpu or memory
  48. if ( resource[0] in resource_list.take(2)){
  49. //check if above threshold
  50. if ( (resource[2].take(2).toInteger() * Threshold) <= (resource[1].take(2).toInteger())){
  51. return "${resource[0]} " + "utlization is above threshold with usage of " + "${resource[1]} n"
  52. }
  53. }
  54. else if ( (resource[2].toInteger() * Threshold) <= (resource[1].toInteger()) ) {
  55. return "${resource[0]} " + "utlization is above threshold with usage of " + "${resource[1]} n"
  56. }
  57. }
  58.  
  59. result.withReader { reader ->
  60. while ((line = reader.readLine()) != null) {
  61. try {
  62. // find out the project name
  63. if ("Namespace" == "${line}".split(':')[0]){
  64. output.append "#################################### n"
  65. output.append "${line}".split(':')[1].trim() + "n"
  66. output.append "#################################### n"
  67. }
  68. // doing minus do avoid NULL characters
  69. def resource = "${line}".split('t').minus('')
  70. if (resource[0] in resource_list){
  71. def res = process_data(resource)
  72. output.append res.minus('null')
  73. }
  74. }
  75. catch (all){
  76. }
  77.  
  78. }
  79. }
  80.  
  81. # cat output
  82. ####################################
  83. env-demo
  84. ####################################
  85. cpu utlization is above threshold with usage of 14500m
  86. replicationcontrollers utlization is above threshold with usage of 31
  87. ####################################
  88. env-stg
  89. ####################################
  90. memory utlization is above threshold with usage of 28306127360
  91. persistentvolumeclaims utlization is above threshold with usage of 8
  92. replicationcontrollers utlization is above threshold with usage of 34
  93. services utlization is above threshold with usage of 20
Add Comment
Please, Sign In to add comment