cpu.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. /**
  19. * @class
  20. *
  21. * This is a view for showing Host CPU metrics
  22. *
  23. * @extends App.ChartLinearTimeView
  24. * @extends Ember.Object
  25. * @extends Ember.View
  26. */
  27. App.ChartHostMetricsCPU = App.ChartLinearTimeView.extend({
  28. id: "host-metrics-cpu",
  29. title: "CPU Usage",
  30. yAxisFormatter: App.ChartLinearTimeView.PercentageFormatter,
  31. url: function () {
  32. return App.formatUrl(
  33. this.get('urlPrefix') + "/hosts/{hostName}?fields=metrics/cpu/cpu_user[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_wio[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_nice[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_aidle[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_system[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_idle[{fromSeconds},{toSeconds},{stepSeconds}]",
  34. {
  35. hostName: this.get('content').get('hostName')
  36. },
  37. "/data/hosts/metrics/cpu.json"
  38. );
  39. }.property('clusterName').volatile(),
  40. transformToSeries: function (jsonData) {
  41. var seriesArray = [];
  42. if (jsonData && jsonData.metrics && jsonData.metrics.cpu) {
  43. var cpu_idle;
  44. for ( var name in jsonData.metrics.cpu) {
  45. var displayName;
  46. var seriesData = jsonData.metrics.cpu[name];
  47. switch (name) {
  48. case "cpu_wio":
  49. displayName = "CPU I/O Idle";
  50. break;
  51. case "cpu_idle":
  52. displayName = "CPU Idle";
  53. break;
  54. case "cpu_nice":
  55. displayName = "CPU Nice";
  56. break;
  57. case "cpu_aidle":
  58. displayName = "CPU Boot Idle";
  59. break;
  60. case "cpu_system":
  61. displayName = "CPU System";
  62. break;
  63. case "cpu_user":
  64. displayName = "CPU User";
  65. break;
  66. default:
  67. break;
  68. }
  69. if (seriesData) {
  70. var s = this.transformData(seriesData, displayName);
  71. if ('CPU Idle' == s.name) {
  72. cpu_idle = s;
  73. }
  74. else {
  75. seriesArray.push(s);
  76. }
  77. }
  78. }
  79. seriesArray.push(cpu_idle);
  80. }
  81. return seriesArray;
  82. },
  83. colorForSeries: function (series) {
  84. if ("CPU Idle" == series.name) {
  85. return '#CFECEC';
  86. }
  87. return null;
  88. }
  89. });