This guide provides ready-to-use NRQL queries for common security monitoring and analysis scenarios. Copy these queries into the query builder or add them to custom dashboards to gain deeper insights into your vulnerability data.
For information about the underlying data structure, see Security data structure reference.
Executive reporting
Total open vulnerabilities by severity
Get a high-level view of your vulnerability exposure:
FROM VulnerabilitySELECT count(*) as 'Total Vulnerabilities'WHERE state = 'OPEN'FACET severitySINCE 1 day agoCritical and high severity trends
Track how critical vulnerabilities change over time:
FROM VulnerabilitySELECT count(*) as 'Critical & High Vulnerabilities'WHERE severity IN ('CRITICAL', 'HIGH')AND state = 'OPEN'TIMESERIES AUTOSINCE 30 days agoVulnerabilities by entity
Identify which applications or hosts have the most vulnerabilities:
FROM VulnerabilitySELECT count(*) as 'Vulnerability Count'WHERE state = 'OPEN'FACET entity.nameLIMIT 20SINCE 1 day agoVulnerability distribution across portfolio
Understand the spread of vulnerabilities:
FROM VulnerabilitySELECT percentage(count(*), WHERE severity = 'CRITICAL') as 'Critical %', percentage(count(*), WHERE severity = 'HIGH') as 'High %', percentage(count(*), WHERE severity = 'MEDIUM') as 'Medium %', percentage(count(*), WHERE severity = 'LOW') as 'Low %'WHERE state = 'OPEN'SINCE 1 day agoPrioritization and risk assessment
High-priority vulnerabilities
Find vulnerabilities with high exploit probability:
FROM VulnerabilitySELECT cveId, affectedPackage, affectedVersion, cvssScore, epssPercentileWHERE epssPercentile > 90AND state = 'OPEN'ORDER BY epssPercentile DESCLIMIT 50SINCE 7 days agoActive ransomware vulnerabilities
Identify vulnerabilities used in ransomware campaigns:
FROM VulnerabilitySELECT cveId, affectedPackage, cvssScore, entity.nameWHERE activeRansomware = trueAND state = 'OPEN'FACET cveId, entity.nameSINCE 30 days agoNewly detected critical vulnerabilities
Monitor for new critical findings:
FROM VulnerabilitySELECT cveId, affectedPackage, affectedVersion, entity.name, detectedAtWHERE severity = 'CRITICAL'AND state = 'OPEN'AND detectedAt > ago(24 hours)ORDER BY detectedAt DESCVulnerabilities requiring immediate attention
Combine multiple risk factors:
FROM VulnerabilitySELECT cveId, entity.name, affectedPackage, cvssScore, epssPercentileWHERE ( (severity = 'CRITICAL' AND epssPercentile > 85) OR (activeRansomware = true) OR (epssPercentile > 95))AND state = 'OPEN'FACET cveId, entity.nameSINCE 7 days agoExposure and remediation tracking
Average vulnerability exposure time
Calculate mean time to remediate (MTTR):
FROM VulnerabilitySELECT average((resolvedAt - detectedAt) / 86400) as 'Avg Days to Resolve'WHERE state = 'CLOSED'FACET severitySINCE 90 days agoLongest-running open vulnerabilities
Find vulnerabilities that have been open for extended periods:
FROM VulnerabilitySELECT cveId, entity.name, affectedPackage, detectedAt, (max(timestamp) - detectedAt) / 86400 as 'Days Open'WHERE state = 'OPEN'FACET cveId, entity.nameORDER BY 'Days Open' DESCLIMIT 20SINCE 90 days agoRemediation velocity
Track how quickly you're resolving vulnerabilities:
FROM VulnerabilitySELECT count(*) as 'Vulnerabilities Resolved'WHERE state = 'CLOSED'FACET weekOf(resolvedAt)SINCE 90 days agoTIMESERIES 1 weekVulnerabilities by age bucket
Group vulnerabilities by how long they've been open:
FROM VulnerabilitySELECT count(*) as 'Count'WHERE state = 'OPEN'FACET cases( WHERE (now() - detectedAt) / 86400 <= 7 as '0-7 days', WHERE (now() - detectedAt) / 86400 <= 30 as '8-30 days', WHERE (now() - detectedAt) / 86400 <= 90 as '31-90 days', WHERE (now() - detectedAt) / 86400 > 90 as '> 90 days')SINCE 180 days agoPackage and library analysis
Most vulnerable libraries
Identify libraries introducing the most vulnerabilities:
FROM VulnerabilitySELECT count(*) as 'Vulnerability Count'WHERE state = 'OPEN'FACET affectedPackageORDER BY count(*) DESCLIMIT 10SINCE 30 days agoLibraries requiring upgrades
Find packages with available fixes:
FROM VulnerabilitySELECT affectedPackage, affectedVersion, fixedVersion, count(*) as 'Vulnerable Entities'WHERE state = 'OPEN'AND fixedVersion IS NOT NULLFACET affectedPackage, affectedVersion, fixedVersionORDER BY count(*) DESCLIMIT 20SINCE 7 days agoVulnerability detection by source
Understand which integrations are finding vulnerabilities:
FROM VulnerabilitySELECT count(*) as 'Detections'FACET sourceSINCE 30 days agoJava dependencies analysis
Focus on Java-specific vulnerabilities:
FROM VulnerabilitySELECT count(*) as 'Vulnerabilities'WHERE affectedPackage LIKE '%.jar'OR affectedPackage LIKE '%maven%'FACET affectedPackage, severitySINCE 30 days agoEntity-specific queries
Application vulnerability summary
Get vulnerability counts for a specific application:
FROM VulnerabilitySELECT count(*) as 'Total', filter(count(*), WHERE severity = 'CRITICAL') as 'Critical', filter(count(*), WHERE severity = 'HIGH') as 'High', filter(count(*), WHERE severity = 'MEDIUM') as 'Medium', filter(count(*), WHERE severity = 'LOW') as 'Low'WHERE entity.name = 'YOUR_APP_NAME'AND state = 'OPEN'SINCE 1 day agoHost vulnerability breakdown
Analyze vulnerabilities for infrastructure hosts:
FROM VulnerabilitySELECT count(*) as 'Vulnerabilities'WHERE entityType = 'HOST'AND state = 'OPEN'FACET entity.name, severityLIMIT 50SINCE 7 days agoEntities with no recent scans
Identify entities that may not be reporting vulnerability data:
FROM VulnerabilitySELECT entity.name, max(timestamp) as 'Last Scan'FACET entity.nameHAVING max(timestamp) < ago(7 days)SINCE 30 days agoCompliance and reporting
Vulnerabilities older than 30 days (SLA tracking)
Monitor vulnerabilities exceeding your remediation SLA:
FROM VulnerabilitySELECT count(*) as 'Overdue Vulnerabilities', entity.name, severityWHERE state = 'OPEN'AND detectedAt < ago(30 days)FACET entity.name, severitySINCE 180 days agoCritical vulnerability response time
Track how quickly critical vulnerabilities are addressed:
FROM VulnerabilitySELECT percentile((resolvedAt - detectedAt) / 86400, 50, 75, 90, 95) as 'Days to Resolve'WHERE severity = 'CRITICAL'AND state = 'CLOSED'SINCE 90 days agoMonthly vulnerability metrics
Generate monthly reports:
FROM VulnerabilitySELECT count(*) as 'Total Detected', uniqueCount(entity.guid) as 'Affected Entities', filter(count(*), WHERE severity IN ('CRITICAL', 'HIGH')) as 'High Risk'FACET monthOf(detectedAt)SINCE 180 days agoTIMESERIES 1 monthAdvanced analysis
Vulnerability blast radius
Identify vulnerabilities affecting many entities:
FROM VulnerabilitySELECT cveId, count(entity.guid) as 'Affected Entities', max(cvssScore) as 'CVSS'WHERE state = 'OPEN'FACET cveIdHAVING count(entity.guid) > 5ORDER BY count(entity.guid) DESCLIMIT 20SINCE 30 days agoSecurity hygiene score
Calculate a custom security score:
FROM VulnerabilitySELECT 100 - ( filter(count(*), WHERE severity = 'CRITICAL') * 10 + filter(count(*), WHERE severity = 'HIGH') * 5 + filter(count(*), WHERE severity = 'MEDIUM') * 2 + filter(count(*), WHERE severity = 'LOW') * 0.5) as 'Security Score'WHERE state = 'OPEN'FACET entity.nameSINCE 1 day agoVulnerability trends by type
Compare application vs infrastructure vulnerabilities:
FROM VulnerabilitySELECT count(*) as 'Vulnerabilities'WHERE state = 'OPEN'FACET entityTypeTIMESERIES AUTOSINCE 30 days agoUsing these queries
In the query builder
- Go to one.newrelic.com > All capabilities > Query your data
- Copy and paste any query from this page
- Click Run to see results
- Adjust time ranges and filters as needed
In custom dashboards
- Create a new dashboard or edit an existing one
- Add a widget and select Query builder
- Paste the query and configure visualization
- Save the widget to your dashboard
In alerts
- Go to Alerts > Create a condition
- Select NRQL query as the condition type
- Use queries that return counts or thresholds
- Configure alert thresholds and notification channels
For more information on alerting, see Set up vulnerability alerts.
Tips for customizing queries
Replace placeholders
'YOUR_APP_NAME'- Replace with your actual application name'YOUR_ENTITY_GUID'- Replace with your entity's GUID- Time ranges (e.g.,
SINCE 30 days ago) - Adjust to your needs
Combine with other data
Join vulnerability data with APM or Infrastructure metrics:
FROM Vulnerability, TransactionSELECT count(Vulnerability.cveId), average(Transaction.duration)WHERE Vulnerability.entity.guid = Transaction.appIdAND Vulnerability.state = 'OPEN'FACET Vulnerability.entity.nameSINCE 1 day agoExport results
All query results can be:
- Downloaded as CSV
- Added to dashboards
- Exported via API
- Shared with your team