Metrics and KPIs

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

GitHub Security Administration: Monitoring and Reporting Metrics and KPIs

Introduction: Why Security Metrics Matter in GitHub

In the modern software development lifecycle, GitHub has evolved from a simple code hosting platform into the central nervous system of engineering organizations. Because it holds your source code, CI/CD pipelines, secret keys, and collaboration workflows, it is a primary target for attackers. Security administration is no longer just about configuring permissions; it is about visibility. Without a data-driven approach to security, you are flying blind, hoping that your configurations are sufficient without any empirical evidence to back up that assumption.

Monitoring and reporting using Key Performance Indicators (KPIs) and metrics is the bridge between security policy and operational reality. When you define a metric, you are essentially defining what success looks like for your security program. Are your developers addressing vulnerabilities quickly? Are your access controls actually restrictive, or are they causing friction? By tracking these data points, you move from a reactive posture—where you scramble to fix breaches after they happen—to a proactive posture, where you identify trends, address weaknesses, and measure the effectiveness of your security controls over time.

This lesson explores how to extract, analyze, and report on security data within GitHub. We will cover the specific metrics that matter, how to pull this data using the GitHub API and CLI, and how to frame these reports for different stakeholders, from engineering managers to executive leadership.


Not read yet

Defining Your Security Metric Framework

Before diving into the technical implementation, it is vital to understand that not every data point is a metric. A metric must be actionable, repeatable, and aligned with your business objectives. If a metric does not help you make a decision or change a behavior, it is just noise.

The Four Pillars of GitHub Security Metrics

To build a comprehensive dashboard, we categorize security metrics into four logical pillars. This structure helps ensure that you aren't just measuring one aspect of security, such as vulnerabilities, while ignoring others, like access management or configuration drift.

  1. Vulnerability Management (The "How Fast" Metric): This focuses on the lifecycle of security flaws found in code or dependencies. It measures how quickly your teams identify and remediate risks.
  2. Access and Identity (The "Who Has Access" Metric): This tracks the distribution of permissions, the usage of personal access tokens (PATs), and the lifecycle of external collaborators.
  3. Compliance and Configuration (The "Is it Locked Down" Metric): This monitors the adherence to organization-wide policies, such as mandatory branch protection rules and the enforcement of two-factor authentication (2FA).
  4. Audit and Activity (The "What Happened" Metric): This captures the trail of events within the organization, helping you detect anomalous behavior or unauthorized changes to sensitive infrastructure.

Callout: Metric vs. KPI A metric is a quantitative measurement, such as "the number of open vulnerabilities." A Key Performance Indicator (KPI) is a metric that is tied to a specific business goal, such as "reduce the average time to remediate critical vulnerabilities to under 48 hours." While all KPIs are metrics, not all metrics are KPIs. Focus your reporting on KPIs when presenting to leadership.


Not read yet

Practical Implementation: Gathering Data from GitHub

GitHub provides multiple ways to extract data for your reports. Depending on the scale of your organization, you might use the GitHub UI, the CLI (gh), or the REST/GraphQL APIs. For automated reporting, the API is the gold standard.

Using the GitHub CLI for Quick Audits

The GitHub CLI is an excellent tool for ad-hoc security audits. If you need to quickly check the configuration of a specific repository or a list of users, the CLI allows you to pipe data into standard Linux tools like jq to parse and format the output.

For example, to list all repositories in an organization that do not have branch protection rules enabled, you might use a script like this:

# Example: List repos without branch protection
gh repo list my-org --limit 100 --json name,hasBranchProtection \
  | jq '.[] | select(.hasBranchProtection == false) | .name'

This simple command provides immediate visibility into which repositories might be vulnerable to unauthorized code changes. By automating these small checks, you build a baseline of "known good" configurations.

Leveraging the REST API for Comprehensive Reporting

For enterprise-level reporting, you need to pull data across the entire organization. The GitHub REST API allows you to pull audit logs, dependency alerts, and member lists systematically.

Note: When pulling large datasets, always use pagination. The GitHub API limits the number of results per request (usually 30 to 100 items). Failing to handle pagination will result in incomplete reports and skewed metrics.

Example: Extracting Repository Vulnerability Data

To calculate the "Mean Time to Remediate" (MTTR), you need to track when a vulnerability is opened and when it is closed. The following pseudo-code demonstrates the logic for fetching dependency alerts:

import requests

def get_vulnerability_data(org, token):
    headers = {'Authorization': f'token {token}'}
    url = f"https://api.github.com/orgs/{org}/dependabot/alerts"
    response = requests.get(url, headers=headers)
    
    # Process the data to calculate remediation time
    alerts = response.json()
    for alert in alerts:
        created_at = alert['created_at']
        fixed_at = alert.get('fixed_at')
        # Logic to calculate duration between these timestamps

By storing these timestamps in a database (like PostgreSQL or a dedicated SIEM), you can build time-series charts that show if your organization's security posture is improving or degrading over time.


Not read yet

Key Metrics to Track (Detailed Breakdown)

Let us dive deeper into the specific metrics you should be tracking and why they matter for your security posture.

1. Vulnerability Remediation Speed (MTTR)

This is arguably the most important metric for any software organization. It measures the time elapsed between the discovery of a vulnerability (e.g., via Dependabot) and the deployment of a fix.

  • How to calculate: (Time of Fix - Time of Discovery) / Total Number of Vulnerabilities.
  • Why it matters: High MTTR indicates that your developers are either overwhelmed by noise (false positives) or lack the resources to prioritize security patches.
  • Target: Aim for lower MTTR for "Critical" and "High" severity vulnerabilities.

2. Percentage of Repositories with Branch Protection

Branch protection is your first line of defense against malicious code injection. It ensures that no one can push directly to the main branch without a pull request and peer review.

  • How to calculate: (Repositories with Branch Protection / Total Repositories) * 100.
  • Why it matters: If this percentage is low, your organization is at high risk of accidental or intentional code corruption.
  • Target: 100% for all production-facing repositories.

3. Usage of Personal Access Tokens (PATs)

PATs are a common vector for credential theft. If a developer's machine is compromised, a long-lived PAT could grant an attacker permanent access to your organization.

  • How to track: Periodically audit the age of all PATs in your organization.
  • Why it matters: Old tokens are "zombie" credentials that are often forgotten by the owner.
  • Target: Zero tokens older than 90 days.

4. Secret Scanning Alerts per Repository

GitHub Secret Scanning helps prevent developers from accidentally pushing API keys or credentials to public or private repositories.

  • How to track: Count the number of secret scanning alerts generated per repository over a 30-day window.
  • Why it matters: A high number of alerts in a specific repository suggests that the developers working there may need additional security training or that their local environment is not properly configured to ignore secret files.

Not read yet

Comparison Table: Monitoring Methods

Method Best For Complexity Automation Potential
GitHub UI (Insights) High-level snapshots Low None
GitHub CLI Ad-hoc audits, local scripts Medium Moderate
REST/GraphQL API Enterprise reporting, SIEM integration High High
Audit Log Streaming Real-time threat detection Very High Very High

Best Practices for Security Reporting

Reporting is not just about the data; it is about communication. If your report is too dense or lacks context, it will be ignored by the very people who need to take action.

Keep it Contextual

Never report a metric without context. If you report "There are 50 open vulnerabilities," that number means nothing. Instead, report "There are 50 open vulnerabilities, which is a 10% decrease from last month, and 90% of these are low-risk." Always compare current data to historical trends.

Tailor the Message to the Audience

  • For Engineers: Provide granular data. Give them lists of specific repositories, file paths, and suggested fixes. They want to know "What do I need to fix right now?"
  • For Engineering Managers: Focus on trends and resource allocation. They want to know "Are our teams improving, and do they have the time to handle these security tasks?"
  • For Executives: Keep it high-level. Focus on risk reduction, compliance, and the "big picture" health of the organization. They want to know "Are we safe from a catastrophic breach?"

Automate the Delivery

Do not rely on manual spreadsheets. Use tools like Grafana, Datadog, or even simple GitHub Actions that generate a Markdown report and post it to a Slack channel or a dedicated repository. Automation ensures that the reports are consistent, unbiased, and always up to date.

Tip: Use GitHub "Security Advisories" to track your own internal security debt. By treating security issues as "technical debt," you can integrate them into your existing sprint planning and backlog grooming processes.


Not read yet

Common Pitfalls and How to Avoid Them

Even with the best intentions, security metrics programs often fail. Here are the most common traps and how to navigate them.

1. The "Vanity Metric" Trap

Many administrators track metrics that look impressive but mean nothing. For example, "Number of security scans run" is a vanity metric. Running a scan 1,000 times a day does not make you more secure if you aren't fixing the issues found. Focus on outcomes (e.g., vulnerabilities fixed) rather than activities (e.g., scans performed).

2. Ignoring False Positives

If your automated tools report hundreds of vulnerabilities, but 80% of them are false positives, your developers will eventually stop trusting the system. This is known as "alert fatigue." Invest time in tuning your tools and suppressing false positives so that the alerts you do send are actionable and high-signal.

3. Lack of Accountability

Data without ownership is useless. If you report a security issue, it must be clear who is responsible for fixing it. Use GitHub's CODEOWNERS file to ensure that every repository has an assigned team. When an alert triggers, GitHub will automatically notify the correct people, closing the loop between detection and remediation.

4. Over-Complicating the Dashboard

A dashboard with 50 different charts is overwhelming. Start small. Pick 3 to 5 key metrics that align with your current security goals. Once those are stable and driving action, you can slowly add more complexity.


Not read yet

Step-by-Step: Setting Up a Weekly Security Report

If you are just starting, follow this roadmap to build your first automated security reporting pipeline.

Step 1: Establish Your Baseline

Before you can measure improvement, you need to know where you stand. Run a full audit of your organization's security settings using the GitHub CLI or API. Document the number of:

  • Open critical/high vulnerabilities.
  • Repositories without branch protection.
  • Users without 2FA enabled.
  • External collaborators with write access.

Step 2: Configure Notifications

Use GitHub's built-in notification settings or create a custom Webhook to send security alerts to a central location. If you have an Enterprise account, use the "Security Overview" dashboard. If you are on a smaller plan, create a dedicated security repository where you log these findings as issues.

Step 3: Automate Data Collection

Create a GitHub Action that runs every Monday morning. This action should:

  1. Query the GitHub API for the metrics you defined in Step 1.
  2. Compare the results against your baseline.
  3. Generate a summary report.
  4. Send this report to a Slack channel or email list.

Step 4: Review and Iterate

Hold a monthly meeting with team leads to review the report. Ask:

  • "Why did this metric spike?"
  • "What blockers are preventing us from fixing these issues?"
  • "Do we need to adjust our security policies?"

By formalizing this feedback loop, you turn security from a "policing" activity into a collaborative, engineering-driven process.


Not read yet

Advanced Topic: Integrating with SIEM/SOAR

For larger organizations, GitHub metrics should be part of a broader security ecosystem. You can stream your GitHub audit logs directly into a SIEM (Security Information and Event Management) system like Splunk, ELK, or Microsoft Sentinel.

When you stream these logs, you can move beyond simple metrics and into Threat Hunting. For example, you can create alerts for:

  • A user adding a new SSH key from an unfamiliar IP address.
  • A user modifying sensitive branch protection rules.
  • Multiple failed attempts to access a repository.

By correlating GitHub audit events with other corporate logs (like VPN access or SSO logs), you can detect sophisticated attacks that would be invisible if you only looked at GitHub in isolation.

Callout: The Importance of Audit Logs Audit logs are the "black box" of your GitHub organization. They record every action—who did what and when. Without streaming these logs to a secure, external location, you are vulnerable to log tampering if an attacker gains administrative access to your GitHub organization. Always ensure your logs are immutable and stored in a separate, restricted environment.


Not read yet

Frequently Asked Questions (FAQ)

Q: How do I handle "alert fatigue" in my organization? A: Focus on severity levels. Configure your team's notification settings to only alert for "Critical" and "High" vulnerabilities. Use automated PRs (via Dependabot) to fix "Medium" and "Low" vulnerabilities without requiring human intervention whenever possible.

Q: Should I report security metrics to the entire company? A: Transparency is generally good, but be careful. Publicly shaming teams for having vulnerabilities can lead to defensive behavior. Instead, use the data to identify which teams need more training or better tooling. Frame it as "how can we help you succeed" rather than "why are you failing."

Q: What if our developers refuse to fix the vulnerabilities I report? A: This is a culture problem, not a technical one. You need to align security goals with engineering goals. Work with engineering leadership to ensure that a percentage of every sprint is dedicated to "security debt" and "maintenance." If security is not a part of the definition of "done," it will never be a priority.

Q: Can I use GitHub's built-in "Security Overview" instead of building my own? A: Yes, if you are using GitHub Enterprise. The built-in dashboard is excellent for high-level visibility. However, even with the built-in dashboard, you will likely still want to extract data via API for custom reporting that integrates with your company's specific business intelligence tools.


Not read yet

Conclusion: Key Takeaways

Monitoring and reporting are the foundation of a mature security administration program. By moving from manual checks to automated, data-driven insights, you empower your organization to manage risk effectively. Remember the following core principles:

  1. Measure What Matters: Focus on actionable KPIs that reflect your organization's security goals, such as MTTR, rather than vanity metrics like total scan counts.
  2. Context is King: Always present data with historical context and clear ownership so that stakeholders understand the "why" behind the numbers.
  3. Automate for Consistency: Use the GitHub API and GitHub Actions to collect and report data. Manual reporting is prone to error and rarely sustainable.
  4. Close the Feedback Loop: Establish regular review meetings to discuss metrics, identify blockers, and adjust your security strategy accordingly.
  5. Prioritize Actionability: If a metric does not lead to a decision or an improvement, stop tracking it. Keep your dashboard clean and focused on high-signal data.
  6. Integrate with Culture: Treat security debt like feature debt. Work with engineering teams to integrate security remediation into their standard development workflows.
  7. Secure Your Logs: Treat your audit logs as sensitive infrastructure. Stream them to a secure, external location to ensure you have a reliable record of events, even in the event of a platform-level compromise.

By implementing these practices, you transform your GitHub security administration from a reactive, manual burden into a proactive, transparent, and highly efficient operation. You are not just securing code; you are building a culture of security that scales with your organization.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.