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

staboat

v0.1.0

Published

Staboat 是一种侵入式的线上服务监控系统, 提供对服务接口调用情况的实时监控。

Downloads

3

Readme

Staboat 监控系统

简介

Staboat 是一种侵入式的线上服务监控系统, 提供对服务接口调用情况的实时监控。

设计具有高度拓展性,支持多种服务故障后通知方式:短信、电子邮件、微信公众号等。

动机

  1. 普通的服务是裸奔的, 没有一套控制系统系统掌握它的业务状态变化。
  2. 其次很多监控系统的对接较为复杂,功能超出监控本身要关心的事。
  3. 树课等业务服务已经到达了需要一个监控系统保证它稳定性的时候,
  4. 从外部保证各种业务代码可以放下包袱的开始随心设计。

于是设计了一款具有高拓展性,支持各种系统对接的,支持HTTP Restful API查询的监控系统。

安装

直接执行

git clone https://github.com/Underdog-Studio/staboat

拉取本项目工程目录

视为完成安装

启动监控

先初始化一个配置文件

node ../bin/cli --init

会在当前目录下生成一个配置文件

之后执行

node ../bin/cli -c config.json

即可手动启动监控

图片

向监控报告状态

报告有三种类型,分别是

SUCCESS:代表一个成功的服务调用发生了
ERROR:代表一次失败的服务调用发生了
HEARTBEAT:代表一次心跳报告

通过 npm 安装 staboat

npm install staboat

之后可以导入 staboat 提供的报告器

const {ReporterHelper, UDPReporter} = require("staboat");

通过报告器可以向已经启动的监控系统上报自己的状态

const reporter = new UDPReporter("127.0.0.1:9999");
const helper = new ReporterHelper(reporter);

helper.report({
    serv_id:"testservice",
    level:"SUCCESS"
    msg:"一次API调用成功"
});

helper.report({
    serv_id:"testservice",
    level:"ERROR"
    msg:"一次API调用失败,原因是..."
});

更方便的上报状态

如果使用 jigsaw 对外提供接口

可以向staboat库获取jigsaw适配器

const {ReporterHelper,JigsawAdapter} = require("staboat");
const reporter = new UDPReporter("127.0.0.1:9999");
const helper = new ReporterHelper(reporter);

const adapter = new JigsawAdapter(helper);

...

jigsaw.use(adapter.handle());

之后只要是该jigsaw实例收到一次请求,都会以testservice的服务名自动上报调用情况.

四种服务状态

FINE: 当前服务工作正常
NOTWELL: 当前服务勉强工作
FAILURE: 当前服务故障过于频繁
DOWN: 当前服务已经停止了工作

如果注册了通知器, 通知器在服务改变状态的时候会向你报告这四种状态的切换情况

对外 Restful API 接口

本监控系统可以实时查询服务情况, 以及可以添加服务名, 删除服务名等 以上操作都是标准的 HTTP Restful API

在监控启动后,通过访问 http://127.0.0.1:1000/?path=staboat

可以得到所有Restful API

{
    "error": true,
    "code": 9005,
    "httpcode": 400,
    "message": "Your request format isn't correct.",
    "detail": {
        "/v1/service/id": {
            "desc": "获取当前所有服务标识符",
            "return": "array<serv_id>",
            "method": {
                "get": {},
                "post": {
                    "serv_id": "required"
                },
                "delete": {
                    "serv_id": "required"
                }
            }
        },
        "/v1/service/service": {
            "desc": "获取所有服务的状态信息",
            "return": "array<info>",
            "method": {
                "get": {
                    "id": "string",
                    "detail": "in:true,false"
                }
            }
        },
        "/v1/service/report": {
            "desc": "向服务新增一次报告",
            "return": "void",
            "method": {
                "post": {
                    "id": "required|string",
                    "level": "required|in:SUCCESS,ERROR,HEARTBEAT",
                    "msg": "required|string"
                }
            }
        }
    },
    "type": "object",
    "data": null
}

例如我要调用 /v1/service/service API

请用 GET 等方式(不同的HTTP方式执行结果,要求的参数也是不一样的)

访问 GET http://127.0.0.1:1000/v1/service/service?path=staboat

HTTP的正文必须是一个JSON,提供接口需要的参数,否则HTTP接口会提示你缺少什么参数。