An exporter for converting BigQuery results into Prometheus metrics.
100K+
An exporter for converting BigQuery results into Prometheus metrics.
Prometheus collects the current status of a system as reported by an exporter. Prometheus then associates the values collected with a timestamp of the time of collection.
NOTE: there is no way to associate historical values with timestamps in the the past with this exporter!
So, the results of queries run by prometheus-bigquery-exporter should represent a meaningful value at a fixed point in time relative to the time the query is made, e.g. total number of tests in a 5 minute window 1 hour ago.
The prometheus-bigquery-exporter accepts arbitrary BQ queries. However, the query results must be structured in a predictable way for the exporter to successfully interpret and convert it into prometheus metrics.
Metric names are derived from the query file name and query value columns.
The bigquery-exporter identifies value columns by looking for column names
that match the pattern: value([.+]). All characters in the matching group
([.+]) are appended to the metric prefix taken from the query file name.
For example:
bq_ndt_test.sqlbq_ndt_testvalue_countbq_ndt_test_countValue columns are required (at least one):
value([.+]) - every query must define a result "value". Values must
be integers or floats. For a query to return multiple values, prefix each
with "value" and define unique suffixes.Label columns are optional:
Labels must be strings:
Duplicate metrics are an error:
The following query creates a label and groups by each label.
-- Example data in place of an actual table of values.
WITH example_data as (
SELECT "a" as label, 5 as widgets
UNION ALL
SELECT "b" as label, 2 as widgets
UNION ALL
SELECT "b" as label, 3 as widgets
)
SELECT
label, SUM(widgets) as value
FROM
example_data
GROUP BY
label
Save the sample query to a file named "bq_example.sql".
Start the exporter:
prometheus-bigquery-exporter -gauge-query bq_example.sql
Visit http://localhost:9348/metrics and you will find metrics like:
bq_example{label="a"} 5
bq_example{label="b"} 5
...
Typical deployments will be in Kubernetes environment, like GKE.
# Change to the example directory.
cd example
# Deploy the example query as a configmap and example k8s deployment.
./deploy.sh
To run the bigquery exporter locally (e.g. with a new query) you can build and run locally.
Use the following steps:
docker build -t bqx-local -f Dockerfile .
gcloud auth login
gcloud auth application-default login
docker run -p 9348:9348 --rm \
-v $HOME/.config/gcloud:/root/.config/gcloud \
-v $PWD:/queries -it bqx-local \
-project=$GCLOUD_PROJECT \
-gauge-query=/queries/example/config/bq_example.sql
Content type
Image
Digest
sha256:66e0d4784…
Size
16.7 MB
Last updated
almost 3 years ago
docker pull measurementlab/prometheus-bigquery-exporter