Metadata-Version: 2.5
Name: trytond_strings_xo_monitoring
Version: 8.0.0.3
Summary: Xen Orchestra Statistics
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <clemens.hupka@backend.at>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
Keywords: monitoring,orchestra,statistics,tryton,virtualization,xcp-ng,xen
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Requires-Dist: trytond-company<8.1,>=8.0
Requires-Dist: trytond-strings-xo-backup<8.1,>=8.0
Requires-Dist: trytond-strings-xo-compute<8.1,>=8.0
Requires-Dist: trytond-strings-xo-infrastructure<8.1,>=8.0
Requires-Dist: trytond-strings-xo-snapshot<8.1,>=8.0
Requires-Dist: trytond-strings-xo<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Requires-Dist: trytond-chorus-notifications<8.1,>=8.0; extra == 'test'
Requires-Dist: trytond-statuspage-monitoring<8.1,>=8.0; extra == 'test'
Description-Content-Type: text/x-rst

Xen Orchestra Statistics
========================

The ``strings_xo_monitoring`` module collects the performance data Xen
Orchestra samples for the hosts, the virtual machines and the storage
repositories the suite mirrors, keeps the samples in a Tryton-side
history pruned by granularity, and reports the history through
aggregation helpers and graph views.

Collection
----------

The statistics of an entity are read from the RRD endpoints of the Xen
Orchestra REST API v0, one request per granularity, and a server whose
REST API does not carry the route of a kind - the statistics of a
storage repository on a Xen Orchestra version predating them, in
particular - is asked through the historical JSON-RPC method of the
kind, which answers the very same payload.

Xen Orchestra reports the metrics of the hypervisor, which differ for a
host, a virtual machine and a storage repository, and carries a series
per processor, interface or virtual disk.  The metric tree is folded
into the flat set of measures a sample stores - the processor usage of
the entity and of its busiest processor, its memory and its free
memory, the load average of a host, the time it waited for its storage,
the traffic of its interfaces, the operations, the throughput and the
latency of its storage - so that one row describes the entity as a
whole: a counter is summed, a rate and a percentage are averaged, and a
value the hypervisor could not report stays a gap rather than becoming
a zero.

Storage
-------

A sample is written once whatever the number of runs that read it.  Its
uniqueness - the server, the kind, the entity, the granularity and the
timestamp - is enforced by the database, and the samples of a run are
compared to the ones already stored in a single range query before
anything is written, so that collecting an entity twice - a manual
collection after a scheduled one, or a run overlapping the window of the
previous one - never duplicates its history.  The samples of a run are
written by batches, so that the size of a statement stays bounded
whatever the length of a series.

An entity the mirror of the suite does not hold is still collected: its
samples are stored detached, so that the history of an entity which was
deleted from the inventory is not lost, and the entity is attached again
when the mirror reports it once more.

Run
---

A run reads every requested entity of every requested kind at every
requested granularity.  It never lets a single entity abort it: an
entity Xen Orchestra refuses - an entity that is unknown, a virtual
machine that does not run, a granularity the hypervisor does not keep -
is recorded as an error and the remaining entities are still collected,
so that the statistics of a whole server are never lost to one of its
entities.

The outcome of a run is reported as a single structured log record,
holding the server, the duration, the counters of every kind at every
granularity and the errors it recorded.

Retention
---------

The history is pruned by granularity beyond a retention read from the
configuration, oldest first and by batches.  A retention of zero days
keeps the samples of the granularity forever, so that only an explicit
deletion removes them.  The pruning is confirmed by the user when it is
triggered from a server, because the samples it removes are gone for
good: they are only collected again for the periods the hypervisor
still holds.

Reporting
---------

The samples are read through the ORM.  ``XOStat.aggregate`` groups a
period into buckets - a minute, an hour or a day, laid out from a fixed
epoch so that two aggregations of the same period group the samples the
same way - and reduces the measures of every bucket with an aggregation
function, an average by default.  ``XOStat.latest`` returns the most
recent sample of every entity matching a domain, which is what a report
reads to tell what an entity consumes now rather than what it consumed
over a period.  The window of the statistics draws the samples of an
entity as a series with the graph views of the model.

Alerting
--------

The module watches the infrastructure the suite mirrors through the
alert rules an operator authors.  A rule watches one kind of condition
of an entity - a host that is down, a storage repository the use of
which crosses a threshold or the free capacity of which runs short, a
backup that failed within a look-back window, or a virtual machine whose
newest snapshot is older than a number of days - and every evaluation
turns the conditions it finds into the open alerts of the rule, so that
a condition is raised once whatever the number of evaluations that
found it.

An evaluation never raises a condition twice: a finding already open is
refreshed rather than duplicated, and it is resolved once it stops being
found, so that the alerts of a rule are the conditions that are true now
rather than the history of everything that was ever true.  The identity
of a condition is the reference of the record it watches, so a rule
recognises a condition from one evaluation to the next.  An alert that
stays open beyond the escalation delay of its rule is escalated once, to
the critical severity, and its delivery is repeated on the cooldown of
the rule; an operator acknowledges an alert to record that it has been
seen, which leaves it open until the evaluation no longer finds its
condition.

The delivery goes through the modules of the suite rather than through
channels of its own.  A rule names a Chorus channel and a status page
service, and the modules publishing them deliver the alert: the chat
post is created in the channel, so that the notifications of
``chorus_notifications`` reach its members, and the status page service
is moved to the severity of the alert while an incident is opened for
it, and moved back to ``ok`` when the alert is resolved.  Both are
optional dependencies: an alert delivered to no channel is still an
alert an operator reads in Tryton.

Task monitoring
---------------

The asynchronous work of the suite - the backup runs, the imports, the
migrations, every action Xen Orchestra answers with a task identifier -
is mirrored in ``xo.task``, and the module reads that mirror for the
operators.  The console offers the tasks through a window an operator
reads by the state, the action, the target, the server and the date they
were enqueued on, and gathers the questions of a run of failures into a
dashboard: what failed, whose poll keeps failing, and how the states are
distributed over the servers.

A failure is surfaced where it is read: the window carries the record the
task acted upon, the *Show Error* button raises the error Xen Orchestra
reported, and the poll counters tell a task whose poll keeps failing from
one that failed once.  The console does not retry a task: the body a
retry would need is not part of the mirror, and the retry of an operation
belongs to the record that started it.

The figures of a run of failures are one line per server, action and
state, read through a query over the mirror rather than a counter kept
beside it, and scoped to the companies of the user like every other
record of the module.  An action that fails more than it succeeds, or a
server whose tasks pile up in a state, stands out as a line of its own,
and a combination no task falls into has no line rather than a zero.

Scheduling
----------

Three scheduled actions drive the module in the background: the
collection ticks at a base granularity and skips a server collected
less than its own interval ago, so that the effective interval is
controlled entirely through the configuration file; the pruning ticks
once a day; and the alert rules are evaluated on the base granularity of
the collection, because an alert is resolved by the evaluation that no
longer finds its condition.  All three can be disabled from the
configuration file, and all three are offered as scheduled methods under
*Administration > Scheduled Actions*.

The manual counterpart of the scheduled collection is the *Collect
Statistics* wizard, offered from the *Monitoring* menu and from the
button of a host, of a virtual machine and of a server.  The wizard
defaults to the entities it was opened from and to the granularities of
the scheduled collection, and reports the summary of the run: what was
read, what was stored, what was already stored and what Xen Orchestra
refused.

Features
--------

- **Hosts, virtual machines and storage repositories**: the statistics of
  every kind of entity the suite mirrors are collected, and the metric
  tree of each kind is folded into the measures a sample stores.
- **Four granularities**: the samples are read at the granularity the
  hypervisor keeps - five seconds for the last ten minutes, one minute
  for the last two hours, one hour for the last week and one day for the
  last year - so that a period is reported at the resolution it deserves.
- **Idempotent storage**: a sample is written once, and the samples of a
  run are compared to the ones already stored before anything is
  written; the uniqueness of a sample is enforced by the database.
- **Batched writes and deletions**: the size of a statement stays bounded
  whatever the length of a series and whatever the depth of the history.
- **Gaps preserved**: a value the hypervisor did not report is stored
  empty, so that a gap in a series is never read as a zero.
- **Failure isolation**: an entity Xen Orchestra refuses is recorded as
  an error and does not keep the remaining entities from being
  collected.
- **Reporting**: bucketed aggregation over a selection with an
  average, a maximum, a minimum or a sum, the most recent sample of every
  entity, and graph views drawing the series of an entity.
- **Retention by granularity**: the history is pruned beyond a retention
  read from the configuration, a retention of zero days keeping the
  samples forever.
- **Confirmation**: a deletion triggered from a server is confirmed
  before it removes anything.
- **Scheduling**: a scheduled collection, a scheduled pruning and a
  scheduled evaluation of the alert rules, all disabled from the
  configuration file and all exposed as scheduled methods.
- **Alert rules**: a host that is down, a storage repository the use of
  which crosses a threshold or the free capacity of which runs short, a
  backup that failed within a look-back window, or a snapshot older than
  it should be.
- **Deduplicated alerts**: a condition is raised once whatever the
  number of evaluations that found it, refreshed while it stays true and
  resolved once it is gone, so that the alerts of a rule are the
  conditions that are true now.
- **Escalation and cooldown**: an alert that stays open beyond the
  escalation delay of its rule is escalated once to the critical
  severity, and its delivery is repeated on the cooldown of the rule.
- **Delivery through the suite**: the alerts are posted to a Chorus
  channel and reported on a status page service, so that the
  notifications of ``chorus_notifications`` and the incidents of
  ``statuspage_monitoring`` carry them; both are optional.
- **Task monitoring**: the asynchronous tasks of the suite are read
  through a window filtered by state, action, target, server and date,
  and gathered into a dashboard of the failures, the poll problems and
  the state distribution.
- **Task figures**: one line per server, action and state counts the
  tasks of a run of failures and reports the moment of the newest of
  them, read as a query over the mirror rather than as a counter kept
  beside it.
- **Structured logging**: one summary record per run, holding the
  counters and the errors of every kind at every granularity.
- **Security**: dedicated access rights - the history is written by the
  collection and the pruning and read by every Xen Orchestra user, and
  the alerts are read and acknowledged by every Xen Orchestra user while
  the rules are authored by the administration groups - and permissions
  on the buttons restricting the collection and the pruning to the
  administration groups.

Configuration
-------------

After installing the module, the history is browsable under *Xen
Orchestra > Monitoring > Statistics*, and the *Collect Statistics*
wizard is offered beside it and from the button of a host, of a virtual
machine and of a server.  The alerts are browsable under *Xen Orchestra
> Monitoring > Alerts*, and the rules are authored under *Xen Orchestra
> Monitoring > Alert Rules*.  The asynchronous tasks are browsable under
*Xen Orchestra > Monitoring > Tasks*, and their dashboard - the failed
tasks, the tasks whose poll keeps failing and the figures over the
states - is offered beside the statistics as *Xen Orchestra > Monitoring
> Task Dashboard*.

The module reads the ``[strings_xo_monitoring]`` section of the trytond
configuration file:

.. code-block:: ini

    [strings_xo_monitoring]
    ingest_cron = True
    ingest_interval_minutes = 5
    ingest_granularities = minutes,hours
    batch_max = 5000
    prune_cron = True
    alert_cron = True
    retention_seconds = 1
    retention_minutes = 3
    retention_hours = 30
    retention_days = 400

``ingest_cron``
    whether the scheduled collection of the statistics is enabled;
    defaults to ``True``.
``ingest_interval_minutes``
    the minimum number of minutes between two collections of the same
    server; defaults to ``5``.  The value is clamped to at least one
    minute.
``ingest_granularities``
    the granularities collected by the scheduled run, as a comma
    separated list of ``seconds``, ``minutes``, ``hours`` and ``days``;
    defaults to ``minutes,hours``.  The ``seconds`` granularity samples
    every five seconds and is only kept by the hypervisor for about ten
    minutes, so it is left out of the default and has to be asked for
    explicitly.
``batch_max``
    the number of samples written and removed per statement; defaults to
    ``5000``.  The value is clamped to at least one sample.
``prune_cron``
    whether the scheduled pruning of the statistics is enabled;
    defaults to ``True``.
``alert_cron``
    whether the scheduled evaluation of the alert rules is enabled;
    defaults to ``True``.  Disabling it stops the alerts from being
    raised and from being resolved, so that they stay where the last
    evaluation left them.
``retention_<granularity>``
    the number of days the samples of a granularity are kept, a
    fractional value being accepted; a value of ``0`` keeps the samples
    of the granularity forever.

The scheduled collection ticks at a base granularity of five minutes
and skips a server collected less than ``ingest_interval_minutes`` ago,
so the effective interval is controlled entirely through the
configuration file.  The three scheduled actions can also be suspended
by deactivating their record under *Administration > Scheduled
Actions*.
