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.8.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 2

File details

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

File metadata

  • Download URL: carbon-slack-0.0.8.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.8.tar.gz
Algorithm Hash digest
SHA256 fb8bd9ecd7ae99602c824f0ede1efd0380d2a0b7c1a87bfe43b1ed24dfbf05c0
MD5 04ccd6e821a54cd885a6d5fc8bb241fd
BLAKE2b-256 750f88ff2cd407d3efc630b367d4b68405083f846eb5e563ad7d9dff801cc871

See more details on using hashes here.

File details

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

File metadata

  • Download URL: carbon_slack-0.0.8-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.8-py2-none-any.whl
Algorithm Hash digest
SHA256 b47dad3a821a47f6f2a23907966e5bc269f45aa9ce9d226af7f7c61dd14700f6
MD5 19fc9043e98a52bfab8940471b5cfdbf
BLAKE2b-256 1b3a473bf5e35aec1e0c1318f9d12f8081276140e46598b0485698ef3da08be4

See more details on using hashes here.

Supported by

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