diff --git a/hc/front/templatetags/hc_extras.py b/hc/front/templatetags/hc_extras.py index 5f1e31e9..16fc643f 100644 --- a/hc/front/templatetags/hc_extras.py +++ b/hc/front/templatetags/hc_extras.py @@ -40,6 +40,19 @@ def site_root(): return settings.SITE_ROOT +@register.simple_tag +def site_scheme(): + parts = settings.SITE_ROOT.split("://") + assert parts[0] in ("http", "https") + return parts[0] + + +@register.simple_tag +def site_hostname(): + parts = settings.SITE_ROOT.split("://") + return parts[1] + + @register.simple_tag def site_version(): return settings.VERSION diff --git a/hc/front/urls.py b/hc/front/urls.py index 21511b42..ade96a74 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -49,6 +49,7 @@ channel_urls = [ path("add_matrix/", views.add_matrix, name="hc-add-matrix"), path("add_apprise/", views.add_apprise, name="hc-add-apprise"), path("add_msteams/", views.add_msteams, name="hc-add-msteams"), + path("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"), path("/checks/", views.channel_checks, name="hc-channel-checks"), path("/name/", views.update_channel_name, name="hc-channel-name"), path("/test/", views.send_test_notification, name="hc-channel-test"), @@ -70,11 +71,8 @@ urlpatterns = [ path("projects//checks/add/", views.add_check, name="hc-add-check"), path("checks/cron_preview/", views.cron_preview), path("projects//checks/status/", views.status, name="hc-status"), - path( - "projects//checks/metrics/", - views.metrics, - name="hc-metrics", - ), + path("projects//checks/metrics/", views.metrics,), + path("projects//metrics/", views.metrics, name="hc-metrics",), path("checks//", include(check_urls)), path("integrations/", include(channel_urls)), path("docs/", views.serve_doc, name="hc-docs"), diff --git a/hc/front/views.py b/hc/front/views.py index dbfff65e..bb8b5690 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1542,6 +1542,12 @@ def add_msteams(request): return render(request, "integrations/add_msteams.html", ctx) +@login_required +def add_prometheus(request): + ctx = {"page": "channels", "project": request.project} + return render(request, "integrations/add_prometheus.html", ctx) + + def metrics(request, code, key): if len(key) != 32: return HttpResponseBadRequest() diff --git a/static/img/integrations/prometheus.png b/static/img/integrations/prometheus.png new file mode 100644 index 00000000..74984631 Binary files /dev/null and b/static/img/integrations/prometheus.png differ diff --git a/static/img/integrations/setup_prometheus_1.png b/static/img/integrations/setup_prometheus_1.png new file mode 100644 index 00000000..35298154 Binary files /dev/null and b/static/img/integrations/setup_prometheus_1.png differ diff --git a/templates/front/channels.html b/templates/front/channels.html index 04164260..3d38d6ac 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -291,6 +291,16 @@ Add Integration +
  • + Prometheus icon + +

    Prometheus

    +

    Export check and tag status values to Prometheus.

    + + Add Integration +
  • + {% if enable_pushbullet %}
  • +
    +

    Prometheus

    + +

    + {% site_name %} provides a + Prometheus-compatible metrics endpoint + for each project. The endpoints are secured using each project's + read-only API key. + + If your team uses Prometheus, you can configure it to scrape {% site_name %} + and have up-to-date check and tag status values available in Prometheus. +

    + +

    Setup Guide

    + +
    +
    + 1 +

    + Look up your project's read-only API key in + Project Settings › API Access. +

    +

    + If you have not generated API keys before, you will need to do that + first. +

    +
    +
    + Click create integration button +
    +
    + +
    +
    + 2 +

    + Edit Prometheus configuration and add a new section in the + scrape_configs section. +

    +
    +- job_name: 'healthchecks-{{ project|slugify }}'
    +  scheme: {% site_scheme %}
    +  metrics_path: /projects/{{ project.code }}/metrics/YOUR-READ-ONLY-API-KEY
    +  static_configs:
    +  - targets: ['{% site_hostname %}']
    +
    +
    + +
    +
    + 3 +

    + Reload Prometheus' configuration. You should now start seeing + {% site_name %} data appear in Prometheus. +

    +
    +
    + +
    + +{% endblock %}