Skip to main content

Nornir processor plugin which calculates the duration of each task

Project description

nornir_task_duration

Nornir processor plugin which calculates the duration of each task

This plugin will store the duration of each task as attribute in the Nornir result objects.

Installation

pip install nornir_task_duration

Purpose

The plugin will add new class attributes to the Nornir results:

  • total_duration: this is the total duration to process all hosts, this is added to the AggregatedResult
  • host_duration: this is the totoal duration to process a single host, this is added to the host's MultiResult
  • duration: this is added to the Result of each task

Usage

This example shows the usage of the processor and an example how to print a summary. You may want to use the duration during the task execution or in another print plugin.

from nornir import InitNornir
from nornir.core.task import Result, Task, AggregatedResult, MultiResult
from nornir_task_duration.plugins.processors import TaskDuration

nr = InitNornir(
    inventory={
        "plugin": "YAMLInventory",
        "options": {
            "host_file": "tests/inventory/hosts.yaml",
            "group_file": "tests/inventory/groups.yaml",
            "defaults_file": "tests/inventory/defaults.yaml",
        },
    }
)

nrp = nr.with_processors([TaskDuration()])

results = nrp.run(task=some_task)

def printer(res):
    if type(res) is AggregatedResult:
        print(f"TOTAL DURATION:{res.total_duration}")
        for r in res:
            print(f" * HOST:{r} - DURATION:{res[r].host_duration}")
            printer(res[r])
    if type(res) is MultiResult:
        for r in res:
            printer(r)
    if type(res) is Result:
        print(f"  -- task:{res.name} - duration:{res.duration}")

printer(results)


# TOTAL DURATION:12
#   * HOST:test1 - DURATION:9
#      -- task:ROOT-TASK - duration:9
#      -- task:task1 - duration:4
#      -- task:task2 - duration:3
#      -- task:task2 - duration:3
#   * HOST:test2 - DURATION:12
#      -- task:ROOT-TASK - duration:12
#      -- task:task1 - duration:4
#      -- task:task2 - duration:3
#      -- task:task2 - duration:3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nornir_task_duration-0.0.1a0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

nornir_task_duration-0.0.1a0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page