From 59758f15761973a9513c7824f0cd53c368c52cb9 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Fri, 3 Apr 2020 21:14:30 +0200 Subject: [PATCH] Rename plugin Prometheus metrics Rename Prometheus metrics exported by plugins to follow the clusterio__ naming scheme. --- CHANGELOG.md | 17 +++++++++++++---- docs/writing-plugins.md | 13 ++++++++----- plugins/statistics_exporter/instance.js | 8 ++++---- plugins/subspace_storage/dole.js | 4 ++-- plugins/subspace_storage/master.js | 24 ++++++++++++------------ 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3e180a7..c5f2946f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -133,11 +133,20 @@ Version 2.0.0 socket_io_transmit_bytes, - Removed clusterio_connected_instaces_gauge and added clusterio_master_connected_clients_count in its place. -- Renamed clusterio_player_count_gauge to clusterio_instance_player_count -- Removed clusterio_UPS_gauge and added clusterio_instance_game_ticks_total in - its place. +- Renamed clusterio_player_count_gauge to + clusterio_statistics_exporter_instance_player_count +- Removed clusterio_UPS_gauge and added + clusterio_statistics_exporter_instance_game_ticks_total in its place. - Renamed clusterio_endpoint_hit_gauge to clusterio_http_enpoint_hits_total -- Renamed clusterio_statistics_gauge to clusterio_instance_force_flows +- Renamed clusterio_statistics_gauge to + clusterio_statistics_exporter_instance_force_flows +- Renamed clusterio_nn_dole_gauge to clusterio_subspace_storage_nn_dole_gauge. +- Renamed clusterio_dole_factor_gauge to + clusterio_subspace_storage_dole_factor_gauge. +- Renamed clusterio_import_gauge to clusterio_subspace_storage_import_total. +- Renamed clusterio_export_gauge to clusterio_subspace_storage_export_total. +- Renamed clusterio_master_inventory_gauge to + clusterio_subspace_storage_master_inventory. - Removed clusterioMod plugin specific config options logItemTransfers, disableFairItemDistribution useNeuralNetDoleDivider, autosaveInterval, and disableImportsOfEverythingExceptElectricity from the master config. diff --git a/docs/writing-plugins.md b/docs/writing-plugins.md index 16d8865d..0a1404fd 100644 --- a/docs/writing-plugins.md +++ b/docs/writing-plugins.md @@ -459,21 +459,24 @@ the metric and updating it somewhere in the plugin code. For example: const { Counter } = require('lib/prometheus'); const fooMetric = new Counter( - 'clusterio_foo_metric', "Measures the level of foo", + 'clusterio_foo_frobber_foo_metric', "Measures the level of foo", ); // Somewhere in the master plugin code fooMetric.inc(); This works for master plugins, and the metric will be automatically -available through the /metric HTTP endpoint. For metrics that are -per-instance you must define an `instance_id` label and set it -accordingly, for example: +available through the /metric HTTP endpoint. It's recommended that +plugin metrics follow `clusterio__` as the +naming scheme. + +For metrics that are per-instance you must define an `instance_id` label and +set it accordingly, for example: const { Counter } = require('lib/prometheus'); const barMetric = new Gauge( - 'clusterio_bar_metric', "Bar instance level", + 'clusterio_foo_frobber_bar_metric', "Bar instance level", { labels: ['instance_id'] } ); diff --git a/plugins/statistics_exporter/instance.js b/plugins/statistics_exporter/instance.js index eee2e0ab..4ca365ad 100644 --- a/plugins/statistics_exporter/instance.js +++ b/plugins/statistics_exporter/instance.js @@ -3,19 +3,19 @@ const { Gauge } = require('lib/prometheus'); const instancePlayerCount = new Gauge( - 'clusterio_instance_player_count', "Amount of players connected to this cluster", + "clusterio_statistics_exporter_instance_player_count", "Amount of players connected to this cluster", { labels: ['instance_id'] } ); const instanceGameTicksTotal = new Gauge( - 'clusterio_instance_game_ticks_total', "Game tick an instance has progressed to", + "clusterio_statistics_exporter_instance_game_ticks_total", "Game tick an instance has progressed to", { labels: ['instance_id'] } ); const instanceForceFlowStatistics = new Gauge( - 'clusterio_instance_force_flow_statistics', "Items/fluids/enemies/buildings produced/built/killed by a force", + "clusterio_statistics_exporter_instance_force_flow_statistics", "Items/fluids/enemies/buildings produced/built/killed by a force", { labels: ['instance_id', 'force', 'statistic', 'direction', 'name'] }, ); const instanceGameFlowStatistics = new Gauge( - 'clusterio_instance_game_flow_statistics', "Pollution produced/consumed in the game", + "clusterio_statistics_exporter_instance_game_flow_statistics", "Pollution produced/consumed in the game", { labels: ['instance_id', 'statistic', 'direction', 'name'] }, ); diff --git a/plugins/subspace_storage/dole.js b/plugins/subspace_storage/dole.js index 7f2f2b0d..5a4d9306 100644 --- a/plugins/subspace_storage/dole.js +++ b/plugins/subspace_storage/dole.js @@ -4,12 +4,12 @@ const prometheus = require("lib/prometheus"); const prometheusNNDoleGauge = new prometheus.Gauge( - "clusterio_nn_dole_gauge", + "clusterio_subspace_storage_nn_dole_gauge", "Current demand being supplied by Neural Network ; 1 means all demand covered, 0.5 means about half of each supply is covered, 0 means no items are given", { labels: ["resource"] } ); const prometheusDoleFactorGauge = new prometheus.Gauge( - "clusterio_dole_factor_gauge", + "clusterio_subspace_storage_dole_factor_gauge", "The current dole division factor for this resource", { labels: ["resource"] } ); diff --git a/plugins/subspace_storage/master.js b/plugins/subspace_storage/master.js index 8fbd78dd..f2ce2d35 100644 --- a/plugins/subspace_storage/master.js +++ b/plugins/subspace_storage/master.js @@ -10,25 +10,25 @@ const routes = require("./routes"); const dole = require("./dole"); -const prometheusExportGauge = new prometheus.Gauge( - "clusterio_export_gauge", +const exportCounter = new prometheus.Counter( + "clusterio_subspace_storage_export_total", "Resources exported by instance", { labels: ["instance_id", "resource"] } ); -const prometheusImportGauge = new prometheus.Gauge( - "clusterio_import_gauge", +const importCounter = new prometheus.Counter( + "clusterio_subspace_storage_import_total", "Resources imported by instance", { labels: ["instance_id", "resource"] } ); +const masterInventoryGauge = new prometheus.Gauge( + "clusterio_subspace_storage_master_inventory", + "Amount of resources stored on master", + { labels: ["resource"] } +); class MasterPlugin extends plugin.BaseMasterPlugin { async init() { - this.prometheusMasterInventoryGauge = new prometheus.Gauge( - "clusterio_master_inventory_gauge", - "Amount of resources stored on master", - { labels: ["resource"] } - ); this.ui = { sidebar: [ @@ -91,7 +91,7 @@ class MasterPlugin extends plugin.BaseMasterPlugin { for (let item of message.data.items) { this.items.addItem(item[0], item[1]); - prometheusExportGauge.labels(String(instanceId), item[0]).inc(item[1]); + exportCounter.labels(String(instanceId), item[0]).inc(item[1]); } this.updateStorage(); @@ -152,7 +152,7 @@ class MasterPlugin extends plugin.BaseMasterPlugin { if (itemsRemoved.length) { for (let item of itemsRemoved) { - prometheusImportGauge.labels(String(instanceId), item[0]).inc(item[1]); + importCounter.labels(String(instanceId), item[0]).inc(item[1]); } this.updateStorage(); @@ -171,7 +171,7 @@ class MasterPlugin extends plugin.BaseMasterPlugin { onMetrics() { if (this.items) { for (let [key, count] of this.items._items) { - this.prometheusMasterInventoryGauge.labels(key).set(Number(count) || 0); + masterInventoryGauge.labels(key).set(Number(count) || 0); } } }