def dispatch_values(values,
                        host,
                        plugin,
                        plugin_instance,
                        metric_type,
                        type_instance=None):
        """
        Dispatch metrics to collectd.

        :param values (tuple or list): The values to dispatch. It will be
                                       coerced into a list.
        :param host: (str): The name of the vhost.
        :param plugin (str): The name of the plugin. Should be
                             queue/exchange.
        :param plugin_instance (str): The queue/exchange name.
        :param metric_type: (str): The name of metric.
        :param type_instance: Optional.

        """
        path = "{0}.{1}.{2}.{3}.{4}".format(host, plugin, plugin_instance,
                                            metric_type, type_instance)

        collectd.debug("Dispatching %s values: %s" % (path, values))

        metric = collectd.Values()

        # kayn: the host has to be hostname and not some general value
        # which messes up the graphite. The value of 'host' varible was
        # added to the following element 'plugin'.
        #metric.host = host

        metric.host = socket.gethostname()

        #metric.plugin = plugin
        metric.plugin = host + '.' + plugin

        if plugin_instance:
            metric.plugin_instance = plugin_instance

        metric.type = metric_type

        if type_instance:
            metric.type_instance = type_instance

        if utils.is_sequence(values):
            metric.values = values
        else:
            metric.values = [values]
        # Tiny hack to fix bug with write_http plugin in Collectd
        # versions < 5.5.
        # See https://github.com/phobos182/collectd-elasticsearch/issues/15
        # for details
        metric.meta = {'0': True}
        metric.dispatch()
    def dispatch_values(values,
                        host,
                        plugin,
                        plugin_instance,
                        metric_type,
                        type_instance=None):
        """
        Dispatch metrics to collectd.

        :param values (tuple or list): The values to dispatch. It will be
                                       coerced into a list.
        :param host: (str): The name of the vhost.
        :param plugin (str): The name of the plugin. Should be
                             queue/exchange.
        :param plugin_instance (str): The queue/exchange name.
        :param metric_type: (str): The name of metric.
        :param type_instance: Optional.

        """
        path = "{0}.{1}.{2}.{3}.{4}".format(host, plugin, plugin_instance,
                                            metric_type, type_instance)

        collectd.debug("Dispatching %s values: %s" % (path, values))

        try:
            metric = collectd.Values()
            metric.host = ""

            metric.plugin = plugin

            if plugin_instance:
                metric.plugin_instance = "{0}_{1}".format(
                    host, plugin_instance)
            else:
                metric.plugin_instance = host

            metric.type = metric_type

            if type_instance:
                metric.type_instance = type_instance

            if utils.is_sequence(values):
                metric.values = values
            else:
                metric.values = [values]
            # Tiny hack to fix bug with write_http plugin in Collectd
            # versions < 5.5.
            # See https://github.com/phobos182/collectd-elasticsearch/issues/15
            # for details
            metric.meta = {'0': True}
            metric.dispatch()
        except Exception as ex:
            collectd.warning("Failed to dispatch %s. Exception %s" %
                             (path, ex))
    def dispatch_values(values, host, plugin, plugin_instance,
                        metric_type, type_instance=None):
        """
        Dispatch metrics to collectd.

        :param values (tuple or list): The values to dispatch. It will be
                                       coerced into a list.
        :param host: (str): The name of the vhost.
        :param plugin (str): The name of the plugin. Should be
                             queue/exchange.
        :param plugin_instance (str): The queue/exchange name.
        :param metric_type: (str): The name of metric.
        :param type_instance: Optional.

        """
        path = "{0}.{1}.{2}.{3}.{4}".format(host, plugin,
                                            plugin_instance,
                                            metric_type, type_instance)

        collectd.debug("Dispatching %s values: %s" % (path, values))

        try:
            metric = collectd.Values()
            metric.host = host

            metric.plugin = plugin

            if plugin_instance:
                metric.plugin_instance = plugin_instance

            metric.type = metric_type

            if type_instance:
                metric.type_instance = type_instance

            if utils.is_sequence(values):
                metric.values = values
            else:
                metric.values = [values]
            # Tiny hack to fix bug with write_http plugin in Collectd
            # versions < 5.5.
            # See https://github.com/phobos182/collectd-elasticsearch/issues/15
            # for details
            metric.meta = {'0': True}
            metric.dispatch()
        except Exception as ex:
            collectd.warning("Failed to dispatch %s. Exception %s" %
                             (path, ex))