@tryghost/metrics 0.1.3 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,19 +8,26 @@ class GhostMetrics {
8
8
  /**
9
9
  * Properties in the options bag:
10
10
  *
11
- * domain: Metadata for metrics in shared databases.
12
- * mode: Is used to print short or long log - used for stdout shipper.
13
- * metricTransports: An array of transports for metric shipping (e.g. ['stdout', 'elasticsearch'])
14
- * elasticsearch: Elasticsearch transport configuration
11
+ * domain: Metadata for metrics in shared databases.
12
+ * mode: Is used to print short or long log - used for stdout shipper.
13
+ * metrics.transports: An array of transports for metric shipping (e.g. ['stdout', 'elasticsearch'])
14
+ * metrics.metadata: A property bag of metadata values to be shipped alongside the metric value
15
+ * elasticsearch: Elasticsearch transport configuration
15
16
  * @param {object} options Bag of options
16
17
  */
17
18
  constructor(options) {
18
19
  options = options || {};
19
20
 
20
21
  this.domain = options.domain || 'localhost';
21
- this.transports = options.metricTransports || [];
22
22
  this.elasticsearch = options.elasticsearch || {};
23
23
  this.mode = process.env.MODE || options.mode || 'short';
24
+ if ('metrics' in options && typeof options.metrics === 'object') {
25
+ this.transports = options.metrics.transports || [];
26
+ this.metadata = options.metrics.metadata || {};
27
+ } else {
28
+ this.transports = [];
29
+ this.metadata = {};
30
+ }
24
31
 
25
32
  // CASE: special env variable to enable long mode and level info
26
33
  if (process.env.LOIN) {
@@ -60,6 +67,8 @@ class GhostMetrics {
60
67
 
61
68
  /**
62
69
  * @description Setup ElasticSearch metric shipper
70
+ * ElasticSearch metrics are shipped to an index individually for each metric.
71
+ * The name of the index is the name of the metric prefixed with "metrics-", the metric name itself should be sluggified
63
72
  */
64
73
  setupElasticsearchShipper() {
65
74
  const ElasticSearch = require('@tryghost/elasticsearch');
@@ -77,9 +86,12 @@ class GhostMetrics {
77
86
  value = {value};
78
87
  }
79
88
 
80
- value.domain = this.domain;
89
+ value['@timestamp'] = Date.now();
90
+ if (this.metadata) {
91
+ value.metadata = this.metadata;
92
+ }
81
93
 
82
- elasticSearch.index(value, name);
94
+ elasticSearch.index(value, `metrics-${name}`);
83
95
  };
84
96
  }
85
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/metrics",
3
- "version": "0.1.3",
3
+ "version": "0.2.2",
4
4
  "repository": "https://github.com/TryGhost/framework/tree/main/packages/metrics",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -26,7 +26,9 @@
26
26
  "sinon": "11.1.2"
27
27
  },
28
28
  "dependencies": {
29
- "@tryghost/pretty-stream": "^0.1.1"
29
+ "@tryghost/elasticsearch": "^0.1.2",
30
+ "@tryghost/pretty-stream": "^0.1.1",
31
+ "@tryghost/root-utils": "^0.3.6"
30
32
  },
31
- "gitHead": "90fab655c5bb4f16dd5604fc65be0ae599021e10"
33
+ "gitHead": "4d1564df4c15a78be73c9473c6ac64a9f57c0fe8"
32
34
  }