{"id":23734150,"url":"https://github.com/kintsdev/postmetric","last_synced_at":"2026-02-21T18:34:30.690Z","repository":{"id":269459400,"uuid":"907484370","full_name":"kintsdev/postmetric","owner":"kintsdev","description":"Prometheus exporter for PostgreSQL","archived":false,"fork":false,"pushed_at":"2024-12-24T09:12:19.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T05:34:31.913Z","etag":null,"topics":["postgres","postgresql","postgressql","prometheus-exporter","prometheus-metrics"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kintsdev.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":"2024-12-23T17:26:37.000Z","updated_at":"2024-12-24T09:12:22.000Z","dependencies_parsed_at":"2024-12-23T18:41:47.976Z","dependency_job_id":null,"html_url":"https://github.com/kintsdev/postmetric","commit_stats":null,"previous_names":["kintsdev/postmetric"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kintsdev%2Fpostmetric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kintsdev%2Fpostmetric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kintsdev%2Fpostmetric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kintsdev%2Fpostmetric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kintsdev","download_url":"https://codeload.github.com/kintsdev/postmetric/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239859568,"owners_count":19708864,"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":["postgres","postgresql","postgressql","prometheus-exporter","prometheus-metrics"],"created_at":"2024-12-31T05:34:46.821Z","updated_at":"2026-02-21T18:34:25.657Z","avatar_url":"https://github.com/kintsdev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostMetric\n\nThis application is a Prometheus exporter for PostgreSQL, designed to collect and expose a wide range of PostgreSQL metrics. It provides detailed insights into PostgreSQL performance, including connections, queries, table statistics, replication, and more.\n\n## Features\n\nThe exporter collects and exposes the following metrics:\n\n### Connection Metrics\n- **Connection usage percentage**\n- **Idle connections**\n- **Long-running queries**\n\n### Query Metrics\n- **Active and waiting queries**\n\n### Table Metrics\n- **Live tuples**\n- **Dead tuples**\n- **Table size**\n- **Index size**\n\n### Write-Ahead Log (WAL) Metrics\n- **WAL size in bytes**\n- **WAL files count**\n\n### Buffer Cache Metrics\n- **Cache hits and reads**\n- **Total buffer usage**\n\n### Replication Metrics\n- **Replication lag in bytes**\n\n### Transaction Metrics\n- **Commit rate**\n- **Rollback transactions**\n\n### Other Metrics\n- **Table bloat**\n- **Autovacuum workers**\n- **Temporary table size**\n- **Checkpoint write time**\n- **Deadlocks**\n- **Locks**\n\n### User Metrics\n- **User connections**\n- **User queries**\n\n### Database Metrics\n- **Database transaction rate**\n\n## Prerequisites\n\n- A PostgreSQL instance with sufficient permissions to access `pg_stat` and related views.\n- A Prometheus server to scrape and visualize the metrics.\n- Go 1.16 or later (for building the application).\n\n## Setup\n\nFollow these steps to set up PostMetric:\n\n1. **Clone the Repository**\n   ```bash\n   git clone git@github.com:kintsdev/postmetric.git\n   cd postmetric\n   ```\n\n2. **Build the Application**\n   ```bash\n   go build -o postmetric\n   ```\n\n3. **Configure the PostgreSQL Connection**\n   Set the PostgreSQL connection string as an environment variable:\n   ```bash\n   export POSTGRES_CONNECTION_STRING=\"postgresql://user:password@host:port/dbname?sslmode=disable\"\n   ```\n\n4. **Run the Application**\n   ```bash\n   ./postmetric\n   ```\n\n## Prometheus Configuration\n\nAdd the following scrape configuration to your Prometheus configuration file:\n\n```yaml\nscrape_configs:\n  - job_name: 'postmetric'\n    static_configs:\n      - targets: ['localhost:8080']\n```\n\n## Accessing Metrics\n\nPostMetric exposes metrics at:\n\n```\nhttp://localhost:8080/metrics\n```\n\n## PostgreSQL Metrics Overview\n\nBelow is an overview of the metrics exposed by PostMetric:\n\n### Connection Metrics\n- **`postgres_connection_usage`**: Percentage of used connections out of the maximum connections.\n- **`postgres_idle_connections`**: Number of idle connections.\n\n### Query Metrics\n- **`postgres_active_queries`**: Number of currently active queries.\n- **`postgres_waiting_queries`**: Number of queries waiting for locks.\n- **`postgres_long_running_queries`**: Queries running for more than 5 minutes.\n\n### Table Statistics\n- **`postgres_table_stats`**: Includes the following statistics:\n  - Live tuples\n  - Dead tuples\n  - Total size\n  - Table size\n  - Index size\n  - *(Labeled by `table_name` and `stat_type`)*\n\n### Replication Metrics\n- **`postgres_replication_lag`**: Replication lag in bytes.\n\n### WAL Metrics\n- **`postgres_wal_stats`**: Includes:\n  - WAL size\n  - WAL file count\n\n### Cache Metrics\n- **`postgres_buffer_cache`**: Includes:\n  - Cache hits\n  - Cache reads\n  - Total usage\n\n### Transaction Metrics\n- **`postgres_commit_rate`**: Percentage of committed transactions.\n- **`postgres_rollback_transactions`**: Number of rolled-back transactions.\n\n### Other Metrics\n- **`postgres_table_bloat_bytes`**: Estimated bloat size in bytes.\n- **`postgres_autovacuum_workers`**: Number of active autovacuum workers.\n- **`postgres_temp_table_size_bytes`**: Total size of temporary tables.\n- **`postgres_checkpoint_write_time_ms`**: Average checkpoint write time in milliseconds.\n- **`postgres_deadlocks`**: Number of deadlocks detected.\n- **`postgres_locks`**: Number of active locks.\n\n### User Metrics\n- **`postgres_user_connections`**: Number of connections per user.\n- **`postgres_user_queries`**: Number of queries executed per user.\n\n### Database Metrics\n- **`postgres_database_transaction_rate`**: Transaction rate per database.\n\n---\n\nPostMetric provides a comprehensive set of metrics to help you monitor and optimize PostgreSQL performance effectively. Happy monitoring!\n\n## Package Structure\n\nThe codebase is organized into the following packages:\n\n- **`main`**: The entry point of the application.\n- **`metrics`**: Contains metric definitions and registration logic.\n- **`collector`**: Contains the logic for collecting metrics from PostgreSQL.\n\n## Adding New Metrics\n\nTo add new metrics, follow these steps:\n\n1. **Define the Metric**: Add the new metric definition in `pkg/metrics/metrics.go`.\n2. **Register the Metric**: Ensure the new metric is registered in the `RegisterMetrics` function in `pkg/metrics/metrics.go`.\n3. **Collect the Metric**: Update the `CollectMetrics` function in `pkg/metrics/collector.go` to collect the new metric.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkintsdev%2Fpostmetric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkintsdev%2Fpostmetric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkintsdev%2Fpostmetric/lists"}