Code Monkey home page Code Monkey logo

fhir-server-exporter's Introduction

FHIR Server Exporter

Last Version License Docker Pull CI OpenSSF Scorecard SLSA 3

FHIR server resource count exporter for Prometheus.

Usage

docker run --rm -it \
    -p 9797:9797 \
    -e FhirServerUrl="https://hapi.fhir.org/baseR4" \
    -e FetchIntervalSeconds=60 \
    -e FhirServerName="HAPI FHIR Demo Server" \
    ghcr.io/chgl/fhir-server-exporter:v2.3.7

Open http://localhost:9797/metrics to view the resource counts in Prometheus format:

# HELP fhir_resource_count Number of resources stored within the FHIR server by type.
# TYPE fhir_resource_count gauge
fhir_resource_count{type="Patient", server_name="HAPI FHIR Demo Server"} 124005
fhir_resource_count{type="Condition", server_name="HAPI FHIR Demo Server"} 29282
fhir_resource_count{type="DiagnosticReport", server_name="HAPI FHIR Demo Server"} 36429
...

The container image is pushed to these registries:

  • docker.io/chgl/fhir-server-exporter:v2.3.7
  • ghcr.io/chgl/fhir-server-exporter:v2.3.7

Configuration

Environment Variable Description Default value
FhirServerUrl The base URL of the FHIR server whose metrics should be exported. E.g. http://localhost:8082/fhir ""
FhirServerName A friendly name for the server. Included as a server_name label in the fhir_resource_count metric. ""
FetchIntervalSeconds The number of seconds between consecutive REST requests to the FHIR server to fetch all resource counts. 30
MetricsPort The local port on which the metrics should be exposed at. 9797
FhirServerTimeout The HTTP client timeout for querying the FHIR server in TimeSpan format. "0.00:02:00"
ExcludedResources A comma-separated list of FHIR resource types that should be excluded from counting. E.g. Binary,Subscription ""
IncludedResources A comma-separated list of FHIR resource types that should be included for counting. if unset, defaults to all types. ""
Auth__Basic__Username If the FHIR server requires basic auth, this allows setting the username. ""
Auth__Basic__Password Basic auth password. ""
Auth__BearerToken Static token to set in the Authorization: Bearer … header. ""
Auth__OAuth__TokenUrl OAuth token endpoint URL. ""
Auth__OAuth__ClientId OAuth client ID. ""
Auth__OAuth__ClientSecret OAuth client secret ""
Auth__OAuth__Scope OAuth scope ""

Custom Queries

You can also specify a list of custom queries to run against the FHIR server. Create a file called queries.yaml and place it in the application's main directory:

docker run --rm -it \
   -e FhirServerUrl="https://hapi.fhir.org/baseR4" \
   -e FhirServerName="HAPI FHIR Demo Server" \
   -p 9797:9797 \
   -v $PWD/src/FhirServerExporter/queries.yaml:/opt/fhir-server-exporter/queries.yaml:ro \
   ghcr.io/chgl/fhir-server-exporter:v2.3.7

Here's an example queries.yaml file. It exports three gauge metrics as fhir_male_patient_count, fhir_female_patient_count, and fhir_older_female_patient_count.

queries:
  - name: fhir_male_patient_count
    query: Patient?gender=male
    description: Male patients
  - name: fhir_female_patient_count
    query: Patient?gender=female
  - name: fhir_older_female_patient_count
    query: Patient?gender=female&birthdate=le1900
    description: Female patients born on or before 1900

Note that &_summary=count is automatically appended to the query.

Install on Kubernetes

To deploy the exporter on Kubernetes, a Helm chart is available at https://github.com/chgl/charts/tree/master/charts/fhir-server-exporter.

Authentication

If multiple authentication settings are given, the order of usage is:

  1. Basic Auth
  2. Bearer Token
  3. OAuth

so if you've specified both a basic auth username and password and an oauth token URL, only the basic auth is used.

Development

Using Docker Compose

  1. Start an empty HAPI FHIR server exposed on port 8282 and a pre-configured Prometheus instance on port 9090:

    docker compose -f hack/compose.yaml up
  2. Run the server exporter

    cd src/FhirServerExporter/
    dotnet run
  3. Access the exposed metrics at http://localhost:9797/metrics

On Kubernetes using Skaffold+Kustomize

  1. create a local testing cluster

    kind create cluster
  2. build and deploy container in development mode. This also bootstraps a HAPI FHIR server and loads some sample resources into it.

    skaffold dev --port-forward

Build and run container image locally

docker build -t fhir-server-exporter:local .
docker run -e FhirServerUrl="http://host.docker.internal:8082/fhir" -p 9797:9797 fhir-server-exporter:local

Image signature and provenance verification

Prerequisites:

All released container images are signed using cosign and SLSA Level 3 provenance is available for verification.

IMAGE=ghcr.io/chgl/fhir-server-exporter:v2.3.7
DIGEST=$(crane digest "${IMAGE}")
IMAGE_DIGEST_PINNED="ghcr.io/chgl/fhir-server-exporter@${DIGEST}"
IMAGE_TAG="${IMAGE#*:}"

cosign verify \
   --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \
   --certificate-identity-regexp="^https://github.com/chgl/.github/.github/workflows/standard-build.yaml@[0-9a-f]{40}$" \
   --certificate-github-workflow-repository="chgl/fhir-server-exporter" \
   "${IMAGE_DIGEST_PINNED}"

slsa-verifier verify-image \
    --source-uri github.com/chgl/fhir-server-exporter \
    --source-tag ${IMAGE_TAG} \
    --source-branch master \
    "${IMAGE_DIGEST_PINNED}"

fhir-server-exporter's People

Contributors

chgl avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fhir-server-exporter's Issues

Support scraping multiple FHIR servers

Maybe configurable like this:

servers:
  - name: test-fhir
    url: http://example.com/fhir
    interval: 60s # scrape every 60s
    auth:
      basic:
        username: user
        password: password
  - name: hapi-base
    url: https://hapi.fhir.org/baseR4
    interval: 10min # scrape every 10 minutes

Each server name is added as a label to fhir_resource_count:

fhir_resource_count{server="test-fhir", type="Patient"} 124005
fhir_resource_count{server="hapi-base", type="Patient"} 124006

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://x-access-token:[secure]@github.com/chgl/fhir-server-exporter.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: .renovaterc.json
Error type: The renovate configuration file contains some invalid settings
Message: packageRules: You have included an unsupported manager in a package rule. Your list: docker. Supported managers are: (ansible, ansible-galaxy, argocd, asdf, azure-pipelines, batect, batect-wrapper, bazel, bazelisk, bitbucket-pipelines, buildkite, bundler, cake, cargo, cdnurl, circleci, cloudbuild, cocoapods, composer, conan, deps-edn, docker-compose, dockerfile, droneci, fleet, flux, fvm, git-submodules, github-actions, gitlabci, gitlabci-include, gomod, gradle, gradle-wrapper, helm-requirements, helm-values, helmfile, helmsman, helmv3, hermit, homebrew, html, jenkins, jsonnet-bundler, kotlin-script, kubernetes, kustomize, leiningen, maven, meteor, mint, mix, nix, nodenv, npm, nuget, nvm, pip-compile, pip_requirements, pip_setup, pipenv, poetry, pre-commit, pub, puppet, pyenv, regex, ruby-version, sbt, setup-cfg, swift, tekton, terraform, terraform-version, terragrunt, terragrunt-version, tflint-plugin, travis, velaci, woodpecker).

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
hack/compose.yaml
  • quay.io/prometheus/prometheus v2.53.1@sha256:f20d3127bf2876f4a1df76246fca576b41ddf1125ed1c546fbd8b16ea55117e6
  • docker.io/hapiproject/hapi v7.2.0@sha256:9bcafa8342b572eee248cb7c48c496863d352bbd0347e1d98ea238d09620e89b
  • quay.io/keycloak/keycloak 25.0.2@sha256:b55f55ff60e905db4809ac133c6b963b87963ec1b49aae6d218fdd53646cb09e
dockerfile
Dockerfile
  • mcr.microsoft.com/dotnet/aspnet 8.0.7-noble-chiseled@sha256:1f6d3352e053938ab1496d30a03b0f2fb6d45a7359aa0979ace5eca71cb3fec4
  • mcr.microsoft.com/dotnet/sdk 8.0.303-noble@sha256:e1713bad94cfeca3a44d837286728a5ed40a1f59cb90be2af8b456ca0050f8a1
github-actions
.github/workflows/ci.yaml
  • chgl/.github v1.7.6@f234aae0732b0ed9ed3a4b32158add2558760ea6
  • chgl/.github v1.7.6@f234aae0732b0ed9ed3a4b32158add2558760ea6
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/download-artifact v4.1.8@fa0a91b85d4f404e444e00e005971372dc801d16
  • actions/setup-dotnet v4.0.1@6bd8b7f7774af54e05809fcc5431931b3eb1ddee
  • chgl/.github v1.7.6@f234aae0732b0ed9ed3a4b32158add2558760ea6
  • imjasonh/setup-crane v0.4@31b88efe9de28ae0ffa220711af4b60be9435f6e
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/daily-trivy-scan.yaml
  • aquasecurity/trivy-action 0.24.0@6e7b7d1fd3e4fef0c5fa8cce1229c54b2c9bd0d8
  • github/codeql-action v3.25.15@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a
  • ubuntu 22.04
.github/workflows/scorecards.yaml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • ossf/scorecard-action v2.4.0@62b2cac7ed8198b15735ed49ab1e5cf35480ba46
  • actions/upload-artifact v4.3.5@89ef406dd8d7e03cfd12d9e0a4a378f454709029
  • github/codeql-action v3.25.15@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a
kubernetes
hack/k8s/load-sample-data.yaml
  • docker.io/curlimages/curl 8.9.1@sha256:8addc281f0ea517409209f76832b6ddc2cabc3264feb1ebbec2a2521ffad24e4
  • curlimages/curl 8.9.1@sha256:8addc281f0ea517409209f76832b6ddc2cabc3264feb1ebbec2a2521ffad24e4
hack/k8s/pods.yaml
  • docker.io/hapiproject/hapi v7.2.0@sha256:9bcafa8342b572eee248cb7c48c496863d352bbd0347e1d98ea238d09620e89b
  • docker.io/curlimages/curl 8.9.1@sha256:8addc281f0ea517409209f76832b6ddc2cabc3264feb1ebbec2a2521ffad24e4
hack/k8s/test-job.yaml
  • curlimages/curl 8.9.1@sha256:8addc281f0ea517409209f76832b6ddc2cabc3264feb1ebbec2a2521ffad24e4
nuget
.config/dotnet-tools.json
  • csharpier 0.28.2
  • dotnet-outdated-tool 4.6.4
src/FhirServerExporter.Tests.E2E/FhirServerExporter.Tests.E2E.csproj
  • StyleCop.Analyzers 1.2.0-beta.556
  • Roslynator.Analyzers 4.12.4
  • Meziantou.Analyzer 2.0.163
  • coverlet.collector 6.0.2
  • xunit.runner.visualstudio 2.8.2
  • xunit 2.9.0
  • Testcontainers 3.9.0
  • Microsoft.NET.Test.Sdk 17.10.0
  • FluentAssertions 6.12.0
  • FakeItEasy 8.3.0
  • Hl7.Fhir.R4 5.9.0
src/FhirServerExporter.Tests/FhirServerExporter.Tests.csproj
  • StyleCop.Analyzers 1.2.0-beta.556
  • Roslynator.Analyzers 4.12.4
  • Meziantou.Analyzer 2.0.163
  • coverlet.msbuild 6.0.2
  • coverlet.collector 6.0.2
  • xunit.runner.visualstudio 2.8.2
  • xunit 2.9.0
  • Microsoft.NET.Test.Sdk 17.10.0
  • FluentAssertions 6.12.0
  • FakeItEasy 8.3.0
  • Hl7.Fhir.R4 5.9.0
src/FhirServerExporter/FhirServerExporter.csproj
  • StyleCop.Analyzers 1.2.0-beta.556
  • Roslynator.Analyzers 4.12.4
  • Meziantou.Analyzer 2.0.163
  • Hl7.Fhir.R4 5.9.0
  • prometheus-net 8.2.1
  • NetEscapades.Configuration.Yaml 3.1.0
  • Microsoft.Extensions.Hosting 8.0.0
  • Microsoft.Extensions.Caching.Memory 8.0.0
  • Duende.AccessTokenManagement 2.1.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.