load.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. /**
  20. * @class
  21. *
  22. * This is a view for showing cluster load
  23. *
  24. * @extends App.ChartLinearTimeView
  25. * @extends Ember.Object
  26. * @extends Ember.View
  27. */
  28. App.ChartClusterMetricsLoad = App.ChartLinearTimeView.extend({
  29. id: "cluster-metrics-load",
  30. url: "/data/cluster_metrics/load_1hr.json",
  31. url: function () {
  32. return App.formatUrl(App.apiPrefix + "/clusters/{clusterName}?fields=metrics/load[{fromSeconds},{toSeconds},{stepSeconds}]", {
  33. clusterName: App.router.get('clusterController.clusterName')
  34. }, "/data/cluster_metrics/load_1hr.json");
  35. }.property('App.router.clusterController.clusterName'),
  36. renderer: 'line',
  37. title: "Cluster Load",
  38. transformToSeries: function(jsonData){
  39. var seriesArray = [];
  40. if (jsonData && jsonData.metrics && jsonData.metrics.load) {
  41. for ( var name in jsonData.metrics.load) {
  42. var displayName = name;
  43. var seriesData = jsonData.metrics.load[name];
  44. if (seriesData) {
  45. // Is it a string?
  46. if ("string" == typeof seriesData) {
  47. seriesData = JSON.parse(seriesData);
  48. }
  49. // We have valid data
  50. var series = {};
  51. series.name = displayName;
  52. series.data = [];
  53. for ( var index = 0; index < seriesData.length; index++) {
  54. series.data.push({
  55. x: seriesData[index][1],
  56. y: seriesData[index][0]
  57. });
  58. }
  59. seriesArray.push(series);
  60. }
  61. }
  62. }
  63. return seriesArray;
  64. }
  65. });