Skip to content

Commit

Permalink
Merge pull request #454 from ddps-lab/gcp-collector
Browse files Browse the repository at this point in the history
GCP CloudWatch로 수집 개수 전송
  • Loading branch information
red0sena authored Nov 8, 2023
2 parents 5bc0b64 + c4cc06e commit 6a9595c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 21 additions & 0 deletions collector/spot-dataset/gcp/lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ def requests_retry_session(
return session


def upload_cloudwatch(df_current, timestamp):
ondemand_count = len(df_current.drop(columns=['Spot Price', 'Savings']).dropna())
spot_count = len(df_current.drop(columns=['OnDemand Price', 'Savings']).dropna())

cw_client = boto3.client('logs')

log_event = {
'timestamp': int(timestamp.timestamp()),
'message': f'GCPONDEMAND: {ondemand_count} GCPSPOT: {spot_count}'
}

cw_client.put_log_events(
logGroupName=GCP_CONST.LOG_GROUP_NAME,
logStreamName=GCP_CONST.LOG_STREAM_NAME,
logEvents=[log_event]
)


def gcp_collect(timestamp):
# load pricelist
response = requests_retry_session().get(GCP_CONST.API_LINK)
Expand Down Expand Up @@ -78,6 +96,9 @@ def gcp_collect(timestamp):
slack_msg_sender.send_slack_message(e)
print(e)

# upload to cloudwatch data count
upload_cloudwatch(df_current, timestamp)

# # get previous latest_data from s3
object = s3.Object(STORAGE_CONST.BUCKET_NAME, GCP_CONST.S3_LATEST_DATA_SAVE_PATH)
response = object.get()
Expand Down
9 changes: 8 additions & 1 deletion const_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,11 @@ def S3_LATEST_DATA_SAVE_PATH():
@constant
def LOCAL_PATH():
return "/tmp"


@constant
def SPOT_DATA_COLLECTION_LOG_GROUP_NAME():
return "Collection-Data-Count"

@constant
def LOG_STREAM_NAME():
return "GCP-Count"

0 comments on commit 6a9595c

Please sign in to comment.