# zw-service-monitor

> 日志监控上报

Latest version **3.0.11** (published 2023-06-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install zw-service-monitor
pnpm add zw-service-monitor
yarn add zw-service-monitor
bun add zw-service-monitor
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.11 |
| Published | 2023-06-26 |
| First published | 2021-03-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | v_mayachen |
| Maintainers | tianzhaozhao, hellnaren, liu354, luof, shanjunyuan, mayachen1 |

## Links

- npm: https://www.npmjs.com/package/zw-service-monitor
- npm.io page: https://npm.io/package/zw-service-monitor

## Dependencies (2)

- [md5](https://npm.io/package/md5.md) ^2.3.0
- [crypto-js](https://npm.io/package/crypto-js.md) ^4.0.0

## Recent versions

- 3.0.11 (latest) — 2023-06-26
- 3.0.10 — 2023-06-09
- 3.0.9 — 2023-06-05
- 3.0.8 — 2023-04-21
- 3.0.7 — 2023-03-21
- 3.0.6 — 2023-03-20
- 3.0.5 — 2023-03-20
- 3.0.4 — 2023-03-17
- 3.0.3 — 2023-02-24
- 3.0.2 — 2023-02-22
- 3.0.1 — 2023-02-22
- 3.0.0 — 2023-02-20
- 2.1.6-alpha — 2023-02-15
- 2.1.5-alpha — 2023-02-13
- 2.1.4-alpha — 2023-02-13
- … 27 more at https://npm.io/package/zw-service-monitor/versions

## README

# zw-service-monitor

政务方向，服务异常监控

# 监控接入

## 1、 安装依赖
```
npm i zw-service-monitor --save
```

## 2、接入
### 2.1 方式1：原生小程序
直接在 app.js 中引入（zw-service-monitor会重写 request）
```
import 'zw-service-monitor';
```
### 2.2 方式2：可以通过使用 sendFailLog、sendSuccessLog 进行接入
```
import {sendSuccessLog, sendFailLog} = from 'zw-service-monitor/dist/index.js';
```

#### 2.2.1 sendSuccessLog方法参数说明
|参数||类型|说明|
|--|--|--|--|
|params||Object|业务发送接口请求的参数|
||url|String|业务接口地址|
||data|Number|业务请求的参数|
|oldDate||Number|业务请求的时间戳|

#### 2.2.2 sendFailLog方法参数说明
|参数||类型|说明|
|--|--|--|--|
|params||Object|业务发送接口请求的参数|
||url|String|业务接口地址|
||data|Number|业务请求的参数|
|oldDate||Number|业务请求的时间戳|
|err||Object|业务请求失败的报错信息|

## 3、使用demo
```
// 引入
import {sendSuccessLog, sendFailLog} = from 'zw-service-monitor/dist/index.js';

function request() {
    const url = 'https://sfc.baidu.com/shopping/nianhuo/bimai?timestamp=10001';
    const data = {
        tabname: '美食酒水'
    };
    const oldDate = +new Date();
   
   
    // 发起请求
    swan.request({
        url,
        data,
        method: 'POST',
        success: res => {
            // 请求错误
            if (res && res.statusCode !== 200) {
                res.errCode = res.statusCode;
   
   
                // 发送错误日志
                sendFailLog({
                    url,
                    data
                }, oldDate, res);
            } else {
                // 业务接口状态
                if (+res.data.errno === 0) {
                    // 发送成功日志
                    sendSuccessLog({
                        url,
                        data
                    }, oldDate)
                      
                } else {
                    // 发送错误日志
                    sendFailLog({
                        url,
                        data
                    }, oldDate, res);
                }
            } 
        },
        fail: err => {
            // 发送错误日志
            sendFailLog({
                url,
                data
            }, oldDate, err);
        }
    });
}
```


4、 观察工具中以下接口请求是否正常

接口地址：https://minipro.baidu.com/ma/zw/monitor/logreport

请求成功：![图片](https://cityservice-hb.cdn.bcebos.com/amis/img/1d099b911b7d.png)

确认该接口的 form data 的 status 是 success 还是 fail，success 代表业务接口正常，fail 代表业务接口异常

![图片](https://cityservice-hb.cdn.bcebos.com/amis/img/3b965e4c6113.png)

---
_Source: https://npm.io/package/zw-service-monitor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
