Skip to content

Commit

Permalink
Bug fixes to the metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jeniawhite authored and nimrod-becker committed Jul 24, 2019
1 parent c7e8650 commit b40b322
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions src/server/analytic_services/prometheus_reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const METRIC_RECORDS = Object.freeze([{
configuration: {
name: get_metric_name('cloud_types'),
help: 'Cloud Resource Types in the System',
labelNames: ['type', 'count']
labelNames: ['type']
}
}, {
metric_type: 'Gauge',
metric_variable: 'projects_capacity_usage',
configuration: {
name: get_metric_name('projects_capacity_usage'),
help: 'Projects Capacity Usage',
labelNames: ['project', 'count']
labelNames: ['project']
}
}, {
metric_type: 'Gauge',
Expand All @@ -39,23 +39,23 @@ const METRIC_RECORDS = Object.freeze([{
configuration: {
name: get_metric_name('bucket_class_capacity_usage'),
help: 'Bucket Class Capacity Usage',
labelNames: ['bucket_class', 'count']
labelNames: ['bucket_class']
}
}, {
metric_type: 'Gauge',
metric_variable: 'unhealthy_cloud_types',
configuration: {
name: get_metric_name('unhealthy_cloud_types'),
help: 'Unhealthy Cloud Resource Types in the System',
labelNames: ['type', 'count']
labelNames: ['type']
}
}, {
metric_type: 'Gauge',
metric_variable: 'object_histo',
configuration: {
name: get_metric_name('object_histo'),
help: 'Object Sizes Histogram Across the System',
labelNames: ['size', 'avg', 'count']
labelNames: ['size', 'avg']
}
}, {
metric_type: 'Gauge',
Expand Down Expand Up @@ -280,16 +280,16 @@ class PrometheusReporting {
set_bucket_class_capacity_usage(usage_info) {
if (!this.enabled()) return;
this._metrics.bucket_class_capacity_usage.reset();
for (let [key, value] of Object.entries(usage_info)) {
this._metrics.bucket_class_capacity_usage.set({ bucket_class: key }, value);
for (let [bucket_class, value] of Object.entries(usage_info)) {
this._metrics.bucket_class_capacity_usage.set({ bucket_class }, value);
}
}

set_projects_capacity_usage(usage_info) {
if (!this.enabled()) return;
this._metrics.projects_capacity_usage.reset();
for (let [key, value] of Object.entries(usage_info)) {
this._metrics.projects_capacity_usage.set({ project: key }, value);
for (let [project, value] of Object.entries(usage_info)) {
this._metrics.projects_capacity_usage.set({ project }, value);
}
}

Expand All @@ -315,18 +315,25 @@ class PrometheusReporting {

set_providers_bandwidth(type, write_size, read_size) {
if (!this.enabled()) return;
this._metrics.providers_bandwidth.reset();
this._metrics.providers_bandwidth.set({ type: type, write_size, read_size }, Date.now());
const { hashMap } = this._metrics.providers_bandwidth;
const hashKey = Object.keys(hashMap).find(key => key.includes(`type:${type}`));
const record = hashMap[hashKey];
if (record) delete this._metrics.providers_bandwidth.hashMap[hashKey];
this._metrics.providers_bandwidth.set({ type, write_size, read_size }, Date.now());
}

set_providers_ops(type, write_num, read_num) {
if (!this.enabled()) return;
this._metrics.providers_ops.reset();
this._metrics.providers_ops.set({ type: type, write_num, read_num }, Date.now());
const { hashMap } = this._metrics.providers_ops;
const hashKey = Object.keys(hashMap).find(key => key.includes(`type:${type}`));
const record = hashMap[hashKey];
if (record) delete this._metrics.providers_ops.hashMap[hashKey];
this._metrics.providers_ops.set({ type, write_num, read_num }, Date.now());
}

set_object_savings(savings) {
if (!this.enabled()) return;
this._metrics.object_savings.reset();
const { logical_size, physical_size } = savings;
this._metrics.object_savings.set({ logical_size, physical_size }, logical_size - physical_size);
}
Expand All @@ -342,41 +349,46 @@ class PrometheusReporting {

set_system_info(info) {
if (!this.enabled()) return;
this._metrics.system_info.set({ system_name: info.name, system_address: info.address }, 0);
this._metrics.system_info.reset();
this._metrics.system_info.set({ system_name: info.name, system_address: info.address }, Date.now());
}

update_providers_bandwidth(type, write_size, read_size) {
if (!this.enabled()) return;
const { hashMap } = this._metrics.providers_bandwidth;
const hashKey = Object.keys(hashMap).find(key => key.includes(`type:${type}`));
const record = hashMap[hashKey];
let updated_labels = {
type,
write_size: (write_size || 0),
read_size: (read_size || 0),
};
if (record) {
const { labels } = record;
const updated_labels = {
type,
write_size: (labels.write_size || 0) + (write_size || 0),
read_size: (labels.read_size || 0) + (read_size || 0),
};
this._metrics.providers_bandwidth.reset();
this._metrics.providers_bandwidth.set(updated_labels, Date.now());
updated_labels.write_size += (labels.write_size || 0);
updated_labels.read_size += (labels.read_size || 0);
delete this._metrics.providers_bandwidth.hashMap[hashKey];
}
this._metrics.providers_bandwidth.set(updated_labels, Date.now());
}

update_providers_ops(type, write_num, read_num) {
if (!this.enabled()) return;
const { hashMap } = this._metrics.providers_ops;
const hashKey = Object.keys(hashMap).find(key => key.includes(`type:${type}`));
const record = hashMap[hashKey];
let updated_labels = {
type,
write_num: (write_num || 0),
read_num: (read_num || 0),
};
if (record) {
const { labels } = record;
const updated_labels = {
type,
write_num: (labels.write_num || 0) + (write_num || 0),
read_num: (labels.read_num || 0) + (read_num || 0),
};
this._metrics.providers_ops.reset();
this._metrics.providers_ops.set(updated_labels, Date.now());
updated_labels.write_num += (labels.write_num || 0);
updated_labels.read_num += (labels.read_num || 0);
delete this._metrics.providers_ops.hashMap[hashKey];
}
this._metrics.providers_ops.set(updated_labels, Date.now());
}
}

Expand Down

0 comments on commit b40b322

Please sign in to comment.