Skip to content

Commit

Permalink
feat: add uptime ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
a-legrand committed Oct 10, 2023
1 parent b70b129 commit 73bed33
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions files/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 73bed33

Please sign in to comment.