{"id":16307063,"url":"https://github.com/fujiwara/cloudwatch-to-mackerel","last_synced_at":"2026-01-05T13:05:49.312Z","repository":{"id":57494063,"uuid":"171888819","full_name":"fujiwara/cloudwatch-to-mackerel","owner":"fujiwara","description":"Copy metrics from Amazon CloudWatch to Mackerel.","archived":false,"fork":false,"pushed_at":"2024-08-01T01:20:13.000Z","size":79,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-28T16:08:25.756Z","etag":null,"topics":["aws","cloudwatch","mackerel"],"latest_commit_sha":null,"homepage":"","language":"Go","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/fujiwara.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-21T14:41:44.000Z","updated_at":"2024-05-22T02:43:18.000Z","dependencies_parsed_at":"2024-05-01T03:27:24.730Z","dependency_job_id":"98f9f05f-0771-475d-a2c7-796385696c47","html_url":"https://github.com/fujiwara/cloudwatch-to-mackerel","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fcloudwatch-to-mackerel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fcloudwatch-to-mackerel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fcloudwatch-to-mackerel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fujiwara%2Fcloudwatch-to-mackerel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fujiwara","download_url":"https://codeload.github.com/fujiwara/cloudwatch-to-mackerel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245020147,"owners_count":20548154,"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":["aws","cloudwatch","mackerel"],"created_at":"2024-10-10T21:12:23.245Z","updated_at":"2026-01-05T13:05:44.270Z","avatar_url":"https://github.com/fujiwara.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cloudwatch-to-mackerel\n\n[![GoDoc](https://godoc.org/github.com/fujiwara/cloudwatch-to-mackerel?status.svg)][godoc]\n\n[godoc]: https://godoc.org/github.com/fujiwara/cloudwatch-to-mackerel\n\nCopy metrics from [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) to [Mackerel](https://mackerel.io).\n\ncloudwatch-to-mackerel agent fetches metrics from Amazon CloudWatch by MetricDataQuery, and post these metrics to Mackerel as service/host metrics.\n\n## Usage (cw2mkr command)\n\n### Install\n\nHomebrew or [binary packages](https://github.com/fujiwara/cloudwatch-to-mackerel/releases).\n\n```console\n$ brew install fujiwara/tap/cloudwatch-to-mackerel\n```\n\n### Usage\n\n```console\n$ cw2mkr metric-data-query.json\n```\n\n```\nUsage of cw2mkr:\n  -dump-metrics\n        dump metrics to stdout instead of posting to mackerel. env:CW2MKR_DUMP_METRICS\n  -end-time int\n        end time(unix) if negative, relative time from now. env:CW2MKR_END_TIME\n  -log-level string\n        log level (debug, info, warn, error) env:CW2MKR_LOG_LEVEL (default \"info\")\n  -query string\n        query content. env:CW2MKR_QUERY\n  -query-file string\n        query file path. env:CW2MKR_QUERY_FILE\n  -start-time int\n        start time(unix) if negative, relative time from now. env:CW2MKR_START_TIME\n  -time-offset duration\n        time offset for relative time. adds the offset to mackerel's metrics env:CW2MKR_TIME_OFFSET\n  -version\n        show version\n```\n\nEnvironment variable `AWS_REGION` and `MACKEREL_APIKEY` are required both.\n\nBy the default, end-time is now, start-time is 3 min ago.\n\nSome flags can be set by environment variables. The following is an example.\n\n```console\n$ cw2mkr -query-file query.json\n$ CW2MKR_QUERY_FILE=query.json cw2mkr\n```\n\n## Usage (as library)\n\n```go\nimport (\n\t\"github.com/fujiwara/cloudwatch-to-mackerel/agent\"\n)\n\n// MetricDataQuery JSON\nquery := []byte(`\n[\n  {\n    \"Id\": \"m1\",\n    \"Label\": \"service=MyService:alb.my-alb.response-time.p99\",\n    \"MetricStat\": {\n      \"Metric\": {\n        \"Namespace\": \"AWS/ApplicationELB\",\n        \"MetricName\": \"TargetResponseTime\",\n        \"Dimensions\": [\n          {\n            \"Name\": \"LoadBalancer\",\n            \"Value\": \"app/my-alb/8e0641feccf3491c\"\n          }\n        ]\n      },\n      \"Period\": 60,\n      \"Stat\": \"p99\"\n    }\n  },\n  {\n    \"Id\": \"m2\",\n    \"Label\": \"service=MyService:alb.my-alb.response-time.p90\",\n    \"MetricStat\": {\n      \"Metric\": {\n        \"Namespace\": \"AWS/ApplicationELB\",\n        \"MetricName\": \"TargetResponseTime\",\n        \"Dimensions\": [\n          {\n            \"Name\": \"LoadBalancer\",\n            \"Value\": \"app/my-alb/8e0641feccf3491c\"\n          }\n        ]\n      },\n      \"Period\": 60,\n      \"Stat\": \"p90\"\n    }\n  }\n]\n`)\n\nerr := agent.Run(agent.Option{Query: query})\n```\n\nSee [pkg.go.dev](https://pkg.go.dev/github.com/fujiwara/cloudwatch-to-mackerel/agent) in details.\n\n## Usage (Lambda)\n\nA `cw2mkr` binary can be used as an AWS Lambda function.\n\n1. Rename `cw2mkr` binary to `bootstrap`.\n2. Create a zip archive with `bootstrap` and `metric-data-query.json`.\n3. Upload the zip archive to AWS Lambda.\n4. Invoke the Lambda function.\n\nYou can set flags by environment variables (`CW2MKR_QUERY_FILE` etc.).\n\nSupported runtime is `provided.al2` and `provided.al2023`.\n\nIf the binary name is \"cw2mkr\", cw2mkr runs as a CLI command whenever it is executed on a Lambda environment or not.\n\n### Query format\n\nSame as [MetricDataQuery](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDataQuery.html) JSON format.\n\nSee also `aws cloudwatch get-metric-data help`.\n\n### Label syntax\n\ncloudwatch-to-mackerel parses `Label` fields in MetricDataQuery as Mackerel's service/host which to post metrics.\n\n```ebnf\n(* service_name, host_id, metric_name are defined by Mackerel *)\nservice = \"service=\" , service_name ;\nhost    = \"host=\" , host_id ;\noption  = \"emit_zero\"\nlabel   = ( service | host ) , \":\" , metric_name , { \";\", option } ;\n```\n\n## License\n\nCopyright 2019 FUJIWARA Shunichiro.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffujiwara%2Fcloudwatch-to-mackerel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffujiwara%2Fcloudwatch-to-mackerel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffujiwara%2Fcloudwatch-to-mackerel/lists"}