예제 #1
0
from statscache_plugins.volume.utils import VolumePluginMixin, plugin_factory

import fedmsg.meta
import sqlalchemy as sa


class PluginMixin(VolumePluginMixin):
    name = "volume, by package"
    summary = "the count of messages, organized by package"
    description = """
    For any given time window, the number of messages that come across
    the bus for each package.
    """
    _keys = ['package', 'timestamp']

    def process(self, message):
        timestamp = self.schedule.next(
            now=datetime.datetime.fromtimestamp(message['timestamp']))
        packages = fedmsg.meta.msg2packages(message, **self.config)
        for package in packages:
            self._volumes[(package, timestamp)] += 1


plugins = plugin_factory(
    [datetime.timedelta(seconds=s) for s in [1, 5, 60]], PluginMixin,
    "VolumeByPackage", "data_volume_by_package_", {
        'volume': sa.Column(sa.Integer, nullable=False),
        'package': sa.Column(sa.UnicodeText, nullable=False, index=True),
    })
예제 #2
0
from statscache_plugins.volume.utils import VolumePluginMixin, plugin_factory

import sqlalchemy as sa


class PluginMixin(VolumePluginMixin):
    name = "volume"
    summary = "the number of messages coming across the bus"
    description = """
    This is perhaps the most simple metric catalogued by statscache.
    For any given time window, the number of messages are simply counted.
    It can give you a baseline quantity against which you could normalize
    other statistics.
    """
    _keys = ['timestamp']

    def process(self, message):
        timestamp = datetime.datetime.fromtimestamp(message['timestamp'])
        self._volumes[(timestamp,)] += 1


plugins = plugin_factory(
    [datetime.timedelta(seconds=s) for s in [1, 5, 60]],
    PluginMixin,
    "Volume",
    "data_volume_",
    {
        'volume': sa.Column(sa.Integer, nullable=False),
    }
)
import sqlalchemy as sa


class PluginMixin(VolumePluginMixin):
    name = "volume, by category"
    summary = "the count of messages, organized by category"
    description = """
    For any given time window, the number of messages that come across
    the bus for each category.
    """
    _keys = ['category', 'timestamp']

    def process(self, message):
        timestamp = self.schedule.next(
            now=datetime.datetime.fromtimestamp(message['timestamp'])
        )
        category = message['topic'].split('.')[3]
        self._volumes[(category, timestamp)] += 1


plugins = plugin_factory(
    [datetime.timedelta(seconds=s) for s in [1, 5, 60]],
    PluginMixin,
    "VolumeByCategory",
    "data_volume_by_category_",
    {
        'volume': sa.Column(sa.Integer, nullable=False),
        'category': sa.Column(sa.UnicodeText, nullable=False, index=True),
    }
)