diff options
Diffstat (limited to 'weed/mq/topic/local_manager.go')
| -rw-r--r-- | weed/mq/topic/local_manager.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/weed/mq/topic/local_manager.go b/weed/mq/topic/local_manager.go index 6e7db5d08..d0d9def19 100644 --- a/weed/mq/topic/local_manager.go +++ b/weed/mq/topic/local_manager.go @@ -2,6 +2,9 @@ package topic import ( cmap "github.com/orcaman/concurrent-map/v2" + "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" + "github.com/shirou/gopsutil/v3/cpu" + "time" ) // LocalTopicManager manages topics on local broker @@ -53,3 +56,22 @@ func (manager *LocalTopicManager) RemoveTopicPartition(topic Topic, partition Pa } return localTopic.removePartition(partition) } + +func (manager *LocalTopicManager) CollectStats(duration time.Duration) *mq_pb.BrokerStats { + stats := &mq_pb.BrokerStats{} + manager.topics.IterCb(func(topic string, localTopic *LocalTopic) { + for _, localPartition := range localTopic.Partitions { + stats.TopicPartitionCount++ + stats.ConsumerCount += localPartition.ConsumerCount + } + }) + + // collect current broker's cpu usage + usages, err := cpu.Percent(duration, false) + if err == nil && len(usages) > 0 { + stats.CpuUsagePercent = int32(usages[0]) + } + + return stats + +} |
