Skip to content

Commit

Permalink
Add uptime tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Feb 22, 2024
1 parent ff8fa4b commit 4705f30
Show file tree
Hide file tree
Showing 13 changed files with 770 additions and 213 deletions.
2 changes: 1 addition & 1 deletion requirements.pip
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ eth-account
eth-tester
PyJWT
djangorestframework-simplejwt
hcloud
django-ninja
23 changes: 23 additions & 0 deletions stats-backend/api2/migrations/0013_nodestatushistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.7 on 2024-02-20 23:05

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api2', '0012_offer_cheaper_than_offer_times_cheaper'),
]

operations = [
migrations.CreateModel(
name='NodeStatusHistory',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_online', models.BooleanField()),
('timestamp', models.DateTimeField(auto_now_add=True)),
('provider', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api2.node')),
],
),
]
20 changes: 20 additions & 0 deletions stats-backend/api2/migrations/0014_node_uptime_created_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.7 on 2024-02-21 08:17

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('api2', '0013_nodestatushistory'),
]

operations = [
migrations.AddField(
model_name='node',
name='uptime_created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]
17 changes: 15 additions & 2 deletions stats-backend/api2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Node(models.Model):
version = models.CharField(max_length=7)
updated_at = models.DateTimeField(auto_now=True)
created_at = models.DateTimeField(auto_now_add=True)
uptime_created_at = models.DateTimeField(auto_now_add=True)


class EC2Instance(models.Model):
Expand All @@ -26,6 +27,7 @@ class EC2Instance(models.Model):
def __str__(self):
return self.name


class Offer(models.Model):
properties = models.JSONField(null=True)
runtime = models.CharField(max_length=42)
Expand All @@ -35,11 +37,16 @@ class Offer(models.Model):
monthly_price_glm = models.FloatField(null=True, blank=True)
monthly_price_usd = models.FloatField(null=True, blank=True)
is_overpriced = models.BooleanField(default=False)
overpriced_compared_to = models.ForeignKey(EC2Instance, on_delete=models.CASCADE, null=True)
overpriced_compared_to = models.ForeignKey(
EC2Instance, on_delete=models.CASCADE, null=True
)
suggest_env_per_hour_price = models.FloatField(null=True)
times_more_expensive = models.FloatField(null=True)
cheaper_than = models.ForeignKey(EC2Instance, on_delete=models.CASCADE, null=True, related_name='cheaper_offers')
cheaper_than = models.ForeignKey(
EC2Instance, on_delete=models.CASCADE, null=True, related_name="cheaper_offers"
)
times_cheaper = models.FloatField(null=True)

class Meta:
unique_together = (
"runtime",
Expand All @@ -59,4 +66,10 @@ class GLM(models.Model):
current_price = models.FloatField(null=True)


class NodeStatusHistory(models.Model):
provider = models.ForeignKey(Node, on_delete=models.CASCADE)
is_online = models.BooleanField()
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"{self.provider.node_id} - {'Online' if self.is_online else 'Offline'} at {self.timestamp}"
Loading

0 comments on commit 4705f30

Please sign in to comment.