Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUI Fixed sync checker scritp and CW dashboard #109

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The EC2 instance will deploy, initialize the node and start the first sync. In C
4. Once the initial synchronization is done, you should be able to access the RPC API of that node from within the same VPC. The RPC port is not exposed to the Internet. Check if the JSON-RPC port is open and working — run the following command from a terminal:

```bash
INSTANCE_ID=$(cat single-node-deploy.json | jq -r '..|.node-instance-id? | select(. != null)')
INSTANCE_ID=$(cat single-node-deploy.json | jq -r '..|.nodeinstanceid? | select(. != null)')
NODE_INTERNAL_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text --region us-east-1)
echo "NODE_INTERNAL_IP=$NODE_INTERNAL_IP"
```
Expand Down
25 changes: 25 additions & 0 deletions lib/sui/lib/assets/sync-checker/syncchecker-sui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set +e

source /etc/environment

CURRENT_CHECKPOINT_SEQ_NUMBER=$(curl --location --request POST localhost:9000 --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getLatestCheckpointSequenceNumber", "params": [], "id":1}' | jq -r .result)
CURRENT_CHECKPOINT_TIMESTAMP_MS=$(curl --location --request POST localhost:9000 --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getCheckpoint", "params": ['\"$CURRENT_CHECKPOINT_SEQ_NUMBER\"'], "id":1}' | jq -r .result.timestampMs)

EPOCH_SECONDS=$(date +%s)

# Convert seconds to milliseconds
EPOCH_MS=$((EPOCH_SECONDS * 1000))

CURRENT_CHECKPOINT_MS_BEHIND=$(($EPOCH_MS - $CURRENT_CHECKPOINT_TIMESTAMP_MS))

CURRENT_CHECKPOINT_MIN_BEHIND=$(($CURRENT_CHECKPOINT_MS_BEHIND / 60000))

# Sending data to CloudWatch
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s http://169.254.169.254/latest/meta-data/instance-id)
REGION=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq .region -r)
TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S%:z")

aws cloudwatch put-metric-data --metric-name sui_current_checkpoint_no --namespace CWAgent --value $CURRENT_CHECKPOINT_SEQ_NUMBER --timestamp $TIMESTAMP --dimensions InstanceId=$INSTANCE_ID --region $REGION
aws cloudwatch put-metric-data --metric-name sui_minutes_behind --namespace CWAgent --value $CURRENT_CHECKPOINT_MIN_BEHIND --timestamp $TIMESTAMP --dimensions InstanceId=$INSTANCE_ID --region $REGION
34 changes: 32 additions & 2 deletions lib/sui/lib/assets/user-data/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ echo "Starting CloudWatch Agent"
-a fetch-config -c file:/opt/aws/amazon-cloudwatch-agent/etc/custom-amazon-cloudwatch-agent.json -m ec2 -s
systemctl status amazon-cloudwatch-agent



# Download Sui artifacts
cd $HOME

Expand Down Expand Up @@ -314,6 +312,38 @@ echo "[LOG] Sui Version: $(sui -V)"

echo "Sui Version: $(sui -V)"

cd /opt
sudo mv /opt/sync-checker/syncchecker-sui.sh /opt/syncchecker.sh
sudo chmod +x /opt/syncchecker.sh


echo "Setting up sync-checker service"
cat >/etc/systemd/system/sync-checker.service <<EOL
[Unit]
Description="Sync checker for the node"

[Service]
ExecStart=/opt/syncchecker.sh
EOL

# Run every minute
echo "Setting up sync-checker timer"
cat >/etc/systemd/system/sync-checker.timer <<EOL
[Unit]
Description="Run Sync checker service every minute"

[Timer]
OnCalendar=*:*:0/1
Unit=sync-checker.service

[Install]
WantedBy=multi-user.target
EOL

echo "Starting sync checker timer"
systemctl start sync-checker.timer
systemctl enable sync-checker.timer

# Useful commands (added as comments)
# Check your node logs: journalctl -fu suid -o cat
# Check your node status: sudo service suid status
Expand Down
8 changes: 4 additions & 4 deletions lib/sui/lib/constructs/node-cw-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ export const SyncNodeCWDashboardJSON = {
"type": "metric",
"properties": {
"metrics": [
[ "CWAgent", "sui_current_block", "InstanceId", "${INSTANCE_ID}", { "label": "${INSTANCE_ID}-${INSTANCE_NAME}" } ]
[ "CWAgent", "sui_current_checkpoint_no", "InstanceId", "${INSTANCE_ID}", { "label": "${INSTANCE_ID}-${INSTANCE_NAME}" } ]
],
"sparkline": true,
"view": "timeSeries",
"stacked": false,
"region": "${REGION}",
"stat": "Maximum",
"period": 60,
"title": "Sui Client Block Height"
"title": "Sui Client Checkpoint Seq No"
}
},
{
Expand All @@ -159,9 +159,9 @@ export const SyncNodeCWDashboardJSON = {
"stat": "Maximum",
"period": 60,
"metrics": [
[ "CWAgent", "sui_blocks_behind", "InstanceId", "${INSTANCE_ID}", { "label": "${INSTANCE_ID}-${INSTANCE_NAME}" } ]
[ "CWAgent", "sui_minutes_behind", "InstanceId", "${INSTANCE_ID}", { "label": "${INSTANCE_ID}-${INSTANCE_NAME}" } ]
],
"title": "Sui Client Blocks Behind"
"title": "Sui Client Minutes Behind"
}
},
{
Expand Down
Loading
Loading