Skip to main content

scrapy_prometheus

https://img.shields.io/pypi/status/scrapy_prometheus.svg https://travis-ci.org/sashgorokhov/scrapy_prometheus.svg?branch=master https://img.shields.io/github/license/sashgorokhov/scrapy_prometheus.svg https://img.shields.io/pypi/pyversions/scrapy_prometheus.svg https://badge.fury.io/py/scrapy_prometheus.svg

Scrapy stats collector that exports scrapy stats as prometheus metrics through pushgateway service.

Installation

Via pip:

pip install scrapy_prometheus

Usage

To start using, add scrapy_prometheus.PrometheusStatsCollector to STATS_CLASS setting:

STATS_CLASS = 'scrapy_prometheus.PrometheusStatsCollector'

This stats collector works exactly like the vanilla one (because it subclasses it), but also creates prometheus metrics and pushes them to pushgateway service on spider close signal.

It supports two metric types: Counter and Gauge. Stat metric type is determined by operation used on the stat: stats.inc_value will create a Counter metric, while other methods, stats.set_value, stats.max_value, stats.min_value, will create Gauge.

All metrics will have a spider label attached with spider name.

Stat value must be either int or float.

Note, that trying to perform action on a metric, that is not supposed to be used with this action (set_value on Counter or inc_value on Gauge) will produce scrapy_prometheus.InvalidMetricType error. To suppress it, set PROMETHEUS_SUPPRESS_TYPE_CHECK to True.

If you want to create custom metrics, you can access your spider’s CollectorRegistry by using stats.get_registry(spider).

Available settings

# Prometheus pushgateway host
PROMETHEUS_PUSHGATEWAY = 'localhost:9091'  # default

# Metric name prefix
PROMETHEUS_METRIC_PREFIX = 'scrapy_prometheus'  # default

# Timeout for pushing metrics to pushgateway
PROMETHEUS_PUSH_TIMEOUT = 5  # default

# Method to use when pushing metrics
# Read https://github.com/prometheus/pushgateway#put-method
PROMETHEUS_PUSH_METHOD = 'POST'  # default

# Do not raise scrapy_prometheus.InvalidMetricType when stat is accessed as different type metric.
# For example, doing stats.inc_value('foo', 1) and then stats.set_value('foo', 2) will raise an error,
# Because metric of type Counter was already created for stat foo.
PROMETHEUS_SUPPRESS_TYPE_CHECK = False

# job label value, applied to all metrics.
PROMETHEUS_JOB = 'scrapy'  # default

# grouping label dict, applied to all metrics.
# by default it is an instance key with hostname value.
PROMETHEUS_GROUPING_KEY = {'instance': <hostname>}

How metrics are created

Metric name is build from PROMETHEUS_METRIC_PREFIX and stat name, where all / are replaced with _.

For example:

  • stat foo: 67 whill produce metric scrapy_prometheus_foo{instance="...",job="scrapy",spider="..."} 67

  • stat foo/bar: 67 whill produce metric scrapy_prometheus_foo_bar{instance="...",job="scrapy",spider="..."} 67

  • stat foo/bar/baz: 67 whill produce metric scrapy_prometheus_foo_bar_baz{instance="...",job="scrapy",spider="..."} 67

Metadata

Release files for scrapy-prometheus 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrapy-prometheus 0.4.4
File Size Uploaded Provenance Actions
scrapy_prometheus-0.4.4.tar.gz 4.0 kB Without provenance Details for scrapy_prometheus-0.4.4.tar.gz

Release files / scrapy_prometheus-0.4.4.tar.gz

Download URL scrapy_prometheus-0.4.4.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0c501c33ccfa4483533f18e101b3892ecdb1a2fd851d1af8a6e8e8503d9ba20f
BLAKE2b-256 checksum
How to use checksums
ab32f5effba16931631289b76bbcaaaea29a5ac07ced80409cb95e45139d585a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for scrapy-prometheus 0.4.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page