feat: монолит iot-service (Фаза 1) — config/store/api/bridge/consumer без k8s, устройства в PG, новые Dockerfile/Makefile
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// sqsstats.go — сбор статистики очереди shared-SQS для админ-страницы.
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
sqstypes "github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
)
|
||||
|
||||
// iotAdminSQSStats — информация об очереди для мониторинга.
|
||||
type iotAdminSQSStats struct {
|
||||
ApproximateMessages int64 `json:"approximate_messages"`
|
||||
ApproximateMessagesNotVisible int64 `json:"approximate_messages_not_visible"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// collectSQSStats получает ApproximateNumberOfMessages из очереди телеметрии.
|
||||
func (h *Handler) collectSQSStats(ctx context.Context) iotAdminSQSStats {
|
||||
if h.SQS == nil {
|
||||
return iotAdminSQSStats{Error: "SQS client not configured"}
|
||||
}
|
||||
|
||||
queueUrlOut, err := h.SQS.GetQueueUrl(ctx, &sqs.GetQueueUrlInput{
|
||||
QueueName: aws.String(h.Cfg.SQSQueueName),
|
||||
})
|
||||
if err != nil {
|
||||
return iotAdminSQSStats{Error: fmt.Sprintf("GetQueueUrl: %v", err)}
|
||||
}
|
||||
|
||||
attrsOut, err := h.SQS.GetQueueAttributes(ctx, &sqs.GetQueueAttributesInput{
|
||||
QueueUrl: queueUrlOut.QueueUrl,
|
||||
AttributeNames: []sqstypes.QueueAttributeName{
|
||||
sqstypes.QueueAttributeNameApproximateNumberOfMessages,
|
||||
sqstypes.QueueAttributeNameApproximateNumberOfMessagesNotVisible,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return iotAdminSQSStats{Error: fmt.Sprintf("GetQueueAttributes: %v", err)}
|
||||
}
|
||||
|
||||
approxMsg, _ := strconv.ParseInt(attrsOut.Attributes["ApproximateNumberOfMessages"], 10, 64)
|
||||
approxNotVisible, _ := strconv.ParseInt(attrsOut.Attributes["ApproximateNumberOfMessagesNotVisible"], 10, 64)
|
||||
|
||||
return iotAdminSQSStats{
|
||||
ApproximateMessages: approxMsg,
|
||||
ApproximateMessagesNotVisible: approxNotVisible,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user