Skip to content

Commit

Permalink
[FEAT][Caluclate pricing]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Feb 24, 2024
1 parent d8b321e commit 094f51a
Show file tree
Hide file tree
Showing 6 changed files with 655 additions and 2 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ tensorrt
torch
einops
tiktoken
uvicorn
uvicorn
loguru
pydantic
File renamed without changes.
83 changes: 83 additions & 0 deletions scripts/hive.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
provider "aws" {
region = "us-west-2" # Choose an appropriate region
}

resource "aws_security_group" "allow_http" {
name = "allow_http"
description = "Allow HTTP inbound traffic"

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_launch_template" "gpu_instance" {
name_prefix = "gpu-instance-"
image_id = "ami-123456" # Specify an appropriate AMI for your GPU instance
instance_type = "p3.2xlarge" # This is an example GPU instance type. Adjust based on your needs.

network_interfaces {
associate_public_ip_address = true
security_groups = [aws_security_group.allow_http.id]
}

user_data = <<-EOF
#!/bin/bash
echo "Your setup script goes here. This could install Docker, your application, etc."
EOF
}

resource "aws_autoscaling_group" "gpu_asg" {
launch_template {
id = aws_launch_template.gpu_instance.id
version = "$Latest"
}

min_size = 1
max_size = 3
desired_capacity = 2
vpc_zone_identifier = ["subnet-12345"] # Specify your subnet IDs

tag {
key = "Name"
value = "GPUInstance"
propagate_at_launch = true
}
}

resource "aws_elb" "api_load_balancer" {
name = "api-lb"
availability_zones = ["us-west-2a", "us-west-2b"] # Adjust based on your VPC and subnet setup

listener {
instance_port = 80
instance_protocol = "HTTP"
lb_port = 80
lb_protocol = "HTTP"
}

health_check {
target = "HTTP:80/"
interval = 30
timeout = 5
healthy_threshold = 2
unhealthy_threshold = 2
}

instances = [aws_autoscaling_group.gpu_asg.*.id]
cross_zone_load_balancing = true
idle_timeout = 400
connection_draining = true
connection_draining_timeout = 400
}

104 changes: 104 additions & 0 deletions scripts/hive2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
provider "aws" {
region = "us-west-2"
}

# Define an Application Load Balancer
resource "aws_lb" "example" {
name = "example-lb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.lb_sg.id]
subnets = [aws_subnet.example1.id, aws_subnet.example2.id]

enable_deletion_protection = false
}

# Define a target group for the ALB
resource "aws_lb_target_group" "example" {
name = "example-tg"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.example.id

health_check {
enabled = true
path = "/"
protocol = "HTTP"
matcher = "200"
}
}

# Launch Template
resource "aws_launch_template" "example" {
name_prefix = "example-lt-"
image_id = "ami-1234567890abcdef0" # Replace with a valid AMI ID
instance_type = "t2.micro"

# Add other configurations as necessary, such as key name, security groups, etc.
}

# Auto Scaling Group
resource "aws_autoscaling_group" "example" {
launch_template {
id = aws_launch_template.example.id
version = "$Latest"
}

min_size = 1
max_size = 10
desired_capacity = 2
vpc_zone_identifier = [aws_subnet.example1.id, aws_subnet.example2.id]
target_group_arns = [aws_lb_target_group.example.arn]
}

# CloudWatch Alarm for Scaling Out
resource "aws_cloudwatch_metric_alarm" "high_cpu" {
alarm_name = "high-cpu-usage"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 300
statistic = "Average"
threshold = 75
alarm_actions = [aws_autoscaling_policy.scale_out.arn]

dimensions = {
AutoScalingGroupName = aws_autoscaling_group.example.name
}
}

# Scaling Policy for Out
resource "aws_autoscaling_policy" "scale_out" {
name = "scale-out"
scaling_adjustment = 1
adjustment_type = "ChangeInCapacity"
autoscaling_group_name = aws_autoscaling_group.example.name
cooldown = 300
}

# CloudWatch Alarm for Scaling In
resource "aws_cloudwatch_metric_alarm" "low_cpu" {
alarm_name = "low-cpu-usage"
comparison_operator = "LessThanThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 300
statistic = "Average"
threshold = 25
alarm_actions = [aws_autoscaling_policy.scale_in.arn]

dimensions = {
AutoScalingGroupName = aws_autoscaling_group.example.name
}
}

# Scaling Policy for In
resource "aws_autoscaling_policy" "scale_in" {
name = "scale-in"
scaling_adjustment = -1
adjustment_type = "ChangeInCapacity"
autoscaling_group_name = aws_autoscaling_group.example.name
cooldown = 300
}
Loading

0 comments on commit 094f51a

Please sign in to comment.