本文整理汇总了TypeScript中metrix-js/lib/index.MetricsCollector.addMetrics方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MetricsCollector.addMetrics方法的具体用法?TypeScript MetricsCollector.addMetrics怎么用?TypeScript MetricsCollector.addMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类metrix-js/lib/index.MetricsCollector
的用法示例。
在下文中一共展示了MetricsCollector.addMetrics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
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) {
collector.measure(result || {});
}
示例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));