Skip to content

Commit

Permalink
Merge pull request #10 from bmistry12/metric-config
Browse files Browse the repository at this point in the history
Allow for user configuration of required metrics
  • Loading branch information
italux authored Mar 24, 2021
2 parents af7fd56 + 61c9efa commit 39fddd7
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 199 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ docker-compose up -d
- `sentry_issues`: Gauge Histogram of open issues split into 3 buckets: 1h, 24h, and 14d
- `sentry_events`: Total events counts per project

### Metric Configuration
By default all metrics are scraped, however, issue or event-related metrics can be disabled by setting the relevant variable to False:
```sh
export SENTRY_SCRAPE_ISSUE_METRICS=False
export SENTRY_SCRAPE_EVENT_METRICS=False
```
By default, if `SENTRY_SCRAPE_ISSUE_METRICS=True or is unset` issue metrics are scraped for `1hour`, `24hours` and `14days`. Any of these can be disabled by setting the relevant variable to False:
```sh
export SENTRY_ISSUES_1H=False
export SENTRY_ISSUES_24H=False
export SENTRY_ISSUES_14D=False
```
As with `SENTRY_AUTH_TOKEN`, all of these variables can be passed in through the `docker run -e VAR_NAME=<>` command or via the `.env` file if using Docker Compose.

## Samples

**Grafana Dashboard**
Expand Down Expand Up @@ -98,6 +112,8 @@ scrape_configs:
- Use a high `scrape_timeout` for the exporter job
> General recomendation is to set `scrape_interval - 1` (i.e.: `4m`)

- If the scraping of particular metrics are disabled the values above can be reduced depending on your setup.

## 📒 Documentation

[Sentry Prometheus Exporter documentation](https://italux.github.io/sentry-prometheus-exporter/)
Expand Down
13 changes: 12 additions & 1 deletion exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
app = Flask(__name__)


def get_metric_config():
"""Get metric scraping options."""
scrape_issue_metrics = getenv("SENTRY_SCRAPE_ISSUE_METRICS") or "True"
scrape_events_metrics = getenv("SENTRY_SCRAPE_EVENT_METRICS") or "True"
default_for_time_metrics = "True" if scrape_issue_metrics == "True" else "False"
get_1h_metrics = getenv("SENTRY_ISSUES_1H") or default_for_time_metrics
get_24h_metrics = getenv("SENTRY_ISSUES_24H") or default_for_time_metrics
get_14d_metrics = getenv("SENTRY_ISSUES_14D") or default_for_time_metrics
return [scrape_issue_metrics, scrape_events_metrics, get_1h_metrics, get_24h_metrics, get_14d_metrics]


@app.route("/")
def hello_world():
return "<h1>Sentry Issues & Events Exporter</h1>\
Expand All @@ -41,7 +52,7 @@ def sentry_exporter():
sentry = SentryAPI(BASE_URL, AUTH_TOKEN)
log.info("exporter: cleaning registry collectors...")
clean_registry()
REGISTRY.register(SentryCollector(sentry, ORG_SLUG, PROJECTS_SLUG))
REGISTRY.register(SentryCollector(sentry, ORG_SLUG, get_metric_config(), PROJECTS_SLUG))
exporter = DispatcherMiddleware(app.wsgi_app, {"/metrics": make_wsgi_app()})
return exporter

Expand Down
Loading

0 comments on commit 39fddd7

Please sign in to comment.