cpu.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: Em.I18n.t('hosts.host.metrics.cpu'),
  30. yAxisFormatter: App.ChartLinearTimeView.PercentageFormatter,
  31. sourceUrl: "/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}]",
  32. mockUrl: "/data/hosts/metrics/cpu.json",
  33. transformToSeries: function (jsonData) {
  34. var seriesArray = [];
  35. if (jsonData && jsonData.metrics && jsonData.metrics.cpu) {
  36. var cpu_idle;
  37. for ( var name in jsonData.metrics.cpu) {
  38. var displayName;
  39. var seriesData = jsonData.metrics.cpu[name];
  40. switch (name) {
  41. case "cpu_wio":
  42. displayName = "CPU I/O Idle";
  43. break;
  44. case "cpu_idle":
  45. displayName = "CPU Idle";
  46. break;
  47. case "cpu_nice":
  48. displayName = "CPU Nice";
  49. break;
  50. case "cpu_aidle":
  51. displayName = "CPU Boot Idle";
  52. break;
  53. case "cpu_system":
  54. displayName = "CPU System";
  55. break;
  56. case "cpu_user":
  57. displayName = "CPU User";
  58. break;
  59. default:
  60. break;
  61. }
  62. if (seriesData) {
  63. var s = this.transformData(seriesData, displayName);
  64. if ('CPU Idle' == s.name) {
  65. cpu_idle = s;
  66. }
  67. else {
  68. seriesArray.push(s);
  69. }
  70. }
  71. }
  72. seriesArray.push(cpu_idle);
  73. }
  74. return seriesArray;
  75. },
  76. colorForSeries: function (series) {
  77. if ("CPU Idle" == series.name) {
  78. return '#CFECEC';
  79. }
  80. return null;
  81. }
  82. });