| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | |
| 4 that can be found in the LICENSE file. | |
| 5 | |
| 6 For more on Google Charts and the data format, see https://developers.google.c
om/chart/interactive/docs/datatables_dataviews | |
| 7 --> | |
| 8 | |
| 9 <link rel="import" href="/res/imp/bower_components/polymer/polymer.html"> | |
| 10 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html"> | |
| 11 <link rel="import" href="/res/imp/bower_components/iron-flex-layout/iron-flex-la
yout-classes.html"> | |
| 12 | |
| 13 <link rel="import" href="load-charts-api.html"> | |
| 14 <link rel="import" href="partial-line-chart.html"> | |
| 15 | |
| 16 <dom-module id="stats-overview"> | |
| 17 <style include="iron-flex iron-flex-alignment iron-positioning"> | |
| 18 | |
| 19 </style> | |
| 20 | |
| 21 <template> | |
| 22 <iron-ajax | |
| 23 auto url="/swarming/api/v1/stats/summary/minutes" | |
| 24 headers="[[headers]]" | |
| 25 params="[[params]]" | |
| 26 handle-as="json" | |
| 27 last-response="{{response}}"> | |
| 28 </iron-ajax> | |
| 29 | |
| 30 <load-charts-api loaded="{{charts_api_loaded}}"></load-charts-api> | |
| 31 | |
| 32 <div class="vertical layout charts"> | |
| 33 | |
| 34 <!-- These arrays are JSON, so they must use double quotes--> | |
| 35 <partial-line-chart | |
| 36 all_data="{{data_table}}" | |
| 37 resolution="minutes" | |
| 38 names='["bots_active","tasks_active","tasks_bot_died","tasks_request_exp
ired"]' | |
| 39 title="Shards Activity"> | |
| 40 </partial-line-chart> | |
| 41 | |
| 42 <partial-line-chart | |
| 43 all_data="{{data_table}}" | |
| 44 resolution="minutes" | |
| 45 names='["tasks_avg_pending_secs","tasks_total_runtime_secs","tasks_avg_r
untime_secs"]' | |
| 46 title="Times"> | |
| 47 </partial-line-chart> | |
| 48 | |
| 49 <partial-line-chart | |
| 50 all_data="{{data_table}}" | |
| 51 resolution="minutes" | |
| 52 names='["http_requests","http_failures"]' | |
| 53 title="Requests"> | |
| 54 </partial-line-chart> | |
| 55 | |
| 56 </div> | |
| 57 </template> | |
| 58 <script> | |
| 59 Polymer({ | |
| 60 is: 'stats-overview', | |
| 61 properties: { | |
| 62 // input | |
| 63 // TODO(kjlubick): Update the stats endpoints to use OAuth. | |
| 64 auth_headers: { | |
| 65 type: Object, | |
| 66 } | |
| 67 | |
| 68 //output | |
| 69 busy: { | |
| 70 type: Boolean, | |
| 71 value: false, | |
| 72 notify: true, | |
| 73 }, | |
| 74 data_table: { | |
| 75 type: Object, | |
| 76 computed: "_extractData(response,charts_api_loaded)", | |
| 77 notify: true, | |
| 78 }, | |
| 79 | |
| 80 //private | |
| 81 charts_api_loaded: { | |
| 82 type: Boolean, | |
| 83 }, | |
| 84 _headers: { | |
| 85 type: Object, | |
| 86 value: { | |
| 87 "x-datasource-auth": "a", | |
| 88 }, | |
| 89 }, | |
| 90 params: { | |
| 91 type: Object, | |
| 92 value: { | |
| 93 duration: 20, | |
| 94 }, | |
| 95 }, | |
| 96 response: { | |
| 97 type: Object, | |
| 98 }, | |
| 99 }, | |
| 100 | |
| 101 _extractData: function (_response, ready) { | |
| 102 // Times are coming in like Date(2016,4,13,12,10,0) which is supposed | |
| 103 // to be UTC but the browser interprets as browser local time. We fix | |
| 104 // the dates to be parsed as UTC and the partial-line-chart will show | |
| 105 // times in browser local time. | |
| 106 var table = _response.table; | |
| 107 // Our data looks like https://developers.google.com/chart/interactive/d
ocs/datesandtimes#dates-and-times-using-the-date-string-representation | |
| 108 // i.e. | |
| 109 // rows: [ | |
| 110 // {c: [v: "Date(2016,8,23,14,35,0)", v: ...]} | |
| 111 // {c: ... } | |
| 112 // ] | |
| 113 // and we parse the first part of each datum, the Date. | |
| 114 // TODO(kjlubick): Is there a cleaner way to do this server side? | |
| 115 table.rows.forEach(function(r) { | |
| 116 var time = r.c[0].v; | |
| 117 if (time.startsWith && time.startsWith("Date")) { | |
| 118 // Remove the Date() wrapper | |
| 119 time = time.substring(5, time.length-1); | |
| 120 // Split into an array of arguments | |
| 121 time = time.split(","); | |
| 122 // Parse and store. | |
| 123 r.c[0].v = new Date(Date.UTC(...time)) | |
| 124 } | |
| 125 }); | |
| 126 return _response.table; | |
| 127 }, | |
| 128 }); | |
| 129 </script> | |
| 130 </dom-module> | |
| OLD | NEW |