Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

artedi

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

artedi - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

3

CHANGES.md

@@ -6,2 +6,5 @@ # Changelog

## 1.2.0
* #9 Create an accessor function for collector values
## 1.1.1

@@ -8,0 +11,0 @@ * [MORAY-447](https://smartos.org/bugview/MORAY-447) strange latency data point

@@ -6,3 +6,3 @@ /*

*
* Copyright (c) 2017, Joyent, Inc.
* Copyright (c) 2018, Joyent, Inc.
*/

@@ -49,2 +49,12 @@ var mod_assert = require('assert-plus');

function getWithLabels(pairs, obj) {
mod_assert.optionalObject(pairs, 'pairs');
if (!pairs || mod_jsprim.isEmpty(pairs)) {
return (obj.metricVec.getDefault());
}
return (obj.metricVec.getWithLabels(pairs));
}
/*

@@ -70,5 +80,7 @@ * Call the 'prometheus()' function on the MetricVector object, which represents

labels: labels,
getWithLabels: getWithLabels,
COUNTER: 'counter',
GAUGE: 'gauge',
HISTOGRAM: 'histogram'
HISTOGRAM: 'histogram',
NOEXISTERROR: 'NoExistError'
};

@@ -6,3 +6,3 @@ /*

*
* Copyright (c) 2017, Joyent, Inc.
* Copyright (c) 2018, Joyent, Inc.
*/

@@ -51,2 +51,15 @@

/*
* Returns the value of a metric with the provided labels.
*/
Counter.prototype.getValue = function getValue(pairs) {
mod_assert.optionalObject(pairs, 'pairs');
var metric = this.getWithLabels(pairs);
if (metric) {
return (metric.getValue());
}
return (new VError({name: lib_common.NOEXISTERROR}));
};
/* Private Functions */

@@ -64,2 +77,10 @@ /*

/*
* Returns a Metric object that represents the labels passed in. Differs from
* this.labels() by returning 'null' if no Metric exists.
*/
Counter.prototype.getWithLabels = function getWithLabels(pairs) {
return (lib_common.getWithLabels(pairs, this));
};
/*
* Call the 'prometheus()' function on the MetricVector object, which represents

@@ -66,0 +87,0 @@ * all of the metrics. Additionally, append the HELP and TYPE lines that are

@@ -6,5 +6,6 @@ /*

*
* Copyright (c) 2017, Joyent, Inc.
* Copyright (c) 2018, Joyent, Inc.
*/
var mod_assert = require('assert-plus');
var VError = require('verror').VError;

@@ -46,2 +47,16 @@ var lib_common = require('./common');

/*
* Returns the value of a metric with the provided labels.
*/
Gauge.prototype.getValue = function getValue(pairs) {
mod_assert.optionalObject(pairs, 'pairs');
var metric = this.getWithLabels(pairs);
if (metric) {
return (metric.getValue());
}
return (new VError({name: lib_common.NOEXISTERROR}));
};
/* Private Functions */

@@ -51,2 +66,7 @@ Gauge.prototype.labels = function labels(pairs) {

};
Gauge.prototype.getWithLabels = function getWithLabels(pairs) {
return (lib_common.getWithLabels(pairs, this));
};
Gauge.prototype.prometheus = function prometheus(cb) {

@@ -53,0 +73,0 @@ lib_common.prometheus(cb, this);

@@ -6,3 +6,3 @@ /*

*
* Copyright (c) 2017, Joyent, Inc.
* Copyright (c) 2018, Joyent, Inc.
*/

@@ -81,4 +81,15 @@

mod_assert.object(labels, 'labels');
/*
* If the user tries to 'get' a metric that has already been assigned
* static labels, we shouldn't accidentally create a second metric with
* identical non-static labels.
*/
if (this.metrics['default'] && mod_jsprim.deepEqual(labels,
this.metrics['default'].labels)) {
return (this.metrics['default']);
}
var lhash = lib_utils.hashObj(labels);
return (this.metrics[lhash] || null);
return (this.metrics[lhash]);
};

@@ -85,0 +96,0 @@

14

lib/metric.js

@@ -6,3 +6,3 @@ /*

*
* Copyright (c) 2017, Joyent, Inc.
* Copyright (c) 2018, Joyent, Inc.
*/

@@ -26,4 +26,4 @@

this.value = 0;
// Unix time in milliseconds of when this metric was last updated.
this.timestamp = 0;
// ISO 8601 time when this metric was last updated.
this.timestamp = null;
}

@@ -40,3 +40,3 @@

this.value += num;
this.timestamp = Date.now();
this.timestamp = new Date().toISOString();
};

@@ -48,7 +48,11 @@

this.value = num;
this.timestamp = Date.now();
this.timestamp = new Date().toISOString();
};
Metric.prototype.getValue = function getValue() {
return (this.value);
};
module.exports = {
Metric: Metric
};
{
"name": "artedi",
"version": "1.1.1",
"version": "1.2.0",
"description": "a metric client library",

@@ -5,0 +5,0 @@ "main": "lib/collector.js",

@@ -65,10 +65,10 @@ # node-artedi: client library for metric collection

// # TYPE http_request_latency_ms histogram
// http_request_latency_ms{le="729"} 0 1499645380000
// http_request_latency_ms{le="2187"} 1 1499645380000
// http_request_latency_ms{le="3645"} 0 1499645380000
// http_request_latency_ms{le="5103"} 0 1499645380000
// http_request_latency_ms{le="6561"} 0 1499645380000
// http_request_latency_ms{le="+Inf"} 1 1499645380000
// http_request_latency_ms_count{} 1 1499645380000
// http_request_latency_ms_sum{} 998 1499645380000
// http_request_latency_ms{zone="e5d3",method="getobject",code="200",le="729"} 0
// http_request_latency_ms{zone="e5d3",method="getobject",code="200",le="2187"} 1
// http_request_latency_ms{zone="e5d3",method="getobject",code="200",le="3645"} 0
// http_request_latency_ms{zone="e5d3",method="getobject",code="200",le="5103"} 0
// http_request_latency_ms{zone="e5d3",method="getobject",code="200",le="6561"} 0
// http_request_latency_ms{zone="e5d3",method="getobject",code="200",le="+Inf"} 1
// http_request_latency_ms_count{zone="e5d3",method="getobject",code="200"} 1
// http_request_latency_ms_sum{zone="e5d3",method="getobject",code="200"} 998
});

@@ -75,0 +75,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc