Git Product home page Git Product logo

discord-influx's Introduction

Discord InfluxDB exporter

Grafana Preview

Export Discord chat metrics to InfluxDB time-series DB

Installation

From source

Requirements: Go 1.16

git clone https://github.com/terorie/discord-influx.git
go build -o ./discord-influx .

Docker (from source)

git clone https://github.com/terorie/discord-influx.git
docker build -t terorie/discord-influx .

Docker (binary)

docker pull ghcr.io/terorie/discord-influx:latest

Source: https://github.com/users/terorie/packages/container/package/discord-influx

Usage

Reference: ./discord-influx --help

Environment variables

Key Description
INFLUXDB_TOKEN InfluxDB API token
INFLUXDB_TOKEN_FILE Path to a file containing InfluxDB API token
DISCORD_TOKEN Discord API token
DISCORD_TOKEN_FILE Path to a file containing Discord API token

Flags

Key Description
--debug Enables debug logging
--influxdb-url https://... URL to InfluxDB API
--influxdb-org org_name InfluxDB org name
--influxdb-bucket my_bucket InfluxDB bucket name

Live mode

Live mode listens for new messages indefinitely and continually stats to InfluxDB.

Usage

export INFLUXDB_TOKEN=xxx
export DISCORD_TOKEN=xxx
./discord-influx live \
  --influxdb-url http://localhost:8086 \
  --influxdb-org my_org \
  --influxdb-bucket my_bucket

History mode

History mode backfills stats of past messages to InfluxDB for the given guilds and channels.

This takes a while because Discord's APIs are heavily rate-limited.

It runs once until the export is complete. This operation is idempotent.

Targets

Export targets are given are positional arguments, as either of these two forms:

  • <guild_id>: Export all channels in given guild
  • <guild_id>/<channel_id>: Export specific channel in guild

So for example historic 1234 9999/123 exports

  • All channels in guild ID 1234
  • Channel 123 in guild ID 9999

Time frame

The default time frame spans all messages up to the current system time.

The time frame can be adjusted using flags.

Flags

Key Description
--start <message_id> Export after this message ID
--start 2006-01-02T15:04:05Z Export after this RFC 3339 timestamp
--stop <message_id> Export before this message ID
--start 2007-01-02T15:04:05Z Export before this RFC 3339 timestamp

Usage

export INFLUXDB_TOKEN=xxx
export DISCORD_TOKEN=xxx
./discord-influx historic <org_id> [<org_id> ...] \
  --influxdb-url http://localhost:8086 \
  --influxdb-org my_org \
  --influxdb-bucket my_bucket \
  --start 2006-01-02T15:04:05Z \
  --stop 212490023738540032

Metrics

This exporter requires a bucket with 1ns or 1ms accuracy.

With the following labels:

Name Description
guild Guild ID
channel Channel Name
user Username nick#1234
emoji Emoji char or reaction ID

It exports the following time series:

Name Field Labels
discord_messages count guild, channel
discord_user_messages count guild, user
discord_message_reactions count guild, emoji

Attributions

This project is made possible by:

Troubleshooting

Invalid Discord token

Logs: {"error": "HTTP 401 Unauthorized, {\"message\": \"401: Unauthorized\", \"code\": 0}", "guild": "xxx"}

Meaning: Your Discord Bot token is invalid.

Insufficient Discord permissions

Logs: {"error": "HTTP 403 Forbidden, {\"message\": \"Missing Access\", \"code\": 50001}", "guild": "xxx"}

Meaning: Your Discord Bot does not have sufficient permissions.

Invalid InfluxDB token

Logs: influxdb2client E! Write error: unauthorized: unauthorized access

Meaning: Your InfluxDB token is invalid or does not have the required permissions.

discord-influx's People

Contributors

riptl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

discord-influx's Issues

Use streaming endpoints

The application should stream messages from Discord instead of polling using history requests. Using the streaming endpoints also sets the bot status to online (#3).

Don't understand README

Hello !

I don't understand what we have to do in the part :

Export DISCORD_TOKEN to Bot xxx.

Could you be more specific ?

Thank you

Best regards

Running multiple instances?

If i wanted to monitor two discord servers at one how would this be acchived? i see the dashboard lets you choose which guild to show. Can the same bot be added to another server and then passed another instance of influx discord with the other servers guild/id?

Awesome project by the way.

Updated Grafana dashboards

The existing Grafana dashboards broke with version 1.0 of this bot.

TODO:

  • Create a new Grafana dashboard and upload it to this repo.
  • Upload dashboard to Grafana cloud.
  • Update README instructions.

Docker Terminology

What is the proper docker terminology in order to pass the required flags into the container in order to get the container running? I attempted:
docker container run -it [image] ./discord-influx --influxdb-url [URL] --influxdb-org [org] --influxdb-bucket [bucketname]

However was given an error of:

Error: unknown command "./discord-influx" for "discord-influx"
Run 'discord-influx --help' for usage.
unknown command "./discord-influx" for "discord-influx"

Are there Environment Variables instead for me to put the required info in instead?

Thanks!

Streaming too fast causes api to deny requests

Im having an issue trying to add one of my servers. It started sending a bunch a data then the api started refusing any more requests. How could i slow this down to get all the data without being penalized by discord?

Flushed 128 aggregations
Flushed 128 aggregations
Flushed 128 aggregations
Flushed 128 aggregations
Flushed 128 aggregations
Flushed 128 aggregations
Flushed 128 aggregations
Flushed 128 aggregations
Flushed 128 aggregations
Flushed 27 aggregations
Message stream aborted: HTTP status client error (403 Forbidden) for url (https://discordapp.com/api/v6/channels/##########messages?limit=100&after=0)

Add metrics for users and emojis?

I'm interested in adding metrics for user messages and the rate at which server emojis are used for my own server. This is something I intend to do myself whenever motivation and free time from school align, just thought I'd go ahead and make an issue to see if anyone has thoughts on the subject.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.