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

skyrts

v0.1.11

Published

redis统计系统

Downloads

13

Readme

skyrts

redis 实时统计系统

  • 按秒,分钟,小时,天,周,月,年统计
  • 按每(分钟、小时等)每小时,天,周,月,年聚合
  • 自由设置时间盒子
  • 基础聚合值 Min, Max, Avg, Sum, Range(Max-Min),Count ,First(首次进入值) ,Last(最后进入值)
  • 高级聚合值 M2(二阶中心矩), Var.P(M2/Count),Var.S(M2/(Count-1)), STD.P(Sqrt(Var.P)), STD.S(Sqrt(Var.S))
const rts = require('skyrts')
const Pack = require('./package.json')

rts({
  redis: redis, // 异步redis引用
  redisAsync: redis, // 同步redis引用
  gran: '1s, 5m, 1h, 1d, 1w, 1M, 1y', // 维度的梯度
  points: 1000, // 多少点循环记录,默认500个点
  prefix: Pack.name // 需要一个前缀,区分多项目
})
  • 如果需要 按季度记录,gran 中增加 3M
  • 如果要经常统计全局总值,gran 中增加 9999y 9999 年

主要方法

// 埋点
rts.record(name, num = 1, statistics = ['sum', 'avg'], aggregations, timestamp, callback)
  • 异步记录函数,一般常用此方法
  • name 准备存放的字符串,最终形式是 'rts'+options.prefix + name
  • num 默认 1 sum+=1 否则 sum+=num
  • statistics 默认统计 count 计数,sum 总和,avg 平均值
  • 启用 avg 后,同时计算,m2 二阶中心矩,first 首次进入值,last 最后进入值
  • aggregations {Array} dy (day in week each year), hm(hour of day each month) null 就不处理聚合
  • timestamp 可以补历史记录,默认是当前服务器时间长整型
  • callback 一般不用
// 去重埋点 标准误差为0.81%
rts.recordUnique(name, uniqueId, statistics, aggregations, timestamp, callback)
  • 异步唯一值记录函数,一般常用此方法,记录后不会立刻生效,会在 options.interval || 60000 60 秒刷新唯一值
  • name 准备存放的字符串,最终形式是 'rts'+options.prefix + name
  • uniqueId 唯一标识字符串,可以为数组形式,多个唯一值
  • statistics 默认为空 记录唯一值,如果是 ['sum', 'avg']形式 调用普通 record 函数
  • aggregations {Array} dy (day in week each year), hm(hour of day each month) null 就不处理聚合
  • timestamp 可以补历史记录,默认是当前服务器时间长整型
// 异步获取埋点时间序列
rts.getStat(type, name, granCode, fromDate, toDate, callback)
  • 不常用,看下面同步方法
// 同步获取埋点时间序列
await rts.getStatAsync(type, name, granCode, fromDate, toDate)
  • type sum, min, max, avg, count, uni 唯一值情况
  • name key 的名称
  • granCode 开始 rts 设置的 gran: '1s, 5m, 1h, 1d, 1w, 1M, 1y'
  • fromDate 开始时间 Date 类型
  • toDate 结束时间 Date 类型
  • 可以使用 meeko 中的 data.offset()
const offset = function (interval, number) {
  /**
   * @function [dateAdd&offset]
   * @description 日期偏移操作.
   * @memberof Date_prototype#
   * @param {string} interval - 年月日时分秒周季 yMdhnswq.
   * @param {int} number - 时间间隔 可正负.
   * @return {string} 返回 得到日期年月日等加数字后的日期.
   * @example
   * $.now().offset('y',-1)
   * // 2018-6-1 10:19:01
   */
}

实战例子

demo1