pg_exporter copilot-instructions.md

Project instructions for pg_exporter, a Rust program that reads PostgreSQL database statistics and makes them available to Prometheus monitoring. They describe the project's tools, tests, and safety requirements.

In plain words
What is it for?
Use them when editing pg_exporter, checking Rust formatting and linting, running tests, or writing PostgreSQL queries and result handling.
Why use it?
They give a coding agent the project context and rules needed to make safer changes without database-reading crashes or type errors.

Instructions file for GitHub Copilot

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/nbari/pg_exporter/copilot-instructions
Clone the repo
git clone --depth 1 https://github.com/nbari/pg_exporter

Made for: GitHub Copilot.

Per session 1,924 This file is loaded in full into every session.
When invoked 1,924 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01924 $0.01924
Opus 5 $0.00962 $0.00962
Sonnet 5 $0.00385 $0.00385
Haiku 4.5 $0.00192 $0.00192

Measured 3d ago against content hash 1e06b0ae31b4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

pg_exporter copilot-instructions.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.github/copilot-instructions.md · 286 lines

How it starts

The opening of the file, as written. The whole thing — 286 lines — stays where its author put it; the contents beside it link to each section on GitHub.

GitHub Copilot Instructions for pg_exporter

Project Overview

This is a PostgreSQL metrics exporter written in Rust. It collects metrics from PostgreSQL and exposes them in Prometheus format. Safety and reliability are paramount - all code must handle edge cases gracefully without panics.

Language & Tooling

  • Language: Rust (latest stable)
  • Formatting: cargo fmt --all -- --check
  • Linting: cargo clippy --all-targets --all-features -- -D warnings
  • Testing: just test (runs clippy, fmt, and all tests)
  • Build Tool: just command runner (see .justfile)

Critical Safety Rules

1. Always Use try_get() Instead of get()

NEVER use row.get() - it panics on NULL or type mismatches.

// ❌ WRONG - Will panic on NULL
let value: i64 = row.get("column");

// ✅ CORRECT - Safe handling
let value: i64 = row.try_get("column").unwrap_or(0);

2. Always Cast SQL Numeric Columns

PostgreSQL NUMERIC type doesn't directly map to Rust types. Always use explicit casts.

// ❌ WRONG - Type mismatch
SELECT total_time FROM pg_stat_statements

// ✅ CORRECT - Explicit cast
SELECT total_time::double precision FROM pg_stat_statements
SELECT calls::bigint FROM pg_stat_statements

3. Always Check Denominator Before Division

Prevent division by zero in both SQL and Rust.

// ❌ WRONG - Division by zero
let ratio = hits / (hits + misses);

// ✅ CORRECT - Safe division
let total = hits + misses;
let ratio = if total > 0 { hits as f64 / total as f64 } else { 0.0 };

SQL version:

-- ✅ CORRECT
CASE WHEN (shared_blks_hit + shared_blks_read) > 0
     THEN shared_blks_hit::double precision / (shared_blks_hit + shared_blks_read)
     ELSE 0.0
END as cache_hit_ratio

4. Always Check Extension Availability

Handle missing extensions gracefully with fetch_optional().

// ✅ CORRECT - Check extension exists
let result = sqlx::query("SELECT * FROM pg_stat_statements LIMIT 1")
    .fetch_optional(&pool)
    .await?;

if result.is_none() {
    warn!("pg_stat_statements extension not available");
    return Ok(());
}

Read the full file on GitHub · 286 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 286 lines · 1,924 tokens per session scan A 1e06b0ae31b4

Subscribe to this mod's changes

pg_exporter copilot-instructions.md is an instructions file published in the GitHub repository nbari/pg_exporter (49 stars, last pushed 11d ago), licensed BSD-3-Clause. It adds 1,924 tokens to every session, about $0.0096 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.