-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michael Hanselmann <[email protected]>
- Loading branch information
0 parents
commit 3aa70b2
Showing
13 changed files
with
1,646 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Run tests | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
schedule: | ||
- cron: '35 15 * * 1' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Go setup | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1 | ||
|
||
- uses: actions/cache@v2 | ||
with: | ||
# https://github.com/actions/cache/blob/main/examples.md#go---modules | ||
path: | | ||
~/.cache/go-build | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Dependencies | ||
run: go get -v | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... | ||
|
||
# vim: set sw=2 sts=2 et : --> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Release packaging | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v[0-9]+.*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
# Required by GoReleaser | ||
fetch-depth: 0 | ||
|
||
- name: Go setup | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1 | ||
|
||
- name: Set variables | ||
id: vars | ||
env: | ||
EVENT_NAME: ${{ github.event_name }} | ||
REF: ${{ github.ref }} | ||
run: | | ||
if [[ "$EVENT_NAME" = push && "$REF" = refs/tags/v[0-9]*.* ]]; then | ||
args=() | ||
else | ||
args=( --skip-publish ) | ||
fi | ||
echo "::set-output name=goreleaser_args::${args[*]}" | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --rm-dist ${{ steps.vars.outputs.goreleaser_args }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Upload assets | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: prometheus-textformat-merge-${{ hashFiles('dist/**') }} | ||
path: dist/** | ||
if-no-files-found: error | ||
|
||
# vim: set sw=2 sts=2 et : --> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/prometheus-textformat-merge | ||
/dist/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Configuration for GoReleaser | ||
# https://goreleaser.com/ | ||
|
||
project_name: prometheus-textformat-merge | ||
|
||
builds: | ||
- main: . | ||
binary: prometheus-textformat-merge | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- darwin | ||
- linux | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm | ||
- arm64 | ||
ignore: | ||
- goos: linux | ||
goarch: arm64 | ||
- goos: windows | ||
goarch: arm | ||
- goos: windows | ||
goarch: arm64 | ||
flags: | ||
- -trimpath | ||
|
||
nfpms: | ||
- description: Utility to merge Prometheus textformat files | ||
maintainer: M. Hanselmann | ||
bindir: /usr/bin | ||
license: BSD-3-Clause | ||
formats: | ||
- deb | ||
- rpm | ||
contents: | ||
- src: ./README.md | ||
dst: /usr/share/doc/prometheus-textformat-merge/README.md | ||
- src: ./LICENSE | ||
dst: /usr/share/doc/prometheus-textformat-merge/LICENSE | ||
|
||
archives: | ||
- format: tar.gz | ||
wrap_in_directory: true | ||
files: | ||
- LICENSE | ||
- README.md | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
release: | ||
draft: true | ||
prerelease: auto | ||
|
||
snapshot: | ||
name_template: '{{ .Tag }}.snapshot{{ replace (replace .Date ":" "") "-" "" }}.g{{ .ShortCommit }}' | ||
|
||
# vim: set sw=2 sts=2 et : |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2021 Michael Hanselmann. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Utility to merge Prometheus textformat files | ||
|
||
[![Latest release](https://img.shields.io/github/v/release/hansmi/prometheus-textformat-merge)][releases] | ||
[![Release workflow](https://github.com/hansmi/prometheus-textformat-merge/actions/workflows/release.yaml/badge.svg)](https://github.com/hansmi/prometheus-textformat-merge/actions/workflows/release.yaml) | ||
[![CI workflow](https://github.com/hansmi/prometheus-textformat-merge/actions/workflows/ci.yaml/badge.svg)](https://github.com/hansmi/prometheus-textformat-merge/actions/workflows/ci.yaml) | ||
[![Go reference](https://pkg.go.dev/badge/github.com/hansmi/prometheus-textformat-merge.svg)](https://pkg.go.dev/github.com/hansmi/prometheus-textformat-merge) | ||
|
||
Prometheus' [node exporter][node_exporter_doc] has a `textfile` collector | ||
reading [textformat][prom_textformat] files in a predetermined directory. When | ||
multiple files contain the same metrics, albeit with different labels, | ||
collection fails. | ||
|
||
There are also use cases where combining multiple metrics sources is useful, | ||
e.g. after downloading them from a collector using [cURL][curl]. | ||
|
||
## Example usage | ||
|
||
```bash | ||
$ cat >first.prom <<'EOF' | ||
# HELP node_disk_io_time_seconds_total Total seconds spent doing I/Os. | ||
# TYPE node_disk_io_time_seconds_total counter | ||
node_disk_io_time_seconds_total{device="dm-0"} 581.412 | ||
node_disk_io_time_seconds_total{device="dm-1"} 483.348 | ||
EOF | ||
|
||
$ cat >second.prom <<'EOF' | ||
# HELP node_load5 5m load average. | ||
# TYPE node_load5 gauge | ||
node_load5 0.42 | ||
EOF | ||
|
||
$ prometheus-textformat-merge first.prom second.prom | ||
# HELP node_disk_io_time_seconds_total Total seconds spent doing I/Os. | ||
# TYPE node_disk_io_time_seconds_total counter | ||
node_disk_io_time_seconds_total{device="dm-0"} 581.412 | ||
node_disk_io_time_seconds_total{device="dm-1"} 483.348 | ||
# HELP node_load5 5m load average. | ||
# TYPE node_load5 gauge | ||
node_load5 0.42 | ||
``` | ||
|
||
Reading from standard input is also supported with the `-` placeholder: | ||
|
||
```bash | ||
$ prometheus-textformat-merge first.prom - <<'EOF' | ||
# TYPE node_disk_io_time_seconds_total counter | ||
node_disk_io_time_seconds_total{device="dm-4"} 104.156 | ||
node_disk_io_time_seconds_total{device="dm-5"} 0.372 | ||
EOF | ||
# HELP node_disk_io_time_seconds_total Total seconds spent doing I/Os. | ||
# TYPE node_disk_io_time_seconds_total counter | ||
node_disk_io_time_seconds_total{device="dm-0"} 581.412 | ||
node_disk_io_time_seconds_total{device="dm-1"} 483.348 | ||
node_disk_io_time_seconds_total{device="dm-4"} 104.156 | ||
node_disk_io_time_seconds_total{device="dm-5"} 0.372 | ||
``` | ||
|
||
Note how the same metric was combined from multiple sources. See the `--help` | ||
output for available flags. | ||
|
||
## Installation | ||
|
||
Pre-built binaries are provided for all [releases][releases]: | ||
|
||
* Binary archives (`.tar.gz`) | ||
* Debian/Ubuntu (`.deb`) | ||
* RHEL/Fedora (`.rpm`) | ||
|
||
With the source being available it's also possible to produce custom builds | ||
directly using [Go][golang] or [GoReleaser][goreleaser]. | ||
|
||
[node_exporter_doc]: https://prometheus.io/docs/guides/node-exporter/ | ||
[prom_textformat]: https://prometheus.io/docs/instrumenting/exposition_formats/ | ||
[curl]: https://curl.se/ | ||
[releases]: https://github.com/hansmi/prometheus-textformat-merge/releases/latest | ||
[golang]: https://golang.org/ | ||
[goreleaser]: https://goreleaser.com/ | ||
|
||
<!-- vim: set sw=2 sts=2 et : --> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/hansmi/prometheus-textformat-merge | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/go-cmp v0.5.5 | ||
github.com/prometheus/client_model v0.2.0 | ||
github.com/prometheus/common v0.30.0 | ||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c | ||
google.golang.org/protobuf v1.27.1 // indirect | ||
) |
Oops, something went wrong.