network.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 network metrics
  23. *
  24. * @extends App.ChartLinearTimeView
  25. * @extends Ember.Object
  26. * @extends Ember.View
  27. */
  28. App.ChartClusterMetricsNetwork = App.ChartLinearTimeView.extend({
  29. id: "cluster-metrics-network",
  30. url: function () {
  31. return App.formatUrl(App.apiPrefix + "/clusters/{clusterName}?fields=metrics/network[{fromSeconds},{toSeconds},{stepSeconds}]", {
  32. clusterName: App.router.get('clusterController.clusterName')
  33. }, "/data/cluster_metrics/network_1hr.json");
  34. }.property('App.router.clusterController.clusterName'),
  35. title: "Network Usage",
  36. yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
  37. transformToSeries : function (jsonData) {
  38. var seriesArray = [];
  39. if (jsonData && jsonData.metrics && jsonData.metrics.network) {
  40. for ( var name in jsonData.metrics.network) {
  41. var displayName = name;
  42. var seriesData = jsonData.metrics.network[name];
  43. if (seriesData) {
  44. // Is it a string?
  45. if ("string" == typeof seriesData) {
  46. seriesData = JSON.parse(seriesData);
  47. }
  48. // We have valid data
  49. var series = {};
  50. series.name = displayName;
  51. series.data = [];
  52. for ( var index = 0; index < seriesData.length; index++) {
  53. series.data.push({
  54. x: seriesData[index][1],
  55. y: seriesData[index][0]
  56. });
  57. }
  58. seriesArray.push(series);
  59. }
  60. }
  61. }
  62. return seriesArray;
  63. }
  64. });