Skip to content

Storage calculation for kafka

0

I have AWS MSK Kafka Cluster with 4 brokers i want to get the storage used i cant access / cant find the metric DataStorage in cloudwatch metrices. is there any other metric i can use is there a better way

1 Answer
0
Accepted Answer

To monitor the storage usage of your AWS MSK Kafka cluster, you can use several CloudWatch metrics. While there isn't a direct metric called DataStorage, you can use other related metrics to estimate the storage usage. Here are some steps and alternative metrics to consider:

1. Use the KafkaLogsDiskUsed Metric:

The KafkaLogsDiskUsed metric indicates the amount of disk space used for storing Kafka logs on each broker. This metric can help you estimate the storage used by your Kafka cluster.

2. Check Broker-Level Metrics:

AWS MSK provides metrics at the broker level that can help you monitor storage usage. Some relevant metrics include:

  • KafkaLogsDiskUsed
  • KafkaLogsDiskFree

3. Calculate Storage Usage:

You can calculate the total storage usage by summing the KafkaLogsDiskUsed across all brokers in your cluster. Similarly, you can monitor the available disk space using KafkaLogsDiskFree.

4. Set Up CloudWatch Alarms:

To get alerted when your storage usage exceeds a certain threshold, you can set up CloudWatch Alarms based on these metrics.

Here is an example of how to retrieve and sum the KafkaLogsDiskUsed metric using the AWS CLI:

aws cloudwatch get-metric-statistics \
  --namespace AWS/Kafka \
  --metric-name KafkaLogsDiskUsed \
  --dimensions Name=ClusterName,Value=<YourClusterName> Name=BrokerId,Value=<BrokerId> \
  --start-time 2023-06-01T00:00:00Z \
  --end-time 2023-07-01T00:00:00Z \
  --period 3600 \
  --statistics Average

Replace <YourClusterName> and <BrokerId> with your actual cluster name and broker ID.

If you prefer using a programming language, here is an example in Python using Boto3:

import boto3
from datetime import datetime, timedelta

cloudwatch = boto3.client('cloudwatch')

end_time = datetime.utcnow()
start_time = end_time - timedelta(days=1)

def get_metric(cluster_name, broker_id):
    response = cloudwatch.get_metric_statistics(
        Namespace='AWS/Kafka',
        MetricName='KafkaLogsDiskUsed',
        Dimensions=[
            {'Name': 'ClusterName', 'Value': cluster_name},
            {'Name': 'BrokerId', 'Value': broker_id}
        ],
        StartTime=start_time,
        EndTime=end_time,
        Period=3600,
        Statistics=['Average']
    )
    return response['Datapoints']

# Replace with your cluster name and broker IDs
cluster_name = '<YourClusterName>'
broker_ids = ['<BrokerId1>', '<BrokerId2>', '<BrokerId3>', '<BrokerId4>']

total_storage_used = 0
for broker_id in broker_ids:
    data_points = get_metric(cluster_name, broker_id)
    for data_point in data_points:
        total_storage_used += data_point['Average']

print(f"Total storage used: {total_storage_used} bytes")

By using these metrics and methods, you should be able to monitor and calculate the storage usage of your AWS MSK Kafka cluster.

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.