pangolin_exporter
/
postgres-metrics-get-changes.sh
40 строк · 1.1 Кб
1#!/bin/bash
2# Script to parse a text exposition format file into a unique list of metrics
3# output by the exporter and then build lists of added/removed metrics.
4
5old_src="$1"6if [ ! -d "$old_src" ] ; then7mkdir -p "$old_src"8fi
9
10function generate_add_removed() {11type="$1"12pg_version="$2"13old_version="$3"14new_version="$4"15
16if [ ! -e "$old_version" ] ; then17touch "$old_version"18fi19
20comm -23 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.removed"21comm -13 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.added"22}
23
24for raw_prom in $(echo .*.prom) ; do25# Get the type and version26type=$(echo "$raw_prom" | cut -d'.' -f3)27pg_version=$(echo "$raw_prom" | cut -d'.' -f4- | sed 's/\.prom$//g')28
29unique_file="${raw_prom}.unique"30old_unique_file="$old_src/$unique_file"31
32# Strip, sort and deduplicate the label names33grep -v '#' "$raw_prom" | \34rev | cut -d' ' -f2- | \35rev | cut -d'{' -f1 | \36sort | \37uniq > "$unique_file"38
39generate_add_removed "$type" "$pg_version" "$old_unique_file" "$unique_file"40done
41