|
2 | 2 | import logging |
3 | 3 | from django.conf import settings |
4 | 4 | from django.db import models |
5 | | -from api import influxdb |
6 | 5 | from api.models.release import Release |
7 | 6 | from api.models import UuidAuditedModel |
8 | | -from api.utils import unit_to_bytes, unit_to_millicpu |
9 | 7 | from api.exceptions import DryccException, UnprocessableEntity |
10 | 8 |
|
11 | 9 |
|
@@ -194,36 +192,3 @@ def save(self, **kwargs): |
194 | 192 | self.set_tags({'tags': {}}) |
195 | 193 |
|
196 | 194 | return super(Config, self).save(**kwargs) |
197 | | - |
198 | | - def to_measurements(self, timestamp: float): |
199 | | - assert len(set(self.memory.keys()).difference(self.cpu.keys())) == 0 |
200 | | - stop = int(timestamp) |
201 | | - start = stop - (stop % 3600) |
202 | | - records = {} |
203 | | - app_id, owner_id = str(self.app_id), str(self.owner_id) |
204 | | - for record in influxdb.query_container_count([app_id, ], start, stop): |
205 | | - container_type = record["container_name"].replace(f"{app_id}-", "", 1) |
206 | | - if container_type not in records: |
207 | | - records[container_type] = [] |
208 | | - records[container_type].append(record) |
209 | | - cpu_measurements = [{ |
210 | | - "app_id": app_id, |
211 | | - "user_id": owner_id, |
212 | | - "name": container_type, |
213 | | - "type": "CPU", |
214 | | - "unit": "MILLI", |
215 | | - "usage": unit_to_millicpu( |
216 | | - self.cpu.get(container_type)) * len(records.get(container_type, [])), |
217 | | - "timestamp": "%f" % timestamp |
218 | | - } for container_type in self.cpu.keys()] |
219 | | - memory_measurements = [{ |
220 | | - "app_id": app_id, |
221 | | - "user_id": owner_id, |
222 | | - "name": container_type, |
223 | | - "type": "MEMORY", |
224 | | - "unit": "BYTES", |
225 | | - "usage": unit_to_bytes( |
226 | | - self.memory.get(container_type)) * len(records.get(container_type, [])), |
227 | | - "timestamp": "%f" % timestamp |
228 | | - } for container_type in self.memory.keys()] |
229 | | - return cpu_measurements + memory_measurements |
0 commit comments