diff --git a/README.md b/README.md index b786abb..f295921 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ So far it works like this: ```bash TERASLICE_URL="https://localhost" \ + TERASLICE_DISPLAY_URL="https://teraslice-xyz.lan" \ DEBUG=True \ NODE_EXTRA_CA_CERTS=/path/to/ca.crt \ node dist/index.js | bunyan @@ -19,6 +20,7 @@ All options are passed as environment variables ```bash TERASLICE_URL="https://localhost" \ + TERASLICE_DISPLAY_URL="https://teraslice-xyz.lan" \ DEBUG=True \ NODE_EXTRA_CA_CERTS=/path/to/ca.crt \ PORT=4242 \ @@ -31,6 +33,7 @@ The `TERASLICE_URL` is the only environment variable that is required. ### Environment variables * `TERASLICE_URL` - URL to the Teraslice Instance to Monitor +* `TERASLICE_DISPLAY_URL` - Optional override of TERASLICE_URL for metric label purposes only * `DEBUG` - Enable debug logging * `NODE_EXTRA_CA_CERTS` - Standard Node variable to specify CA cert for SSL connections diff --git a/package.json b/package.json index 095dfda..cc27678 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "author": "Terascope, LLC ", - "version": "0.1.1", + "version": "0.2.0", "license": "MIT", "dependencies": { "bunyan": "^1.8.14", diff --git a/src/index.ts b/src/index.ts index 32c4f30..9a7003f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,12 +11,14 @@ declare let process : { DEBUG: string, PORT: number, TERASLICE_URL: string + TERASLICE_DISPLAY_URL: string TERASLICE_QUERY_DELAY: number } }; async function main() { let baseUrl: string; + let displayUrl: string; const server = express(); const port = process.env.PORT || 3000; @@ -29,6 +31,13 @@ async function main() { } else { throw new Error('The TERASLICE_URL environment variable must be a valid URL to the root of your teraslice instance.'); } + if (process.env.TERASLICE_DISPLAY_URL) { + // I instantiate a URL, then immediately call toString() just to get the + // URL validation but keep a string type + displayUrl = new URL(process.env.TERASLICE_DISPLAY_URL).toString(); + } else { + displayUrl = baseUrl; + } const terasliceQueryDelay = process.env.TERASLICE_QUERY_DELAY || 30000; // ms const logger = bunyan.createLogger({ name: 'teraslice_exporter', @@ -48,7 +57,7 @@ async function main() { // node v14+ if (process?.env?.DEBUG?.toLowerCase() === 'true') logger.level('debug'); - const terasliceStats = new TerasliceStats(baseUrl); + const terasliceStats = new TerasliceStats(baseUrl, displayUrl); await terasliceStats.update(); updateTerasliceMetrics(terasliceStats); diff --git a/src/metrics.ts b/src/metrics.ts index d391e29..81228de 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -436,7 +436,7 @@ export function updateTerasliceMetrics(terasliceStats: TerasliceStats): void { metricsRegistry.resetMetrics(); const globalLabels = { - url: terasliceStats.baseUrl.toString(), + url: terasliceStats.displayUrl.toString(), name: terasliceStats.info.name, }; // NOTE: This set of labels expands out to including 'name' twice, right now diff --git a/src/teraslice-stats.ts b/src/teraslice-stats.ts index 6daa58a..9b5c0bf 100644 --- a/src/teraslice-stats.ts +++ b/src/teraslice-stats.ts @@ -10,6 +10,8 @@ import { pDelay } from './util'; export default class TerasliceStats implements TerasliceStatsInterface { baseUrl: URL; + displayUrl: string; + controllers: any[]; executions: any[]; @@ -22,8 +24,9 @@ export default class TerasliceStats implements TerasliceStatsInterface { queryDuration: TerasliceQueryDuration; - constructor(baseUrl:string) { + constructor(baseUrl:string, displayUrl:string) { this.baseUrl = new URL(baseUrl); + this.displayUrl = displayUrl; this.controllers = []; this.executions = []; this.jobs = [];