|
77 | 77 | );
|
78 | 78 | }
|
79 | 79 | }
|
80 |
| - $params['StartTime'] = date('Y-m-d H:i:s', time() - 14 * 86400); |
81 |
| - $params['EndTime'] = date('Y-m-d H:i:s', time()); |
82 |
| - $params['Period'] = 3600; |
83 |
| - $params['Statistics'] = $statistics; |
84 | 80 |
|
| 81 | + $latest = time() - 14 * 86400; |
85 | 82 | try {
|
86 |
| - $stats = $awsClient->getMetricStatistics($params); |
87 | 83 |
|
88 |
| - $datapoints = array(); |
| 84 | + $results = $influxClient->$influxCreds['database']->query(" |
| 85 | + SELECT * |
| 86 | + FROM {$columnName} |
| 87 | + LIMIT 1 |
| 88 | + "); |
| 89 | + foreach ($results as $row) { |
| 90 | + $latest = $row->time; |
| 91 | + } |
| 92 | + } catch (Exception $e) { |
| 93 | + echo "Exception - maybe series doesn't exist for {$columnName}\n"; |
| 94 | + } |
89 | 95 |
|
90 |
| - foreach ($stats['Datapoints'] as $point) { |
91 |
| - echo " {$metric} @ {$point['Timestamp']} \t"; |
92 |
| - $thisPoint = array( |
93 |
| - 'time' => strtotime($point['Timestamp']), |
94 |
| - ); |
95 |
| - foreach ($statistics as $stat) { |
96 |
| - $thisPoint[$stat] = (float)$point[$stat]; |
97 |
| - echo "\t{$stat} => {$point[$stat]}"; |
| 96 | + echo "Looking for data since {$latest}\n"; |
| 97 | + |
| 98 | + $remaining = ceil((time() - $latest) / 60); |
| 99 | + $page = 0; |
| 100 | + $influxDb = $influxClient->$influxCreds['database']; |
| 101 | + |
| 102 | + do { |
| 103 | + echo "Requesting page {$page} with remaining={$remaining}\n"; |
| 104 | + |
| 105 | + $params['StartTime'] = date('Y-m-d H:i:s', $latest); |
| 106 | + $params['EndTime'] = date('Y-m-d H:i:s', $latest + 60 * 1440); |
| 107 | + $params['Period'] = 60; |
| 108 | + $params['Statistics'] = $statistics; |
| 109 | + |
| 110 | + try { |
| 111 | + $stats = $awsClient->getMetricStatistics($params); |
| 112 | + |
| 113 | + $datapoints = array(); |
| 114 | + |
| 115 | + foreach ($stats['Datapoints'] as $point) { |
| 116 | + echo " {$metric} @ {$point['Timestamp']} \t"; |
| 117 | + $thisPoint = array( |
| 118 | + 'time' => strtotime($point['Timestamp']), |
| 119 | + ); |
| 120 | + foreach ($statistics as $stat) { |
| 121 | + $thisPoint[$stat] = (float)$point[$stat]; |
| 122 | + echo "\t{$stat} => {$point[$stat]}"; |
| 123 | + } |
| 124 | + echo "\n"; |
| 125 | + $datapoints[] = $thisPoint; |
98 | 126 | }
|
99 |
| - echo "\n"; |
100 |
| - $datapoints[] = $thisPoint; |
101 |
| - } |
102 | 127 |
|
103 |
| - $influxDb = $influxClient->$influxCreds['database']; |
104 |
| - $influxDb->insert($columnName, $datapoints); |
| 128 | + if ($datapoints) { |
| 129 | + $influxDb->insert($columnName, $datapoints); |
| 130 | + } |
| 131 | + $remaining -= 1440; |
| 132 | + echo "Bottom of loop with remaining={$remaining}\n"; |
| 133 | + $latest += 60*1440; |
| 134 | + $page++; |
105 | 135 |
|
106 |
| - } catch (Exception $e) { |
107 |
| - echo "EXCEPTION: ".$e->getMessage(); |
108 |
| - } |
| 136 | + } catch (Exception $e) { |
| 137 | + echo "EXCEPTION: ".$e->getMessage(); |
| 138 | + } |
| 139 | + } while ($remaining >= 0); |
109 | 140 | }
|
110 | 141 | }
|
0 commit comments