Skip to main content

Use Slack as a bus for GraphiteDB / Carbon

Project description

This library’s main purpose is to relay metrics from a Slack channel to a Carbon daemon, for inclusion in a Graphite database. It also contains commands (and classes) used to send and receive metric messages to Carbon.

Configuration

You can configure this library in two ways:

/etc/carbon-slack.yml Configuration

This is what the “native” YAML configuration file looks like:

token: xoxp-1234567890-yadda-yadda # Application token from Slack
carbon-server: 127.0.0.1
carbon-port: 2023
channel: metrics

NOTE: You can get a sample of this from the command line using:

$ carbon-slack-init

Any command provided in this library will expect to load the above configuration, by default using the /etc/carbon-slack.yml file (but you can also provide the configuration path using the --config | -c option).

Embedded in Your Configuration

If you’re using Carbon-Slack as a library, you can also load the necessary configuration elements from any dict using:

import carbon_slack.config as conf
config = conf.Config({
        conf.TOKEN: 'here is my Slack API token',
        conf.CHANNEL: 'metrics',
        conf.CARBON_SERVER: '127.0.0.1',
        conf.CARBON_PORT: 2023
})

This is the same as:

import carbon_slack.config as conf
config = conf.Config({
        'token': 'here is my Slack API token',
        'channel': 'metrics',
        'carbon-server': 127.0.0.1,
        'carbon-port': 2023
})

As you can see, you could initialize this directly from strings in a script, or by reading command line arguments, or from almost anywhere. You could even read in another YAML file that looked something like this:

my-app-id: 10
my-username: buildchimp
relay:
        token: 'here is my Slack API token'
        channel: metrics
        carbon-server: 127.0.0.1
        carbon-port: 2023

Then, use something like the following to initialize your relay:

import carbon_slack.config as conf
from carbon_slack.relay import Relay
import yaml

with open('/path/to/app.yml') as f:
        data = yaml.safe_load(f)

relay = Relay(conf.Config(data['relay']))

Sending Manually

Carbon-Slack provides a command-line client for sending metrics, which can be used like this:

$ carbon-slack-send test.metric 1234

The command-line version of the sender relies on the standard configuration file (see above), and will use the current time when sending the metric. It can only send one metric at a time currently.

Carbon-Slack also provides a library-based approach, for sending metrics programmatically:

from carbon_slack.slack import Sender

sender = Sender(config)
sender.send_metrics({'test.metric', 1234})

Relaying to Carbon

Relaying is what Carbon-Slack is designed to do. It uses Slack as a more-or-less public message bus for sending metrics, which means neither the Graphite DB server nor any of the clients need to be exposed to the internet directly by opening holes in your firewalls. Both the client and the relay initiate connections to Slack and interact on a channel using plaintext.

Metric messages in a Slack channel each contain one or more lines of the format:

metric.name value timestamp-in-seconds

This means you can send a group of metrics in a single message to save on protocol overhead. When the Relay client sees messages in this format, it parses them and sends them on to the Carbon daemon associated with your Graphite DB instance, then deletes the messages from the Slack channel.

Why delete the messages? It helps prevent duplicate processing.

Here’s an example of the Relay in action:

from carbon_slack.relay import Relay

relay = Relay(config)

while True:
    print "Relayed %d metrics" % relay.run()

Of course, the relay is designed to work from the command line as well:

$ carbon-slack-relay

However, command-line usage will require you to use the normal configuration file format (either in the default location, or via the --config | -c command-line option).

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

carbon-slack-0.0.5.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

carbon_slack-0.0.5-py2-none-any.whl (10.8 kB view details)

Uploaded Python 2

File details

Details for the file carbon-slack-0.0.5.tar.gz.

File metadata

  • Download URL: carbon-slack-0.0.5.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for carbon-slack-0.0.5.tar.gz
Algorithm Hash digest
SHA256 ca8cbcc273805aba953cdddff358d13e450ed6c64dd54f3af54b2a5a99d3bb59
MD5 60f924afc56ef7e45d7673047afe46a0
BLAKE2b-256 ad548dcb8126ab74193ea2ee051d46dc2bde21b8b0ccd1f69d3ba0e352328ec9

See more details on using hashes here.

File details

Details for the file carbon_slack-0.0.5-py2-none-any.whl.

File metadata

  • Download URL: carbon_slack-0.0.5-py2-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for carbon_slack-0.0.5-py2-none-any.whl
Algorithm Hash digest
SHA256 000398a4fa2fd6f1119383fcf9d6e6c522024fa1247e808abf49dc4b3460a0fb
MD5 ca296a57add0fb42a07a965815efdc6d
BLAKE2b-256 5c895fe05967a9bc70ea067159d7afc331c57ab85d488160002b7b3edb897b98

See more details on using hashes here.

Supported by

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