stats.go

package nsqd

import (
    "sort"
    "sync/atomic"

    "github.com/nsqio/nsq/internal/quantile"
)

type TopicStats struct {
    TopicName    string         `json:"topic_name"`
    Channels     []ChannelStats `json:"channels"`
    Depth        int64          `json:"depth"`
    BackendDepth int64          `json:"backend_depth"`
    MessageCount uint64         `json:"message_count"`
    Paused       bool           `json:"paused"`

    E2eProcessingLatency *quantile.Result `json:"e2e_processing_latency"`
}

func NewTopicStats(t *Topic, channels []ChannelStats) TopicStats {
    return TopicStats{
        TopicName:    t.name,
        Channels:     channels,
        Depth:        t.Depth(),
        BackendDepth: t.backend.Depth(),
        MessageCount: atomic.LoadUint64(&t.messageCount),
        Paused:       t.IsPaused(),

        E2eProcessingLatency: t.AggregateChannelE2eProcessingLatency().Result(),
    }
}

type ChannelStats struct {
    ChannelName   string        `json:"channel_name"`
    Depth         int64         `json:"depth"`
    BackendDepth  int64         `json:"backend_depth"`
    InFlightCount int           `json:"in_flight_count"`
    DeferredCount int           `json:"deferred_count"`
    MessageCount  uint64        `json:"message_count"`
    RequeueCount  uint64        `json:"requeue_count"`
    TimeoutCount  uint64        `json:"timeout_count"`
    Clients       []ClientStats `json:"clients"`
    Paused        bool          `json:"paused"`

    E2eProcessingLatency *quantile.Result `json:"e2e_processing_latency"`
}

func NewChannelStats(c *Channel, clients []ClientStats) ChannelStats {
    return ChannelStats{
        ChannelName:   c.name,
        Depth:         c.Depth(),
        BackendDepth:  c.backend.Depth(),
        InFlightCount: len(c.inFlightMessages),
        DeferredCount: len(c.deferredMessages),
        MessageCount:  atomic.LoadUint64(&c.messageCount),
        RequeueCount:  atomic.LoadUint64(&c.requeueCount),
        TimeoutCount:  atomic.LoadUint64(&c.timeoutCount),
        Clients:       clients,
        Paused:        c.IsPaused(),

        E2eProcessingLatency: c.e2eProcessingLatencyStream.Result(),
    }
}

type ClientStats struct {
    // TODO: deprecated, remove in 1.0
    Name string `json:"name"`

    ClientID        string `json:"client_id"`
    Hostname        string `json:"hostname"`
    Version         string `json:"version"`
    RemoteAddress   string `json:"remote_address"`
    State           int32  `json:"state"`
    ReadyCount      int64  `json:"ready_count"`
    InFlightCount   int64  `json:"in_flight_count"`
    MessageCount    uint64 `json:"message_count"`
    FinishCount     uint64 `json:"finish_count"`
    RequeueCount    uint64 `json:"requeue_count"`
    ConnectTime     int64  `json:"connect_ts"`
    SampleRate      int32  `json:"sample_rate"`
    Deflate         bool   `json:"deflate"`
    Snappy          bool   `json:"snappy"`
    UserAgent       string `json:"user_agent"`
    Authed          bool   `json:"authed,omitempty"`
    AuthIdentity    string `json:"auth_identity,omitempty"`
    AuthIdentityURL string `json:"auth_identity_url,omitempty"`

    TLS                           bool   `json:"tls"`
    CipherSuite                   string `json:"tls_cipher_suite"`
    TLSVersion                    string `json:"tls_version"`
    TLSNegotiatedProtocol         string `json:"tls_negotiated_protocol"`
    TLSNegotiatedProtocolIsMutual bool   `json:"tls_negotiated_protocol_is_mutual"`
}

type Topics []*Topic

func (t Topics) Len() int      { return len(t) }
func (t Topics) Swap(i, j int) { t[i], t[j] = t[j], t[i] }

type TopicsByName struct {
    Topics
}

func (t TopicsByName) Less(i, j int) bool { return t.Topics[i].name < t.Topics[j].name }

type Channels []*Channel

func (c Channels) Len() int      { return len(c) }
func (c Channels) Swap(i, j int) { c[i], c[j] = c[j], c[i] }

type ChannelsByName struct {
    Channels
}

func (c ChannelsByName) Less(i, j int) bool { return c.Channels[i].name < c.Channels[j].name }

func (n *NSQD) GetStats() []TopicStats {
    n.RLock()
    realTopics := make([]*Topic, 0, len(n.topicMap))
    for _, t := range n.topicMap {
        realTopics = append(realTopics, t)
    }
    n.RUnlock()
    sort.Sort(TopicsByName{realTopics})
    topics := make([]TopicStats, 0, len(realTopics))
    for _, t := range realTopics {
        t.RLock()
        realChannels := make([]*Channel, 0, len(t.channelMap))
        for _, c := range t.channelMap {
            realChannels = append(realChannels, c)
        }
        t.RUnlock()
        sort.Sort(ChannelsByName{realChannels})
        channels := make([]ChannelStats, 0, len(realChannels))
        for _, c := range realChannels {
            c.RLock()
            clients := make([]ClientStats, 0, len(c.clients))
            for _, client := range c.clients {
                clients = append(clients, client.Stats())
            }
            c.RUnlock()
            channels = append(channels, NewChannelStats(c, clients))
        }
        topics = append(topics, NewTopicStats(t, channels))
    }
    return topics
}
				
时间: 2024-08-07 16:52:37

stats.go的相关文章

stats.js随时查看fps

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta h

android battery stats

battery stats android 5.1.0-2.0.0 ./frameworks/base/services/jni/com_android_server_BatteryService.cpp android 5.1.0-2.1.0 system/core/healthd

Memcahce(MC)系列(七)Memcached stats命令

Memcached stats命令,对于查看Memcache运行状态来说,是非常有用的. telnet到memcached服务器后有很多的命令可以使用,除了大家熟知的add.get.set.incr.decr.replace.delete等赋值命令外,还有一系列的获取服务器信息的命令,这部分命令都是以stats开头的. 常用的命令: stats显示服务器信息.统计数据等 stats reset清空统计数据 stats cachedump  slab_id  limit_num显示某个slab中的

关于OGG stats 命令的解释

GGSCI (gg321) 19> stats extqd Sending STATS request to EXTRACT EXTQD ... Start of Statistics at 2015-04-18 17:53:06. Output to /u02/ggs/dirdat/qd: Extracting from usera.taba to usea.taba: *** Total statistics since 2015-04-18 17:38:42 *** Total inser

关于OGG的stats 进程名 reset命令

Oracle GoldenGate Command Interpreter for Oracle Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100 Linux, x86, 32bit (optimized), Oracle 10g on Oct 4 2011 23:54:04 Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.

apache hive 无法收集stats问题

环境: hive: apache-hive-1.1.0 hadoop:hadoop-2.5.0-cdh5.3.2 hive元数据以及stats使用mysql进行存储. hive stats相关参数如下: hive.stats.autogather:在insert overwrite命令时自动收集统计信息,默认开启true:设置为true hive.stats.dbclass:存储hive临时统计信息的数据库,默认是jdbc:derby:设置为jdbc:mysql hive.stats.jdbcd

unity---gameScreen 的Stats参数

Unity Stats 面板介绍 原创 2016年06月12日 10:06:12 1544 0 3 Time per frame and FPS (每帧的时间和FPS):处理和渲染一个游戏框架(以及由此产生的FPS)的需要多少时间.请注意,这个数量只包括游戏视图更新和渲染的帧,不包括在编辑器中绘制场景视图,检视窗口和其他仅编辑器进程的时间. Draw Calls(描绘调用):批处理后网格绘制的总数.请注意其中有对象被多次渲染(例如,被像素灯光照亮的物体),每次渲染结果都会导致一个单独的描绘调用.

Memcached 查询stats及各项状态解释

一.两个最常用状态查询(掌握第一个就完全OK了) 1)查看状态:printf “stats\r\n” |nc 127.0.0.1 11211      2)模拟top命令查看状态:watch “echo stats” |nc 127.0.0.1 11211 二.各种stats中文解释.但工作中最常关注的只有四个. STAT get_hits 1(序号,并不是结果,如下)       STAT get_misses 2       STAT curr_items 3       STAT tota

[转] MemCached 的 stats 命令

Memcached有个stats命令,通过它可以查看Memcached服务的许多状态信息.使用方法如下:先在命令行直接输入telnet 主机名端口号,连接到memcached服务器,然后再连接成功后,输入stats 命令,即可显示当前memcached服务的状态信息.比如在我本机测试如下: stats STAT pid 1552 STAT uptime 3792 STAT time 1262517674 STAT version 1.2.6 STAT pointer_size 32 STAT c

Memcache监控工具 -- stats

Memcache监控工具 -- stats 介绍 Memcache的stats命令是最基本的查看memcache状态的工具. 默认实例下,通过telnet 127.0.0.1 11211这样的命令连接上memcache,然后输入stats就可以看到memcache当前的状态. 这些状态的说明如下: pid memcache服务器的进程ID uptime 服务器已经运行的秒数 time 服务器当前的unix时间戳 version memcache版本 pointer_size 当前操作系统的指针大