Skip to main content

OpenCensus Zenoss Exporter for Python

A Python library intended to be used in Python applications instrumented with OpenCensus to export stats to Zenoss.

Status

This library is in an alpha stage, and the API is subject to change.

Installation

The package can be installed with the following command.

pip install opencensus-ext-zenoss

Usage

The following example shows how to configure the exporter.

from opencensus.ext.zenoss import stats_exporter as zenoss
from opencensus.stats import stats as stats_module

stats = stats_module.stats
view_manager = stats.view_manager

exporter = zenoss.new_stats_exporter(
    zenoss.Options(api_key="YOUR-ZENOSS-API-KEY"))

view_manager.register_exporter(exporter)

Options

The following options are available when creating a stats exporter.

  • address: Zenoss API address. Default is https://api.zenoss.io.
  • api_key: Zenoss API key.
  • source: Added as a tag to all sent metrics. Recommended.
  • extra_tags: Map of additional tags to add to all sent metrics. Default is {}.
  • insecure_tls: Set to True to disable server certification verification. Default is False.

Example Application

The following is a complete example of an application that will write to a measure once per second for 100 seconds. A distribution view is created for measure that will be exported to Zenoss once every 10 seconds.

import os
import random
import sys
import time

from opencensus.ext.zenoss import stats_exporter as zenoss
from opencensus.stats import aggregation as aggregation_module
from opencensus.stats import measure as measure_module
from opencensus.stats import stats as stats_module
from opencensus.stats import view as view_module
from opencensus.tags import tag_map as tag_map_module

# Setup aliases to make working with OpenCensus easier.
stats = stats_module.stats
view_manager = stats.view_manager
stats_recorder = stats.stats_recorder

# Create a measure.
m_latency_ms = measure_module.MeasureFloat(
    "task_latency", "The task latency in milliseconds", "ms")

# Create a view using the measure.
latency_view = view_module.View(
    "task_latency_distribution",
    "The distribution of the task latencies",
    [],
    m_latency_ms,
    # Latency in buckets: [>=0ms, >=100ms, >=200ms, >=400ms, >=1s, >=2s, >=4s]
    aggregation_module.DistributionAggregation(
        [100.0, 200.0, 400.0, 1000.0, 2000.0, 4000.0]))


def main():
    address = os.environ.get("ZENOSS_ADDRESS", zenoss.DEFAULT_ADDRESS)
    api_key = os.environ.get("ZENOSS_API_KEY")
    if not api_key:
        sys.exit("ZENOSS_API_KEY must be set")

    # Create Zenoss exporter.
    exporter = zenoss.new_stats_exporter(
        options=zenoss.Options(
            address=address,
            api_key=api_key,
            source="app.example.com"),
        interval=10)

    # Register Zenoss exporter.
    view_manager.register_exporter(exporter)

    # Register our example view.
    view_manager.register_view(latency_view)

    # Prepare measurement map, and tag map we can reuse for each sample.
    measurement_map = stats_recorder.new_measurement_map()
    tag_map = tag_map_module.TagMap()

    # Record one random measurement each second for 100 seconds.
    print("Recording measurements:")
    for i in range(100):
        ms = random.random() * 5 * 1000
        print("  - latency {}:{}".format(i, ms))
        measurement_map.measure_float_put(m_latency_ms, ms)
        measurement_map.record(tag_map)
        time.sleep(1)


if __name__ == "__main__":
    import logging

    # Setup default logging configuration.
    logging.basicConfig()

    # Change level of Zenoss exporter's logging to debug.
    logging.getLogger("opencensus.ext.zenoss").setLevel(logging.DEBUG)

    main()

Useful Links

Metadata

Release files for opencensus-ext-zenoss 0.0.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 opencensus-ext-zenoss 0.0.4
File Size Uploaded Provenance
opencensus-ext-zenoss-0.0.4.tar.gz 6.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for opencensus-ext-zenoss 0.0.4
File Interpreter ABI Platform
opencensus_ext_zenoss-0.0.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 16.2 kB

Release files / opencensus-ext-zenoss-0.0.4.tar.gz

Download URL opencensus-ext-zenoss-0.0.4.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c1c7037eb7c7c185853b6bfe3ff67574974bcc385e6e62388aad24d3a0f4a2f7
BLAKE2b-256 checksum
How to use checksums
76c127a2251d5a31a046289095156cffc38dc990d224b2df345d3d3c878e0c7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / opencensus_ext_zenoss-0.0.4-py2.py3-none-any.whl

Download URL opencensus_ext_zenoss-0.0.4-py2.py3-none-any.whl
Size 10.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
67ce7c53c02efd3394bd5ee9ba519c92f3f8596583f10d3d7d2f516d8629a65a
BLAKE2b-256 checksum
How to use checksums
61aa2463570e8f0670fd21ca02b446f67e838cf7ba412a9d65e9c3f5b654a36d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Security for opencensus-ext-zenoss 0.0.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