tphakala / birdnet-go

Realtime BirdNET soundscape analyzer
Other
137 stars 14 forks source link

feat: Prometheus Endpoint #123

Closed aster1sk closed 2 months ago

aster1sk commented 2 months ago

I understand there is interest in keeping birdnet-go as lightweight as possible so instead of building out a full-blown Web UI, perhaps an alternative option could be to export metrics to Prometheus and visualized with existing tools like Grafana.

This PR include a bool configuration option to enable a very basic Prometheus CounterVec as well as all of the boilerplate Go performance metrics.

To enable the Prometheus endpoint, simply include the following in your configuration file.

realtime:
    prometheus: true

The current implementation is very simple, the following is sample output from development / testing :

# HELP birdnet_detections How many birdnet_detections partitioned by common name.
# TYPE birdnet_detections counter
birdnet_detections{name="American Robin"} 4
birdnet_detections{name="Downy Woodpecker"} 2
birdnet_detections{name="House Sparrow"} 10
birdnet_detections{name="Northern Cardinal"} 6
birdnet_detections{name="Pileated Woodpecker"} 1
birdnet_detections{name="Rock Pigeon"} 1
birdnet_detections{name="Ruby-crowned Kinglet"} 1

This could easily be improved upon with :

Summary by CodeRabbit

coderabbitai[bot] commented 2 months ago

Walkthrough

The recent update integrates Prometheus metrics into the system's realtime processing capabilities. This includes initializing and registering metrics, specifically a counter for BirdNET detections by common name, and setting up an HTTP endpoint for metrics exposure. Additionally, the processor's method for handling pending detections now updates these metrics based on specific conditions, and configuration settings have been adjusted to support these changes.

Changes

File Path Change Summary
cmd/realtime/..., internal/analysis/realtime.go Added Prometheus metrics initialization, BirdNET detection counter, and metrics exposure via HTTP.
internal/analysis/processor/processor.go Updated pendingDetectionsFlusher method to modify Prometheus detection counter.
internal/conf/config.go Added support for Prometheus metrics in Realtime settings, including new configuration fields.

Poem

🌟🐰✨ In the realm of code, where the rabbits hop,
Metrics spring up, never to stop.
Counting the birds, so high and so free,
With Prometheus's help, as easy as can be.
Hooray for changes, let's give a cheer,
For better insights are now here!
🌟🐰✨


Recent Review Details **Configuration used: CodeRabbit UI**
Commits Files that changed from the base of the PR and between 1659c9af57606639d11d05074800694a1422f1bf and 44b989861e7e22da88107e08b54f3e6ff4091838.
Files ignored due to path filters (2) * `go.mod` is excluded by `!**/*.mod` * `go.sum` is excluded by `!**/*.sum`
Files selected for processing (4) * cmd/realtime/realtime.go (1 hunks) * internal/analysis/processor/processor.go (1 hunks) * internal/analysis/realtime.go (2 hunks) * internal/conf/config.go (2 hunks)
Additional comments not posted (3)
cmd/realtime/realtime.go (1)
`40-40`: Added flag for enabling Prometheus metrics correctly.
internal/conf/config.go (1)
`43-44`: Added configuration fields for Prometheus metrics correctly.
internal/analysis/processor/processor.go (1)
`332-336`: Update to Prometheus detection counter implemented correctly.
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
tphakala commented 2 months ago

Thank you, merged.

isZumpo commented 2 months ago

This is very nice! I would like to add some more metrics in the future for observability of the health of the application etc :+1:

Just one question, would it be better to offer the /metrics view at the same port used for serving the webpage itself at? In this case 8080. That would make the port forwarding a bit easier. However, I suppose one benefit of having it on a separate port is that it allows more control of who should have access to the metrics?

tphakala commented 2 months ago

I have been thinking of adding Go telemetry for some time , so this is more than welcome. I'd prefer to keep telemetry endpoint separate from main application, for example if people wish to publish their dashboard to Internet it would be at least some level security issue if application telemetry would be exposed as well.