{"id":22636126,"url":"https://github.com/47degrees/sbt-energymonitor","last_synced_at":"2025-10-25T23:22:02.021Z","repository":{"id":37103671,"uuid":"463244397","full_name":"47degrees/sbt-energymonitor","owner":"47degrees","description":"Measure energy consumption around sbt commands","archived":false,"fork":false,"pushed_at":"2023-03-29T05:11:19.000Z","size":284,"stargazers_count":7,"open_issues_count":20,"forks_count":0,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-11T21:12:00.739Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/47degrees.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-24T17:41:56.000Z","updated_at":"2024-04-02T17:40:38.000Z","dependencies_parsed_at":"2023-02-05T10:00:38.462Z","dependency_job_id":null,"html_url":"https://github.com/47degrees/sbt-energymonitor","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/47degrees%2Fsbt-energymonitor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/47degrees%2Fsbt-energymonitor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/47degrees%2Fsbt-energymonitor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/47degrees%2Fsbt-energymonitor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/47degrees","download_url":"https://codeload.github.com/47degrees/sbt-energymonitor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480429,"owners_count":21110937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T03:18:23.923Z","updated_at":"2025-10-25T23:21:56.987Z","avatar_url":"https://github.com/47degrees.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sbt-energymonitor\n\nMeasure energy consumption around sbt commands.\n\nThe workflow this plugin supports is calling `energyMonitorPreSample` before you invoke some sbt commands, then calling `energyMonitorPostSample` afterward in order to obtain an `EnergyDiff` that you can track over time.\n\nIn order to use this plugin, you'll need to provide a jar containing `jRAPL` as a dependency in your `project/` folder -- you can see an example in the [scripted tests in this repo](./src/sbt-test/sbt-energymonitor/simple/project/lib). You can use the jar in this repo's `lib/` directory, which was copied from [Wojciech Mazur's fork](https://github.com/WojciechMazur/Energy-Languages/tree/6a75af59de2c7602c382c7f7271ddeaa563e29e0) of the `Energy-Languages` repo.\n\n## Usage\n\nThis plugin requires sbt 1.0.0+. It provides four tasks: `energyMonitorPreSample`, `energyMonitorPostSample`, `energyMonitorPostSampleHttp`, and `energyMonitorPostSampleGitHub` and appropriate settings for configuring them.\n\n### `energyMonitorPreSample`\n\nThis task takes an initial snapshot of energy usage and writes the results to the value configured in `energyMonitorOutputFile`.\n\nIf `energyMonitorDisableSampling` is true, this task will do nothing.\n\n### `energyMonitorPostSample`\n\nThis task reads the initial sample from the path configured in `energyMonitorOutputFile`, takes a new snapshot,\nand prints calculated energy usage to the console.\n\nIf `energyMonitorDisableSampling` is true, this task will do nothing.\n\n### `energyMonitorPostSampleHttp`\n\nThis task works like `energyMonitorPostSample`, but instead of printing results to the console, sends\nthem to an HTTP server with some metadata. The server should accept POSTs to the configured URL, with an HTTP body like:\n\n```json\n{\n  \"joules\": 23,\n  \"seconds\": 8,\n  \"organization\": \"47degrees\",\n  \"repository\": \"sbt-energymonitor\",\n  \"branch\": \"abcde\",\n  \"run\": 8,\n  \"recordedAt\": \"2022-05-05T10:15:00Z\"\n}\n```\n\nIts behavior is controlled by three settings: `energyMonitorPersistenceServerUrl`, and `energyMonitorPersistenceTag`.\n\nHowever, if `energyMonitorDisableSampling` is `true`, this task will do nothing.\n\nYou can see an example usage of this task in the scripted test included in this repository under the `energy-monitor-plugin/src/sbt-test/http-store` directory.\n\n#### `energyMonitorPersistenceServerUrl`\n\nThis setting determines where the task should send the information about energy consumption. Its default value is `http://localhost:8080`, which will be correct if you're experimenting locally and using the demo server provided in the `energyMonitorPersistenceApp` module. You _should not use a local server for real testing though_, since the server's energy consumption will also show up in the power consumed by the CPU / memory during your energy tests.\n\n#### `energyMonitorPersistenceTag`\n\nThis setting determines whether some arbitrary string will be included with the energy consumption sample. You might want to do this if there's some significant change that you think should explain differences in energy, for instance, \"upgrade to cats-effect 3\", or \"refine types to shrink validation in core business logic,\" or something similar. You can put whatever information you want in the tag, or nothing at all. Its default value is `None`.\n\n### `energyMonitorPostSampleGitHub`\n\nThis task works like `energyMonitorPostSample`, but instead of printing results to the console, sends them to a pull request comment.\nIt was written with the aim of posting energy consumption in every GitHub Actions CI run, but that's\n[not going to work](https://github.com/47degrees/sbt-energymonitor/pull/6#issuecomment-1054567642) with the\ncurrent infrastructure backing GitHub Actions. You can still do this locally though if you're testing a PR and\nwant to add a comment documenting energy usage. To do so, you'll need to export four environment variables in\nthe shell session where you're running `sbt`:\n\n- `GITHUB_REPOSITORY`: this value is the `org-name/repo-name` repository that you're working in, e.g. `47degrees/sbt-energymonitor`\n- `GITHUB_TOKEN`: this value is a [GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)\n- `GITHUB_RUN_ATTEMPT`: this value is an integer representing which CI run statistics correspond to. You can set this to any integer value,\n  though tying it to the commit sequence in a pull request might make sense.\n- `GITHUB_REF`: this is a reference like `refs/pull/1234/merge`, where `1234` is the PR number you want to add the comment to.\n\nYou can read more about any of these environment variables in the\n[default environment variables](https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables)\nGitHub Actions documentation.\n\nYou can see example comments in [this sandbox repo for learning `droste`](https://github.com/jisantuc/droste-playground/pull/5#issuecomment-1055702006).\n\nIf `energyMonitorDisableSampling` is true, this task will do nothing.\n\n### `energyMonitorDisableSampling`\n\nThis setting controls whether any of the sampling tasks do anything. If it's set to `true`, none of them will do any work, and they'll\nlog a message that they're not doing any work because sampling is disabled.\n\n### `energyMonitorOutputFile`\n\nThis setting contains the path that the `energyMonitorPreSample` task should write to and that the `energyMonitorPostSample`\nand `energyMonitorPostSampleGitHub` tasks should read from. It defaults to `target/energy-sample`, so if you're ignoring\n`target/` directories in `git`, it shouldn't annoy you. However, if you'd like to write the sample somewhere else, you\nhave that power.\n\n### Testing\n\nRun `test` for regular unit tests.\n\nRun `scripted` for [sbt script tests](http://www.scala-sbt.org/1.x/docs/Testing-sbt-plugins.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F47degrees%2Fsbt-energymonitor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F47degrees%2Fsbt-energymonitor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F47degrees%2Fsbt-energymonitor/lists"}