Export Twitch metrics to Prometheus.
To run it:
make
./twitch_exporter [flags]
Metric | Meaning | Labels |
---|---|---|
twitch_channel_up | Is the twitch channel Online. | username, game |
twitch_channel_viewers_total | Is the total number of viewers on an online twitch channel. | username, game |
twitch_channel_views_total | Is the total number of views on a twitch channel. | username |
twitch_channel_followers_total | Is the total number of follower on a twitch channel. | username |
twitch_channel_subscribers_total | Is the total number of subscriber on a twitch channel. | username, tier, gifted |
./twitch_exporter --help
twitch.channel
: The name of a twitch channel.twitch.client-id
: The client ID to request the New Twitch API (helix).twitch.access-token
: The access token to request the New Twitch API (helix).log.format
: Set the log target and format. Example:logger:syslog?appname=bob&local=7
orlogger:stdout?json=true
log.level
: Logging level.info
by default.version
: Show application version.web.listen-address
: Address to listen on for web interface and telemetry.web.telemetry-path
: Path under which to expose metrics.--[no-]collector.channel_followers_total
: Enable the channel_followers_total collector (default: enabled).--[no-]collector.channel_subscribers_total
: Enable the channel_subscribers_total collector (default: disabled).--[no-]collector.channel_up
: Enable the channel_up collector (default: enabled).--[no-]collector.channel_viewers_total
: Enable the channel_viewers_total collector (default: enabled).
TODO
You can deploy this exporter using the damoun/twitch-exporter Docker image.
For example:
docker pull damoun/twitch-exporter
docker run -d -p 9184:9184 \
damoun/twitch-exporter \
--twitch.client-id <secret> \
--twitch.access-token <secret> \
--twitch.channel dam0un
Helm must be installed to use the charts. Please refer to Helm's documentation to get started.
Once Helm has been set up correctly, add the repo as follows:
helm repo add twitch-exporter https://damoun.github.io/twitch-exporter
If you had already added this repo earlier, run helm repo update
to retrieve
the latest versions of the packages. You can then run helm search repo twitch-exporter
to see the charts.
To install the twitch-exporter chart:
helm install my-twitch-exporter twitch-exporter/twitch-exporter
To uninstall the chart:
helm delete my-twitch-exporter
You are able to use a helm chart to manage your exporter, create a file named
helmfile.yaml
and then add this:
repositories:
- name: twitch-exporter
url: https://damoun.github.com/twitch_exporter/
- name: grafana
url: https://grafana.github.io/helm-charts
releases:
- name: alloy
namespace: twitch-exporter
chart: grafana/alloy
values:
- ./alloy.values.yaml
- name: twitch-exporter
namespace: twitch-exporter
chart: twitch-exporter/twitch-exporter
values:
- ./twitch-exporter.values.yaml
Then create a file called alloy.values.yaml
:
alloy:
configMap:
create: true
content: |-
prometheus.remote_write "mimir" {
endpoint {
# make sure to update this url with your proper push endpoint info,
# cloud for example required authentication.
url = "xxx/api/v1/push"
}
}
prometheus.scrape "twitch_exporter_metrics" {
targets = [{__address__ = "twitch-exporter.twitch-exporter.svc:9184"}]
metrics_path = "/metrics"
forward_to = [prometheus.remote_write.mimir.receiver]
scrape_timeout = "1m"
# twitch cache is going to be a pain anyway, so 5m scrape helps with any
# potential rate limits and works around cache
scrape_interval = "5m"
}
Create a file named twitch-exporter.values.yaml
twitch:
clientId: "muy2fhyb2esa49w3n70fpumxr78ruh"
accessToken: "dvmkxzay1xi4erxfu0x56h6qsfzukj"
channels:
- jordofthenorth
- timthetatman
- dam0un
- surdaft
Note: You can add see more config options in charts/twitch-exporter/values.yaml. Ingress is disabled by default, however you can enable it to allow for public access to your exporter. Such as if you use a firewall and scrape from another device.