Skip to content
Draft
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ Contents
configuring-slack-for-spidermon
configuring-telegram-for-spidermon
actions
mixins
changelog
36 changes: 36 additions & 0 deletions docs/source/mixins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. _mixins:

======
Mixins
======

What is a Mixin?
----------------

A mixin is a class that implements one or more features that you can apply to
any class through multiple inheritance. For more information, see `What is a
mixin, and why are they useful?`_

.. _What is a mixin, and why are they useful?: https://stackoverflow.com/q/533631

Spidermon offers the following built-in mixins:

- `JobMonitorMixin`_
- `SpiderMonitorMixin`_
- `StatsMonitorMixin`_
- `ValidationMonitorMixin`_.

Spidermon built-in mixins
-------------------------

.. automodule:: spidermon.contrib.monitors.mixins.job
:members: JobMonitorMixin

.. automodule:: spidermon.contrib.monitors.mixins.spider
:members: SpiderMonitorMixin

.. automodule:: spidermon.contrib.monitors.mixins.stats
:members: StatsMonitorMixin

.. automodule:: spidermon.contrib.monitors.mixins.validation
:members: ValidationMonitorMixin
71 changes: 71 additions & 0 deletions docs/source/monitors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,77 @@ implement your monitors:

.. autoclass:: spidermon.core.monitors.Monitor

Available monitor mixins
------------------------

.. class:: spidermon.contrib.mixins.StatsMonitorMixin

``stats`` property from attribute from ``data``

.. class:: spidermon.contrib.mixins.JobMonitorMixin

``job`` property from attribute from ``data``

.. class:: spidermon.contrib.mixins.SpiderMonitorMixin

Wraps ``StatsMonitorMixin`` and ``JobMonitorMixin`` and provides more
information about ``responses``.

``responses`` an instance of ``ResponsesInfo``, provides information about
status codes

.. class:: spidermon.contrib.monitors.spider.ResponsesInfo

Utility class used for accessing information about status codes compared
to the total number of responses.

``count`` the total number of responses, equivalent to
``downloader/response_count``` from stats

The following attributes are instances of
``spidermon.contrib.stats.counters.DictPercentCounter``:

``all`` percentages about all status codes

``informational`` percentages about 1xx codes

``succesful`` percentages about 2xx codes

``redirections`` percentages about 3xx codes

``bad_requests`` percentages about 4xx codes

``internal_server_errors`` percentages about 5xx codes

``others`` percentages about other codes

``errors`` percentages about 4xx + 5xx status codes

.. class:: spidermon.contrib.stats.counters.PercentCounter

Utility class for computing percentage from a total value.

``count`` the current value used for computing the percentage

``percent`` percentage of ``count`` from the total value

.. method:: inc_value(value)

increase the ``count`` by a given value

.. class:: spidermon.contrib.stats.counters.DictPercentCounter

Dictionary wrapper initiated with a total and in which values are
``PercentCounter`` instances with that total

``count`` - sum of all values, this represents the total percentage of
requests from given total

.. method:: add_value(value)

create or add to an existing key a value


Monitor Suites
--------------

Expand Down