cpu.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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("/api/clusters/{clusterName}/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}]", {
  33. clusterName: App.router.get('clusterController.clusterName')
  34. }, "/data/hosts/metrics/cpu.json");
  35. }.property('App.router.clusterController.clusterName'),
  36. transformToSeries: function (jsonData) {
  37. var seriesArray = [];
  38. if (jsonData && jsonData.metrics && jsonData.metrics.cpu) {
  39. for ( var name in jsonData.metrics.cpu) {
  40. var displayName;
  41. var seriesData = jsonData.metrics.cpu[name];
  42. switch (name) {
  43. case "cpu_wio":
  44. displayName = "CPU I/O Idle";
  45. break;
  46. case "cpu_idle":
  47. displayName = "CPU Idle";
  48. break;
  49. case "cpu_nice":
  50. displayName = "CPU Nice";
  51. break;
  52. case "cpu_aidle":
  53. displayName = "CPU Boot Idle";
  54. break;
  55. case "cpu_system":
  56. displayName = "CPU System";
  57. break;
  58. case "cpu_user":
  59. displayName = "CPU User";
  60. break;
  61. default:
  62. break;
  63. }
  64. if (seriesData) {
  65. // Is it a string?
  66. if ("string" == typeof seriesData) {
  67. seriesData = JSON.parse(seriesData);
  68. }
  69. // We have valid data
  70. var series = {};
  71. series.name = displayName;
  72. series.data = [];
  73. for ( var index = 0; index < seriesData.length; index++) {
  74. series.data.push({
  75. x: seriesData[index][1],
  76. y: seriesData[index][0]
  77. });
  78. }
  79. seriesArray.push(series);
  80. }
  81. }
  82. }
  83. return seriesArray;
  84. },
  85. colorForSeries: function (series) {
  86. if ("Idle" == series.name) {
  87. return 'rgba(255,255,255,1)';
  88. }
  89. return null;
  90. }
  91. });