Skip to main content

OpenCensus Zenoss Exporter

Project description

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

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

opencensus-ext-zenoss-0.0.4.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencensus_ext_zenoss-0.0.4-py2.py3-none-any.whl (10.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file opencensus-ext-zenoss-0.0.4.tar.gz.

File metadata

  • Download URL: opencensus-ext-zenoss-0.0.4.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for opencensus-ext-zenoss-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c1c7037eb7c7c185853b6bfe3ff67574974bcc385e6e62388aad24d3a0f4a2f7
MD5 23d5c0e87f67d9b5148c13a6e355452d
BLAKE2b-256 76c127a2251d5a31a046289095156cffc38dc990d224b2df345d3d3c878e0c7e

See more details on using hashes here.

File details

Details for the file opencensus_ext_zenoss-0.0.4-py2.py3-none-any.whl.

File metadata

  • Download URL: opencensus_ext_zenoss-0.0.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for opencensus_ext_zenoss-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 67ce7c53c02efd3394bd5ee9ba519c92f3f8596583f10d3d7d2f516d8629a65a
MD5 0de579ce329326da04328abe59748a08
BLAKE2b-256 61aa2463570e8f0670fd21ca02b446f67e838cf7ba412a9d65e9c3f5b654a36d

See more details on using hashes here.

Supported by

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