本文整理汇总了TypeScript中metrix-js/lib/index.MetricsCollector类的典型用法代码示例。如果您正苦于以下问题:TypeScript MetricsCollector类的具体用法?TypeScript MetricsCollector怎么用?TypeScript MetricsCollector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetricsCollector类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
if (!metrics || !metrics.length) {
console.log('Could not read metric definitions from process.env.METRICS - using default');
metrics = [
{ field: 'code', matcher: 'regex', match: '(\\d)\\d\\d', metric: 'router.hit.$100' },
{ field: 'code', matcher: 'regex', match: '\\d{3}', metric: 'router.hit' },
{ field: 'url', matcher: 'substring', match: 'api/note', metric: 'api.note.hit' },
{ field: 'url', matcher: 'substring', match: 'api/note', metric: 'api.hit' },
{ field: 'url', matcher: 'substring', match: 'api/policy', metric: 'api.hit' }
];
}
let SDC = require('statsd-client');
let sdc = new SDC({host: statsdHost, port: statsdPort});
let collector = new MetricsCollector(metric => {
sdc.increment(metric);
});
collector.addMetrics(metrics);
let patterns = grok.loadDefaultSync('grok-patterns');
let logPattern = patterns.createPattern(logPatternStr);
console.log(`Starting up docker log monitor with parameters:
+ statsdHost = ${ statsdHost }
+ statsdPort = ${ statsdPort }
+ logPatternStr = ${ logPatternStr }
+ selectorLabel = ${ selectorLabel }`);
monitor(function (event) {
function logParsed(err, result) {
if (!err) {
示例2: require
import fs = require('fs');
import { MetricsCollector, MetricItem } from "metrix-js/lib/index";
let inputData = JSON.parse(fs.readFileSync('./data.json').toString());
let metricRules: MetricItem[] = [
{ field: 'code', matcher: 'regex', match: '(\\d)\\d\\d', metric: 'router.hit.$100' },
{ field: 'code', matcher: 'regex', match: '\\d{3}', metric: 'router.hit' },
{ field: 'url', matcher: 'substring', match: 'api/note', metric: 'api.note.hit' },
{ field: 'url', matcher: 'substring', match: 'api/note', metric: 'api.hit' },
{ field: 'url', matcher: 'substring', match: 'api/policy', metric: 'api.hit' }
];
let collector = new MetricsCollector(metric => console.log(metric));
collector.addMetrics(metricRules);
console.log(`For input:
---------------------
${JSON.stringify(inputData, null, 3)}
hits:
---------------------`);
inputData.forEach(item => collector.measure(item));
示例3: logParsed
function logParsed(err, result) {
if (!err) {
collector.measure(result || {});
}
}
示例4:
inputData.forEach(item => collector.measure(item));