{"id":35672414,"url":"https://github.com/bborbe/metrics","last_synced_at":"2026-01-05T19:04:25.030Z","repository":{"id":317668016,"uuid":"1068342464","full_name":"bborbe/metrics","owner":"bborbe","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-05T22:34:59.000Z","size":180,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-09T12:31:32.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bborbe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-02T08:34:34.000Z","updated_at":"2025-12-05T22:35:03.000Z","dependencies_parsed_at":"2025-10-02T10:23:38.496Z","dependency_job_id":"0d400115-eb59-413d-b9cc-6b9be4e186fc","html_url":"https://github.com/bborbe/metrics","commit_stats":null,"previous_names":["bborbe/metrics"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/bborbe/metrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bborbe%2Fmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bborbe%2Fmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bborbe%2Fmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bborbe%2Fmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bborbe","download_url":"https://codeload.github.com/bborbe/metrics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bborbe%2Fmetrics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28218058,"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","status":"online","status_checked_at":"2026-01-05T02:00:06.358Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-01-05T19:02:26.102Z","updated_at":"2026-01-05T19:04:20.664Z","avatar_url":"https://github.com/bborbe.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Metrics\n\nGo library for working with Prometheus metrics.\n\n## Features\n\n- **Name Builder**: Create valid Prometheus metric names from arbitrary strings\n- **Pusher**: Push metrics to Prometheus Pushgateway\n\n## Installation\n\n```bash\ngo get github.com/bborbe/metrics\n```\n\n## Usage\n\n### Building Metric Names\n\n```go\nimport \"github.com/bborbe/metrics\"\n\n// Create a valid Prometheus metric name\nname := metrics.BuildName(\"my-service\", \"request_count\")\n// Result: \"my_service_request_count\"\n\n// Add to existing name\nname = name.Add(\"total\")\n// Result: \"my_service_request_count_total\"\n```\n\nThe `BuildName` function:\n- Converts to lowercase\n- Replaces illegal characters with underscores\n- Handles leading numbers\n- Collapses multiple underscores\n\n### Pushing Metrics\n\n```go\nimport (\n    \"context\"\n    \"github.com/bborbe/metrics\"\n    \"github.com/prometheus/client_golang/prometheus\"\n)\n\nfunc pushMetrics(ctx context.Context) error {\n    // Create a registry and register your metrics\n    prometheusRegistry := prometheus.NewRegistry()\n\n    // Create and configure a pusher using the fluent API\n    pusher := metrics.NewPusher(\n        \"http://monitoring-pushgateway:9091\",\n        metrics.BuildName(\"kafka\", \"backup\", \"my_topic\"),\n    ).Gatherer(prometheusRegistry)\n\n    // Push metrics to the gateway (using context from caller)\n    if err := pusher.Push(ctx); err != nil {\n        return err\n    }\n    return nil\n}\n```\n\nThe pusher supports a fluent API for configuration:\n\n```go\npusher := metrics.NewPusher(url, jobName).\n    Gatherer(registry).              // Use a custom registry\n    Collector(myCollector).          // Add a specific collector\n    Client(customHTTPClient)         // Use a custom HTTP client\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbborbe%2Fmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbborbe%2Fmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbborbe%2Fmetrics/lists"}