From 73bed33dd9067dc267ca5149d4bc06b3856ab129 Mon Sep 17 00:00:00 2001 From: Aurelien Le Grand Date: Tue, 10 Oct 2023 08:59:50 +0200 Subject: [PATCH] feat: add uptime ratios --- .github/workflows/dockerimage.yml | 34 +++++++++++++++++++++++++++++++ files/exporter.py | 12 +++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .github/workflows/dockerimage.yml diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml new file mode 100644 index 0000000..8350a3f --- /dev/null +++ b/.github/workflows/dockerimage.yml @@ -0,0 +1,34 @@ +name: Docker Image CI + +on: + push: + branches: [ "add_uptime_ratio" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: What + run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: sir-bruno-hyppo + password: ${{ secrets.GH_TOKEN_BOT }} + - name: Build and push image + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ghcr.io/startupflow/uptimerobot_exporter:${{ env.BRANCH }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/files/exporter.py b/files/exporter.py index 34acc0c..099bd33 100755 --- a/files/exporter.py +++ b/files/exporter.py @@ -19,6 +19,7 @@ def _fetch_paginated(offset, api_key): 'format': 'json', 'response_times': 1, 'response_times_limit': 1, + 'custom_uptime_ratios': '1-7-30-90', 'offset': offset, } return requests.post( @@ -70,6 +71,17 @@ def format_prometheus(data): item.get('url'), item.get('response_times').pop().get('value'), ) + if item.get('custom_uptime_ratio'): + uptime_ratios = item.get('custom_uptime_ratio').split('-') + result += 'uptimerobot_uptime_ratio{{name="{}",type="{}",url="{}",uptime_7="{}",uptime_24="{}",uptime_30="{}",uptime_90="{}"}} 0\n'.format( + item.get('friendly_name'), + item.get('type'), + item.get('url'), + uptime_ratios[0], + uptime_ratios[1], + uptime_ratios[2], + uptime_ratios[3], + ) return result