promjs & monitor


promjs & monitor

API

https://github.com/siimon/prom-client

https://www.npmjs.com/package/promjs

import prom from 'promjs';
 
const registry = prom();
const counter = registry.create('counter', 'my_counter', 'A counter for things');


const counter = registry.create('counter', 'my_counter', 'A counter for things');
//
counter.inc();
console.log(registry.metrics());
// =>
// # HELP my_counter A counter for things \n
// # TYPE my_counter counter
// my_counter 1 \n

demo


const autoReport = (timer = 10000) => {
    window.setInterval(() => {
        const stringData = registry.metrics();
        console.log('重复 bug ???', registry);
        console.log('stringData ???', stringData);
        axios.post(url, stringData).then(() => {
            // 0
            registry.reset();
        });
    }, timer);
};

const manualReport = () => {
    // registry.reset();
    axios.post(url, registry.metrics()).then(() => {
        registry.reset();
    });
};


import prom from 'promjs';
import axios from 'axios';

const registry = prom();
// 打点 API, 新的 1, 旧的 0 ???
const pageRequestsCounter = registry.create('counter', 'page_requests_total');

const pageRetentionTimer = registry.create('histogram', 'page_retention_seconds');

const apiRequestsCounter = registry.create('counter', 'api_requests_total');

const apiRequestsTimer = registry.create('histogram', 'api_requests_duration_seconds');


const url = 'http://metrics.xgqfrms.xyz/metrics/job/app';

const autoReport = (timer = 10000) => {
    window.setInterval(() => {
        console.log('重复 bug ???', registry);
        axios.post(url, registry.metrics()).then(() => {
            // 0
            registry.reset();
        });
    }, timer);
};

const manualReport = () => {
    registry.reset();
    // axios.post(url, registry.metrics()).then(() => {
    //     registry.reset();
    // });
};

refs

Writing client libraries | Prometheus

https://prometheus.io/docs/instrumenting/writing_clientlibs/



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM