tensor

tensor.aggregators

tensor.aggregators.Counter(a, b, delta)[source]

Counter derivative

tensor.aggregators.Counter32(a, b, delta)[source]

32bit counter aggregator with wrapping

tensor.aggregators.Counter64(a, b, delta)[source]

64bit counter aggregator with wrapping

tensor.interfaces

tensor.objects

class tensor.objects.Event(state, service, description, metric, ttl, tags=None, hostname=None, aggregation=None, evtime=None, attributes=None, type='riemann')[source]

Bases: object

Tensor Event object

All sources pass these to the queue, which form a proxy object to create protobuf Event objects

Parameters:
  • state – Some sort of string < 255 chars describing the state
  • service – The service name for this event
  • description – A description for the event, ie. “My house is on fire!”
  • metric – int or float metric for this event
  • ttl – TTL (time-to-live) for this event
  • tags – List of tag strings
  • hostname – Hostname for the event (defaults to system fqdn)
  • aggregation – Aggregation function
  • attributes – A dictionary of key/value attributes for this event
  • evtime – Event timestamp override
class tensor.objects.Output(config, tensor)[source]

Bases: object

Output parent class

Outputs can inherit this object which provides a construct for a working output

Parameters:
  • config – Dictionary config for this queue (usually read from the yaml configuration)
  • tensor – A TensorService object for interacting with the queue manager
createClient()[source]

Deferred which sets up the output

eventsReceived()[source]

Receives a list of events and processes them

Arguments: events – list of tensor.objects.Event

stop()[source]

Called when the service shuts down

class tensor.objects.Source(config, queueBack, tensor)[source]

Bases: object

Source parent class

Sources can inherit this object which provides a number of utility methods.

Parameters:
  • config – Dictionary config for this queue (usually read from the yaml configuration)
  • queueBack – A callback method to recieve a list of Event objects
  • tensor – A TensorService object for interacting with the queue manager
createEvent(state, description, metric, prefix=None, hostname=None, aggregation=None, evtime=None)[source]

Creates an Event object from the Source configuration

createLog(type, data, evtime=None, hostname=None)[source]

Creates an Event object from the Source configuration

startTimer()[source]

Starts the timer for this source

stopTimer()[source]

Stops the timer for this source

tick(*args, **kwargs)[source]

Called for every timer tick. Calls self.get which can be a deferred and passes that result back to the queueBack method

Returns a deferred

tensor.service

class tensor.service.TensorService(config)[source]

Bases: twisted.application.service.Service

Tensor service

Runs timers, configures sources and and manages the queue

sendEvent(source, events)[source]

Callback that all event sources call when they have a new event or list of events

setupOutputs(config)[source]

Setup output processors

setupSources(config)[source]

Sets up source objects from the given config

sourceWatchdog()[source]

Watchdog timer function.

Recreates sources which have not generated events in 10*interval if they have watchdog set to true in their configuration

tensor.utils

class tensor.utils.BodyReceiver(finished)[source]

Bases: twisted.internet.protocol.Protocol

Simple buffering consumer for body objects

class tensor.utils.PersistentCache(location='/var/lib/tensor/cache')[source]

Bases: object

A very basic dictionary cache abstraction. Not to be used for large amounts of data or high concurrency

contains(k)[source]

Return True if key k exists

delete(k)[source]

Remove key k from the cache

expire(age)[source]

Expire any items in the cache older than age seconds

get(k)[source]

Returns key contents, and modify time

set(k, v)[source]

Set a key k to value v

class tensor.utils.ProcessProtocol(deferred, timeout)[source]

Bases: twisted.internet.protocol.ProcessProtocol

ProcessProtocol which supports timeouts

class tensor.utils.Resolver[source]

Bases: object

Helper class for DNS resolution

class tensor.utils.StringProducer(body)[source]

Bases: object

String producer for writing to HTTP requests

exception tensor.utils.Timeout[source]

Bases: exceptions.Exception

Raised to notify that an operation exceeded its timeout.

tensor.utils.fork(executable, args=(), env={}, path=None, timeout=3600)[source]

Provides a deferred wrapper function with a timeout function

Parameters:
  • executable (str.) – Executable
  • args (tupple.) – Tupple of arguments
  • env (dict.) – Environment dictionary
  • timeout (int.) – Kill the child process if timeout is exceeded