npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pitrix/cloudsat-convertor

v1.0.5

Published

cloudsat 监控接口数据转换工具

Downloads

98

Readme

data-convertor2.0

cloudsat 监控接口数据转换工具

安装

npm install @QCFE/data-convertor2.0

用法

import Converter from '@QCFE/data-convertor2.0';

const { result, tags, searchMonitorData } = new Converter(resdata, opts).toLineChart(true);

参数说明

resdata

{
  "data": [
    {
      "monitor_data": [{...}],
      "resource_id": "lbl-g7i7737y",
      "metric_name": "b_rsp_3xx",
      "metric_cn_name": "后端 HTTP 3xx 响应数",
      "metric_unit": "%",
      "create_time": "2022-08-29T16:36:43.061534Z",
      "user_id": "usr-rrPKHDpJ",
      "description": "后端 HTTP 3xx 响应数",
      "step": 10,
      "tags": "node_idx=0,eip_id=eip-3mgnl28l"
    }
  ],
  "ret_code": 0,
  "total_count": 56
}

opts

|参数项|类型|含义|示例| |---|---|---|---| |namespace|string|命名空间|可取值:'common'|'namespace-cloudsat-instance'|'namespace-cloudsat-vol'|'namespace-cloudsat-eip'|'namespace-cloudsat-loadbalancer'| 'namespace-cloudsat-loadbalancer-backend'|'namespace-cloudsat-loadbalancer-listener'|'namespace-cloudsat-nat'| |dateFormat(可选)|string|x轴的时间格式,moment支持的dateFormat格式|'YYYY-MM-DD HH:mm:ss'| |precision(可选)|number|数据转换后的小数位,默认值:2|-| |labelByTag(可选)|string|指定tag name成为lenged label,lb, 集群专用|-| |seriesByTag(可选)|string|指定tag name划分series|-| |metrics(可选)|Partial<Record<MetricsType, Record<'label', string>>>|详细的mertics label名称配置|{"rx": {"label": "带宽-进"},"tx": {"label": "带宽-出"}| |byteTrasnform(可选)|boolean|单位byte是否转化为bit|true| |lang(可选)|'zh-cn'|'cn'|语言|'zh-cn'| |showMaxMinMetrics(可选)|string[]|是否展示指标的最大值和最小值,默认不展示|[]| |legendTruncateLength(可选)|number|legend label展示的宽度,如果超出会默认按...展示|150| |dimension(可选)|DimensionType|选择展示的数据是平均值,最大值还是最小值,showMaxMinMetrics 没有指定当前meter时生效|'avgValue' |

实例方法

|方法名|含义|参数| |---|---|---| |toLineChart|返回echart折线图格式的数据|true(默认):同系列不同指标转成相同的单位false:同系统不同值班转换成各自适合的单位| |getData|返回基本的key,value格式数据|true(默认):同系列不同指标转成相同的单位false:同系统不同值班转换成各自适合的单位|

返回值

result(toLineChart)

[
  {
    "key": "traffic",
    {
      "key": "traffic",
      "value": [
        {
          "echartData": {
            "xAxis": {
              "data": [
                "2022-08-28 08:20",
                "2022-08-28 10:00"
              ]
            },
            "series": [
              {
                "name": "outbound",
                "type": "line",
                "data": [
                  {
                    "value": 400,
                    "name": "2022-08-28 08:20:00"
                  },
                  {
                    "value": 0,
                    "name": "2022-08-28 10:00:00"
                  }
                ]
              },
              {
                "name": "inbound",
                "type": "line",
                "data": [
                  {
                    "value": 800,
                    "name": "2022-08-28 08:20:00"
                  },
                  {
                    "value": 0,
                    "name": "2022-08-28 10:00:00"
                  },
                ]
              }
            ],
            "legend": {
              "data": [
                "inbound",
                "outbound"
              ]
            }
          },
          "attrs": [
            {
              "label": "outbound",
              "unit": "bps",
              "metric_name": "rx",
              "meter_type": "traffic",
              "tags": "node_idx=0|eip_id=eip-3mgnl28l",
              "step": 6000
            },
            {
              "label": "inbound",
              "unit": "bps",
              "metric_name": "tx",
              "meter_type": "traffic",
              "tags": "node_idx=0|eip_id=eip-3mgnl28l",
              "step": 6000
            }
          ],
          "tags": "node_idx=0|eip_id=eip-3mgnl28l"
        }
      ]
    }
  }
]

result(getData)

[
  {
    "key": "traffic",
    "value": [
      {
        "data": [
          {
            "value": 400,
            "time": "2022-08-28 08:20"
          },
          {
            "value": 0,
            "time": "2022-08-28 10:00"
          }
        ],
        "label": "inbound",
        "unit": "bps",
        "metric_name": "rx",
        "meter_type": "traffic",
        "tags": "node_idx=0|eip_id=eip-3mgnl28l",
        "step": 6000
      },
      {
        "data": [
          {
            "value": 800,
            "time": "2022-08-28 08:20"
          },
          {
            "value": 0,
            "time": "2022-08-28 10:00"
          }
        ],
        "label": "outbound",
        "unit": "bps",
        "metric_name": "tx",
        "meter_type": "traffic",
        "tags": "node_idx=0|eip_id=eip-3mgnl28l",
        "step": 6000
      }
    ]
  }
]

tags

 "tags": {
    "node_idx": [
      "0",
      "1"
    ],
    "eip_id": [
      "eip-3mgnl28l",
      "eip-n1ldbmpn"
    ]
  }

searchMonitorData

const monitor = searchMonitorData({key: 'cpu', searchWords: ['node_idx=0']});

|参数|类型|含义|示例| |---|---|---|---| |key|string|metric key|'cpu', 'traffic'...| |searchWords|string[]|查询的关键字,根据 tags 模糊匹配|'node_idx=0'|