memory.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 memory metrics
  22. *
  23. * @extends App.ChartLinearTimeView
  24. * @extends Ember.Object
  25. * @extends Ember.View
  26. */
  27. App.ChartHostMetricsMemory = App.ChartLinearTimeView.extend({
  28. id: "host-metrics-memory",
  29. title: Em.I18n.t('hosts.host.metrics.memory'),
  30. yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
  31. renderer: 'line',
  32. sourceUrl: "/hosts/{hostName}?fields=metrics/memory/swap_free[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_shared[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_free[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_cached[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_buffers[{fromSeconds},{toSeconds},{stepSeconds}]",
  33. mockUrl: "/data/hosts/metrics/memory.json",
  34. transformToSeries: function (jsonData) {
  35. var seriesArray = [];
  36. var KB = Math.pow(2, 10);
  37. if (jsonData && jsonData.metrics && jsonData.metrics.memory) {
  38. for ( var name in jsonData.metrics.memory) {
  39. var displayName;
  40. var seriesData = jsonData.metrics.memory[name];
  41. switch (name) {
  42. case "mem_shared":
  43. displayName = "Shared";
  44. break;
  45. case "swap_free":
  46. displayName = "Swap";
  47. break;
  48. case "mem_buffers":
  49. displayName = "Buffers";
  50. break;
  51. case "mem_free":
  52. displayName = "Free";
  53. break;
  54. case "mem_cached":
  55. displayName = "Cached";
  56. break;
  57. default:
  58. break;
  59. }
  60. if (seriesData) {
  61. var s = this.transformData(seriesData, displayName);
  62. for (var i = 0; i < s.data.length; i++) {
  63. s.data[i].y *= KB;
  64. }
  65. seriesArray.push(s);
  66. }
  67. }
  68. }
  69. return seriesArray;
  70. }
  71. });