Created
May 11, 2023 13:24
-
-
Save wperron/d04a751f3581692ee3021cd2d7489491 to your computer and use it in GitHub Desktop.
Compare two different sets of prometheus metrics based on the output of the `/metrics` endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env deno run -A | |
import { readStringDelim } from "https://deno.land/[email protected]/io/read_string_delim.ts"; | |
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | |
async function extractMetricNames(f) { | |
const filename = path.join(Deno.cwd(), f); | |
let fileReader = await Deno.open(filename); | |
let metrics = new Set(); | |
for await (let line of readStringDelim(fileReader, "\n")) { | |
if (!line.startsWith("#") && line.length !== 0) { | |
let end = line.indexOf("{"); | |
if (end === -1) { | |
end = line.indexOf(" "); | |
} | |
if (end === -1) { | |
end = line.indexOf("\n"); | |
} | |
const metricName = line.slice(0, end); | |
metrics.add(metricName); | |
} | |
} | |
metrics = [...metrics]; | |
metrics.sort(); | |
return metrics; | |
} | |
let [left, right] = await Promise.all([ | |
extractMetricNames(Deno.args[0]), | |
extractMetricNames(Deno.args[1]), | |
]); | |
for (const l of left) { | |
if (!right.includes(l)) { | |
console.log(`%c-${l}`, "color: red"); | |
} | |
} | |
for (const r of right) { | |
if (!left.includes(r)) { | |
console.log(`%c+${r}`, "color: green"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment