Skip to content

Instantly share code, notes, and snippets.

@laiwei
Last active June 27, 2017 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save laiwei/4498809 to your computer and use it in GitHub Desktop.
Save laiwei/4498809 to your computer and use it in GitHub Desktop.
perf-counter 接口规范

Perf-Counter 数据接口规范

数据接口协议:

  • http方式
  • json格式

数据格式:

JSON:

{
    "timestamp": 1357441367,
    "data": {
        "endpoint1": {
            "group1": {
                "key1": {
                    "type": 0, 
                    "unit": "req/s", 
                    "value": 250,
                },

                "key2": {
                    "type": 3, 
                    "unit": "qps", 
                    "value": "$(key1)/$(key2)",
                },

                "key3": {
                    "type": 3, 
                    "unit": "", 
                    "value": "delta($(key1))/delta($(key2))",
                },  

                "req1_time": {
                    "type": 0, 
                    "unit": "", 
                    "value": 10
                },  
                "req2_time": {
                    "type": 0, 
                    "unit": "", 
                    "value": 50
                },  
                "req1_counter": {
                    "type": 0, 
                    "unit": "", 
                    "value": 2
                },  
                "req2_counter": {
                    "type": 0, 
                    "unit": "", 
                    "value": 5
                },  
                "req{$1}_speed": {
                    "type": 4, 
                    "rexp": "^req([0-9]+)_",  // 生成这组key,其正则表达式描述,()中的会被捕获标记为$1,$2...
                    "unit": "/s", 
                    "value": $(req{$1}_time) / $req{$1}_counter
                },  
            },
            "group2" :{
            }
        },

        "endpoint2": {
        }
    }
}

说明:

  1. timestamp为数据生成时的时间戳,如果当前时间戳和上次时间戳相同,本次数据会做丢弃处理。

  2. endpoint, 描述counter所在的服务器和端口组合(端口可选)。

  3. group, 描述counter的分组,为了后续能以层级结构展示,注意group不能和别人的group冲突。建议加一个前缀来区分。

  4. key的长度不要超过128, key只允许使用以下字符[0-9a-zA-Z-_.]

  5. key1中的字段可以用-(中划线)来分隔,展示的时候可以根据其做层级划分。

  6. type描述该counter值得类型,值为0,1,2,3或者4。

    type为0,代表As is,即不会对该counter做处理,直接存原始值。

    type为1,代表speed per second,即最终存储的值为 (当前值-上次值)/(当前时间-上次时间)

    type为2,代表simple change,即最终存储的值为当前值-上次值

    type为3,代表dynamic value,即最终存储的值为一个或多个key的简单运算结果

    type为4,描述一组key的复杂生成规则,可参考上面的req{$1}_speed

  7. unit,描述该counter的单位,用作后续的展示。

  8. value,描述counter当前的值,当type为3或者4时,value为表达式。

数据格式例子:

{
    "timestamp": 12345,
    "data": {
        "10.6.2.22:8081" : { // endpoint
        },

        "10.6.2.22:8080" : { // endpoint
            "perf-mfsv2-avatar": { // group, 不要和别人重复
                "upstream_time": { // key, 在该group内不能重复
                    "type": 2,  // 最终存储的值为 simple change,即(当前值-上次值) 
                    "unit": "s", 
                    "value": 9804,
                },

                "upstream_time_counter": {
                    "type": 1,  // 最终存储的值为 speed per second, 即(当前值-上次值)/(当前时间-上次时间)
                    "unit": "次", 
                    "value": 9804,
                },

                "upstream_time_speed": {
                    "type": 3,   // 简单表达式
                    "unit": "次/s", 
                    "value": "delta($(upstream_time))/delta($(upstream_time_counter))", // delta("key") 指的是该counter (当前值-上次值)
                }
                "req1_time": {
                    "type": 0, 
                    "unit": "", 
                    "value": 10
                },  
                "req2_time": {
                    "type": 0, 
                    "unit": "", 
                    "value": 50
                },  
                "req1_counter": {
                    "type": 0, 
                    "unit": "", 
                    "value": 2
                },  
                "req2_counter": {
                    "type": 0, 
                    "unit": "", 
                    "value": 5
                },  
                "req{$1}_speed": {
                    "type": 4,  // 复杂的计算表达式
                    "rexp": "^req([0-9]+)_",  // 生成这组key,其正则表达式描述,()中的会被捕获标记为$1,$2...
                    "unit": "/s", 
                    "value": $(req{$1}_time) / $(req{$1}_counter)
                },  
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment