You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
792 B

  1. package balancer
  2. import (
  3. "fmt"
  4. cmap "github.com/orcaman/concurrent-map/v2"
  5. )
  6. type Balancer struct {
  7. Brokers cmap.ConcurrentMap[string, *BrokerStats]
  8. }
  9. type BrokerStats struct {
  10. TopicPartitionCount int32
  11. MessageCount int64
  12. BytesCount int64
  13. CpuUsagePercent int32
  14. }
  15. type TopicPartition struct {
  16. Topic string
  17. RangeStart int32
  18. RangeStop int32
  19. }
  20. type TopicPartitionStats struct {
  21. TopicPartition
  22. Throughput int64
  23. ConsumerCount int64
  24. TopicPartitionCount int64
  25. }
  26. func NewBalancer() *Balancer {
  27. return &Balancer{
  28. Brokers: cmap.New[*BrokerStats](),
  29. }
  30. }
  31. func NewBrokerStats() *BrokerStats {
  32. return &BrokerStats{}
  33. }
  34. func (tp *TopicPartition) String() string {
  35. return fmt.Sprintf("%v-%04d-%04d", tp.Topic, tp.RangeStart, tp.RangeStop)
  36. }