This is an automated email from the ASF dual-hosted git repository.

janhoy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new b771587e970 SOLR-18535: Prometheus alert rules for Solr (#5236)
b771587e970 is described below

commit b771587e9707c49847d728fd1f3ff259a182692c
Author: Jan Høydahl <[email protected]>
AuthorDate: Sat Nov 7 00:33:39 2026 +0100

    SOLR-18535: Prometheus alert rules for Solr (#5236)
---
 changelog/unreleased/SOLR-18535-alert-rules.yml    |  13 +
 solr/monitoring/README.md                          |  43 +++-
 solr/monitoring/mixin/Makefile                     |   9 +-
 solr/monitoring/mixin/alerts/alerts.libsonnet      | 262 ++++++++++++++++++++-
 solr/monitoring/mixin/config.libsonnet             |  42 ++++
 solr/monitoring/mixin/make.sh                      |   2 +-
 solr/monitoring/mixin/tests/alerts_test.yml        | 204 ++++++++++++++++
 solr/monitoring/prometheus-solr-alerts.yml         | 156 +++++++++++-
 .../monitoring-with-prometheus-and-grafana.adoc    |  32 +--
 9 files changed, 720 insertions(+), 43 deletions(-)

diff --git a/changelog/unreleased/SOLR-18535-alert-rules.yml 
b/changelog/unreleased/SOLR-18535-alert-rules.yml
new file mode 100644
index 00000000000..1b4850c45f1
--- /dev/null
+++ b/changelog/unreleased/SOLR-18535-alert-rules.yml
@@ -0,0 +1,13 @@
+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
+
+title: >
+  Solr now ships Prometheus alert rules in 
`solr/monitoring/prometheus-solr-alerts.yml`, covering
+  heap usage, GC time, disk space, unreachable nodes, search latency, request 
error rate, Overseer
+  queue buildup and index-to-memory ratio. The reference guide lists the rules 
and their thresholds.
+type: added
+authors:
+  - name: Jan Høydahl
+    url: https://home.apache.org/phonebook.html?uid=janhoy
+links:
+  - name: SOLR-18535
+    url: https://issues.apache.org/jira/browse/SOLR-18535
diff --git a/solr/monitoring/README.md b/solr/monitoring/README.md
index b7131b0a997..a9cf43b0ced 100644
--- a/solr/monitoring/README.md
+++ b/solr/monitoring/README.md
@@ -32,11 +32,9 @@ or testing.
 | `mixin/` | Jsonnet source (single source of truth used to regenerate the 
artifacts above) |
 | `dev/` | **Developer convenience only** — docker-compose stack for testing 
changes to the artifacts |
 
-> **Both artifacts are placeholders right now** — a two-panel dashboard and a 
single alert, which
-> exist to prove the build pipeline works end to end. The real dashboard 
arrives in
-> [SOLR-18534](https://issues.apache.org/jira/browse/SOLR-18534), the alert 
rules in
-> [SOLR-18535](https://issues.apache.org/jira/browse/SOLR-18535), and OTLP 
push support in
-> [SOLR-18536](https://issues.apache.org/jira/browse/SOLR-18536).
+> **The dashboard is still a placeholder**, enough to exercise the build 
pipeline. The real one
+> arrives in [SOLR-18534](https://issues.apache.org/jira/browse/SOLR-18534) 
and OTLP push support
+> in [SOLR-18536](https://issues.apache.org/jira/browse/SOLR-18536). The alert 
rules are complete.
 
 For the full integration guide see the Solr Reference Guide:
 **[Monitoring Solr with Prometheus and 
Grafana](../solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc)**
@@ -71,8 +69,28 @@ Validate locally before deploying:
 promtool check rules prometheus-solr-alerts.yml
 ```
 
-One placeholder rule is included: `SolrNodeDown`, which fires when a Solr 
target has failed to
-scrape for 2 minutes.
+The rules live in the group `SolrAlerts`. Every expression carries 
`solrSelector` and aggregates
+`by (instance)`, so a rule alerts and recovers per node:
+
+| Alert | Severity | Fires when | Setting |
+|---|---|---|---|
+| `SolrHighHeapUsage` | critical | `jvm_memory_used_bytes` / 
`jvm_memory_committed_bytes` (heap, summed over pools) above 90% for 2m | 
`heapUsageThreshold` |
+| `SolrJvmGcThrashing` | critical | `rate(jvm_gc_duration_seconds_sum)` over 
10 s/min for 3m | `gcSecondsPerMinuteThreshold` |
+| `SolrLowDiskSpace` | critical | `solr_disk_space_megabytes` usable/total 
under 15% for 5m | `diskFreeThreshold` |
+| `SolrNodeDown` | warning | Scrape failing, or no metrics for 5m, for 5m | 
`nodeDownFor`, `nodeReportingWindow`, `nodeReportingLookback` |
+| `SolrHighSearchLatency` | warning | p99 of 
`solr_core_requests_times_milliseconds` for `/select*`, `internal="false"`, 
above 1000 ms for 5m | `searchLatencyThresholdMs` |
+| `SolrHighErrorRate` | warning | `solr_core_requests_errors_total` / 
`solr_core_requests_total` over 1% for 5m | `errorRateThreshold` |
+| `SolrOverseerQueueBuildup` | warning | 
`solr_overseer_collection_work_queue_size` over 50 for 5m (SolrCloud only) | 
`overseerQueueThreshold` |
+| `SolrHighMmapRatio` | warning | Index size against `jvm_system_memory_bytes` 
minus committed heap, under 10% for 5m | `mmapRatioThreshold` |
+
+`rateInterval` sets the window for the `rate()` queries in the GC, latency and 
error-rate rules.
+
+Two details the expressions depend on. Heap is measured against committed 
rather than
+`jvm_memory_limit_bytes`, because generational ZGC reports the whole `-Xmx` as 
the limit of both its
+young and old pool; committed is a partition of one heap under every 
collector, and `bin/solr` pins
+`-Xms` to `-Xmx`. The request counters and the latency histogram carry 
`core!=""`, because a handler
+with `aggregateNodeLevelMetricsEnabled` emits a node rollup under the same 
metric name, without the
+`core`, `collection` and `shard` attributes.
 
 ---
 
@@ -85,6 +103,7 @@ All tunable settings live in `mixin/config.libsonnet`:
   _config:: {
     solrSelector: 'job="solr"',   // label selector identifying Solr targets
     rateInterval: '5m',           // window for rate() queries
+    // ... one threshold per alert rule, see the table above
   },
 }
 ```
@@ -130,7 +149,7 @@ Install the required tools once:
 | `jsonnet` (go-jsonnet) | Evaluate jsonnet source | `brew install go-jsonnet` 
or `go install github.com/google/go-jsonnet/cmd/jsonnet@latest` |
 | `jb` (jsonnet-bundler) | Manage dependencies | `brew install 
jsonnet-bundler` or `go install 
github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest` |
 | `gojsontoyaml` | Convert JSON→YAML for alert rules | `go install 
github.com/brancz/gojsontoyaml@latest` |
-| `promtool` *(optional)* | Validate alert rules | `brew install prometheus` |
+| `promtool` *(optional)* | Validate and unit-test alert rules | `brew install 
prometheus` |
 
 Then build:
 
@@ -153,7 +172,8 @@ Both `./make.sh <target>` and `make <target>` accept the 
same targets:
 | `dashboards` | Regenerate `grafana-solr-dashboard.json` |
 | `alerts` | Regenerate `prometheus-solr-alerts.yml` |
 | `all` | Regenerate both outputs |
-| `check` | Run `promtool check rules` on alert rules |
+| `test` | Run the alert rule unit tests in `mixin/tests/` with `promtool test 
rules` |
+| `check` | Run `promtool check rules` on alert rules, then the unit tests |
 | `fmt` | Auto-format all `.libsonnet` source files |
 
 `vendor/` is not checked in; `jsonnetfile.lock.json` pins the exact grafonnet 
revision, so
@@ -162,6 +182,11 @@ Both `./make.sh <target>` and `make <target>` accept the 
same targets:
 **Commit the regenerated artifacts together with the jsonnet change that 
produced them** —
 nothing in the Gradle build regenerates or verifies them.
 
+`mixin/tests/` holds `promtool test rules` cases that feed synthetic series to 
the generated rules.
+They pin the metric properties the expressions depend on — a ZGC heap 
reporting `-Xmx` as the limit
+of two pools, a ParallelGC heap partitioned across three, a node rollup 
sharing a core metric name,
+and the MiB units of the index-size gauge — so run `make test` after editing 
`alerts/`.
+
 ---
 
 ## Developer Convenience Stack
diff --git a/solr/monitoring/mixin/Makefile b/solr/monitoring/mixin/Makefile
index a764b38eaa7..cf43ef90617 100644
--- a/solr/monitoring/mixin/Makefile
+++ b/solr/monitoring/mixin/Makefile
@@ -42,7 +42,7 @@ require_vendor = @test -d vendor || { \
          echo "ERROR: vendor/ is missing — run 'make install' (or ./make.sh 
install) first." >&2; \
          exit 1; }
 
-.PHONY: all dashboards alerts install check fmt clean
+.PHONY: all dashboards alerts install check test fmt clean
 
 all: dashboards alerts
 
@@ -71,11 +71,16 @@ alerts:
        mv $(ALERTS_OUT).tmp $(ALERTS_OUT)
        @echo "→ Generated $(ALERTS_OUT)"
 
-check:
+check: test
        $(call require_tool,$(PROMTOOL))
        $(PROMTOOL) check rules $(ALERTS_OUT)
        @echo "→ Alert rules validated OK"
 
+test:
+       $(call require_tool,$(PROMTOOL))
+       $(PROMTOOL) test rules tests/*.yml
+       @echo "→ Alert rule unit tests passed"
+
 fmt:
        $(call require_tool,$(JSONNETFMT))
        find . -path ./vendor -prune -o -name '*.libsonnet' -exec $(JSONNETFMT) 
$(FMT_FLAGS) -i {} \;
diff --git a/solr/monitoring/mixin/alerts/alerts.libsonnet 
b/solr/monitoring/mixin/alerts/alerts.libsonnet
index 93dad7f5fa2..2894dc6ce34 100644
--- a/solr/monitoring/mixin/alerts/alerts.libsonnet
+++ b/solr/monitoring/mixin/alerts/alerts.libsonnet
@@ -13,11 +13,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// alerts.libsonnet — placeholder alert rule.
+// alerts.libsonnet — Prometheus alert rules for Solr, in the group 
"SolrAlerts".
 //
-// One rule, enough to show that the mixin build produces a file promtool
-// accepts and Prometheus loads. The real rule set replaces this wholesale;
-// see SOLR-18535.
+// Every expression carries cfg.solrSelector, so that metrics from other Java
+// services are never read as Solr's, and aggregates by instance, so that each
+// node alerts and recovers on its own. Thresholds live in config.libsonnet.
 //
 // The rules are built from the configuration of the merged mixin root
 // ($._config), not from a direct import, so that callers can override settings
@@ -26,21 +26,261 @@
 local alertsFor(cfg) = {
   groups: [
     {
-      name: 'SolrExampleAlerts',
+      name: 'SolrAlerts',
       rules: [
+
+        // Committed, not jvm_memory_limit_bytes: generational ZGC reports the
+        // whole -Xmx as the limit of both its young and old pool, so summing
+        // limits doubles the heap and the rule never fires. Committed is 
always
+        // a partition of one heap, whatever the collector, and bin/solr pins
+        // -Xms to -Xmx, so committed is the maximum heap on a Solr node. Where
+        // the two differ, this reads as "how full is the heap as sized now".
+        // The inner max collapses pools reported by more than one OTel scope,
+        // which differ by Solr version.
         {
-          alert: 'SolrNodeDown',
-          expr: 'up{%s} == 0' % cfg.solrSelector,
+          alert: 'SolrHighHeapUsage',
+          expr: |||
+            sum by (instance) (
+              max by (instance, jvm_memory_pool_name) (
+                jvm_memory_used_bytes{%(solrSelector)s,jvm_memory_type="heap"}
+              )
+            )
+            /
+            sum by (instance) (
+              max by (instance, jvm_memory_pool_name) (
+                
jvm_memory_committed_bytes{%(solrSelector)s,jvm_memory_type="heap"}
+              )
+            )
+            > %(threshold)g
+          ||| % { threshold: cfg.heapUsageThreshold, solrSelector: 
cfg.solrSelector },
           'for': '2m',
+          labels: { severity: 'critical' },
+          annotations: {
+            summary: 'Solr node {{ $labels.instance }} has high JVM heap 
usage',
+            description: |||
+              Node {{ $labels.instance }} is using {{ $value | 
humanizePercentage }} of its JVM
+              heap (threshold: %(threshold)s%%). Raise -Xmx, or reduce cache 
sizes.
+            ||| % { threshold: std.floor(cfg.heapUsageThreshold * 100) },
+          },
+        },
+
+        // Scaled from per-second to per-minute so the threshold reads in the
+        // unit operators think in. Inner max dedupes scopes as above.
+        {
+          alert: 'SolrJvmGcThrashing',
+          expr: |||
+            sum by (instance) (
+              max by (instance, jvm_gc_name, jvm_gc_action) (
+                
rate(jvm_gc_duration_seconds_sum{%(solrSelector)s}[%(rateInterval)s])
+              )
+            ) * 60
+            > %(threshold)s
+          ||| % {
+            threshold: cfg.gcSecondsPerMinuteThreshold,
+            solrSelector: cfg.solrSelector,
+            rateInterval: cfg.rateInterval,
+          },
+          'for': '3m',
+          labels: { severity: 'critical' },
+          annotations: {
+            summary: 'Solr node {{ $labels.instance }} is spending much of its 
time in GC',
+            description: |||
+              Node {{ $labels.instance }} spends {{ $value | humanize }} 
seconds per minute in
+              garbage collection (threshold: %(threshold)s). Pauses show up as 
search latency;
+              check heap usage first, then heap sizing and GC settings.
+            ||| % { threshold: cfg.gcSecondsPerMinuteThreshold },
+          },
+        },
+
+        // Node-level metric: the partition holding the Solr home directory.
+        {
+          alert: 'SolrLowDiskSpace',
+          expr: |||
+            min by (instance) 
(solr_disk_space_megabytes{%(solrSelector)s,type="usable_space"})
+            /
+            min by (instance) 
(solr_disk_space_megabytes{%(solrSelector)s,type="total_space"})
+            < %(threshold)g
+          ||| % { threshold: cfg.diskFreeThreshold, solrSelector: 
cfg.solrSelector },
+          'for': '5m',
+          labels: { severity: 'critical' },
+          annotations: {
+            summary: 'Solr node {{ $labels.instance }} is low on disk space',
+            description: |||
+              Node {{ $labels.instance }} has {{ $value | humanizePercentage 
}} of its disk free
+              (threshold: %(threshold)s%%). Indexing fails once the disk 
fills, and a merge needs
+              room for the segments it rewrites.
+            ||| % { threshold: std.floor(cfg.diskFreeThreshold * 100) },
+          },
+        },
+
+        // Covers a node that is down, one that is unreachable, and one with
+        // metrics collection switched off — every rule above goes blind.
+        //
+        // Two branches, because 'up' only describes what Prometheus scrapes.
+        // Where Solr pushes over OTLP, the scrape target is the collector, and
+        // it stays up while every node behind it dies; what stops is the data.
+        // The second branch therefore alerts on a node that reported within
+        // the lookback but has sent nothing for the window. It also covers a
+        // scraped node that drops out of service discovery, which 'up' cannot
+        // report either because the target stops existing.
+        //
+        // max_over_time, not offset: it keeps a node visible on the left after
+        // its series has gone stale, which is exactly the state being 
detected.
+        // The aggregations are what drop __name__, so both branches carry the
+        // same label set and 'or' deduplicates them rather than raising two
+        // alerts for one node.
+        {
+          alert: 'SolrNodeDown',
+          expr: |||
+            max by (job, instance) (up{%(solrSelector)s} == 0)
+            or
+            (
+              count by (job, instance) (
+                
max_over_time(solr_cores_loaded{%(solrSelector)s}[%(lookback)s])
+              )
+              unless
+              count by (job, instance) (
+                max_over_time(solr_cores_loaded{%(solrSelector)s}[%(window)s])
+              )
+            )
+          ||| % {
+            solrSelector: cfg.solrSelector,
+            lookback: cfg.nodeReportingLookback,
+            window: cfg.nodeReportingWindow,
+          },
+          'for': cfg.nodeDownFor,
+          labels: { severity: 'warning' },
+          annotations: {
+            summary: 'Solr node {{ $labels.instance }} is down or has stopped 
reporting',
+            description: |||
+              {{ $labels.instance }} is failing scrapes, or has sent no 
metrics for
+              %(window)s. Either the node is down, its metrics endpoint is 
unreachable, or
+              metrics collection is switched off. Where metrics arrive through 
an
+              OpenTelemetry collector, the label names the collector rather 
than the node
+              unless Solr sends service.instance.id.
+            ||| % { window: cfg.nodeReportingWindow },
+          },
+        },
+
+        // internal="false" drops the shard requests a distributed search fans
+        // out, which would otherwise be counted alongside the request that
+        // issued them. core!="" drops the node rollup that a handler with
+        // aggregateNodeLevelMetricsEnabled emits under this same metric name,
+        // which would weight the quantile towards the cores that enable it.
+        {
+          alert: 'SolrHighSearchLatency',
+          expr: |||
+            histogram_quantile(0.99,
+              sum by (le, instance) (
+                rate(
+                  
solr_core_requests_times_milliseconds_bucket{%(solrSelector)s,handler=~"/select.*",internal="false",core!=""}[%(rateInterval)s]
+                )
+              )
+            )
+            > %(threshold)s
+          ||| % {
+            threshold: cfg.searchLatencyThresholdMs,
+            solrSelector: cfg.solrSelector,
+            rateInterval: cfg.rateInterval,
+          },
+          'for': '5m',
+          labels: { severity: 'warning' },
+          annotations: {
+            summary: 'Solr node {{ $labels.instance }} has high search 
latency',
+            description: |||
+              Node {{ $labels.instance }} answers 99%% of searches in {{ 
$value | humanize }}ms
+              (threshold: %(threshold)sms). Usual causes are expensive queries 
or faceting, caches
+              too small for the working set, and GC pauses.
+            ||| % { threshold: cfg.searchLatencyThresholdMs },
+          },
+        },
+
+        // Counts client (4xx) and server (5xx) failures alike; add
+        // source="server" to the errors selector to ignore malformed requests.
+        // core!="" drops the node rollups, as in the latency rule above.
+        {
+          alert: 'SolrHighErrorRate',
+          expr: |||
+            sum by (instance) 
(rate(solr_core_requests_errors_total{%(solrSelector)s,core!=""}[%(rateInterval)s]))
+            /
+            sum by (instance) 
(rate(solr_core_requests_total{%(solrSelector)s,core!=""}[%(rateInterval)s]))
+            > %(threshold)g
+          ||| % {
+            threshold: cfg.errorRateThreshold,
+            solrSelector: cfg.solrSelector,
+            rateInterval: cfg.rateInterval,
+          },
+          'for': '5m',
           labels: { severity: 'warning' },
           annotations: {
-            summary: 'Solr node {{ $labels.instance }} is not responding to 
scrapes',
+            summary: 'Solr node {{ $labels.instance }} has a high request 
error rate',
             description: |||
-              Prometheus has failed to scrape {{ $labels.instance }} for 2 
minutes.
-              Either the node is down or its metrics endpoint is unreachable.
-            |||,
+              {{ $value | humanizePercentage }} of requests to {{ 
$labels.instance }} are failing
+              (threshold: %(threshold)s%%). The Solr log carries the cause: 
invalid queries,
+              missing fields, cores that failed to load, or connectivity 
problems.
+            ||| % { threshold: std.floor(cfg.errorRateThreshold * 100) },
           },
         },
+
+        // SolrCloud only; silent on a standalone node.
+        {
+          alert: 'SolrOverseerQueueBuildup',
+          expr: |||
+            max by (instance) 
(solr_overseer_collection_work_queue_size{%(solrSelector)s})
+            > %(threshold)s
+          ||| % { threshold: cfg.overseerQueueThreshold, solrSelector: 
cfg.solrSelector },
+          'for': '5m',
+          labels: { severity: 'warning' },
+          annotations: {
+            summary: 'Solr Overseer collection work queue is building up on {{ 
$labels.instance }}',
+            description: |||
+              {{ $value }} collection operations are queued on {{ 
$labels.instance }}
+              (threshold: %(threshold)s). The Overseer is falling behind: look 
for long-running
+              collection operations, a disrupted election, or slow ZooKeeper.
+            ||| % { threshold: cfg.overseerQueueThreshold },
+          },
+        },
+
+        // How much of the index fits in the memory left for the page cache.
+        // Committed heap is what is actually denied to the page cache, and
+        // MetricUtils.bytesToMegabytes() divides by 1024^2, so the physical
+        // memory is converted the same way before the two are compared.
+        // The trailing guard keeps the rule silent when 
jvm_system_memory_bytes
+        // is missing or zero, which would make available memory look negative.
+        {
+          alert: 'SolrHighMmapRatio',
+          expr: |||
+            (
+              clamp_max(
+                (
+                  max by (instance) 
(jvm_system_memory_bytes{%(solrSelector)s,state="total"})
+                  - sum by (instance) (
+                    max by (instance, jvm_memory_pool_name) (
+                      
jvm_memory_committed_bytes{%(solrSelector)s,jvm_memory_type="heap"}
+                    )
+                  )
+                )
+                / (1024 * 1024)
+                / sum by (instance) 
(solr_core_index_size_megabytes{%(solrSelector)s})
+                * 100,
+                100
+              ) < %(threshold)s
+            )
+            and on (instance)
+              max by (instance) 
(jvm_system_memory_bytes{%(solrSelector)s,state="total"}) > 0
+          ||| % { threshold: cfg.mmapRatioThreshold, solrSelector: 
cfg.solrSelector },
+          'for': '5m',
+          labels: { severity: 'warning' },
+          annotations: {
+            summary: 'Little of the Solr index fits in memory on {{ 
$labels.instance }}',
+            description: |||
+              Only {{ $value | humanize }}%% of the index on {{ 
$labels.instance }} fits in the
+              memory left outside the JVM heap (threshold: %(threshold)s%%). 
The rest is read from
+              disk on every search that touches it.
+            ||| % { threshold: cfg.mmapRatioThreshold },
+          },
+        },
+
       ],
     },
   ],
diff --git a/solr/monitoring/mixin/config.libsonnet 
b/solr/monitoring/mixin/config.libsonnet
index 342948d14dd..88378c60ae8 100644
--- a/solr/monitoring/mixin/config.libsonnet
+++ b/solr/monitoring/mixin/config.libsonnet
@@ -31,5 +31,47 @@
     // Window for rate() queries, and the preselected value of the dashboard's
     // Interval dropdown. Raise it for sparse scrape intervals.
     rateInterval: '5m',
+
+    // Alert thresholds. Each is consumed by exactly one rule in alerts/.
+
+    // Fraction of the committed heap in use that fires SolrHighHeapUsage.
+    // bin/solr pins -Xms to -Xmx, so that is the maximum heap; where they
+    // differ, the rule measures the heap as currently sized.
+    heapUsageThreshold: 0.9,
+
+    // Seconds of garbage collection per minute that fire SolrJvmGcThrashing.
+    gcSecondsPerMinuteThreshold: 10,
+
+    // Fraction of the partition still free that fires SolrLowDiskSpace.
+    diskFreeThreshold: 0.15,
+
+    // 99th percentile /select latency in milliseconds that fires
+    // SolrHighSearchLatency.
+    searchLatencyThresholdMs: 1000,
+
+    // Fraction of requests failing that fires SolrHighErrorRate.
+    errorRateThreshold: 0.01,
+
+    // Pending Overseer collection operations that fire
+    // SolrOverseerQueueBuildup.
+    overseerQueueThreshold: 50,
+
+    // Percentage of the index that still fits in memory outside the heap,
+    // below which SolrHighMmapRatio fires.
+    mmapRatioThreshold: 10,
+
+    // How long a node may send no metrics before SolrNodeDown treats it as
+    // gone. Must comfortably exceed the scrape interval, or the OTLP push
+    // interval where metrics are pushed through a collector.
+    nodeReportingWindow: '5m',
+
+    // How far back SolrNodeDown looks to decide that a node ever existed, and
+    // so for how long it keeps firing for a node that never comes back. A node
+    // absent for longer than this is taken to be decommissioned.
+    nodeReportingLookback: '1h',
+
+    // How long SolrNodeDown must hold before it fires, on top of the detection
+    // above. Lower it to be told sooner, raise it to ride out longer restarts.
+    nodeDownFor: '5m',
   },
 }
diff --git a/solr/monitoring/mixin/make.sh b/solr/monitoring/mixin/make.sh
index 7392e564da7..0c00fcde789 100755
--- a/solr/monitoring/mixin/make.sh
+++ b/solr/monitoring/mixin/make.sh
@@ -19,7 +19,7 @@
 # Usage:
 #   ./make.sh              # equivalent to: make all
 #   ./make.sh install all  # equivalent to: make install all
-#   ./make.sh check        # equivalent to: make check
+#   ./make.sh check        # equivalent to: make check (validates and 
unit-tests rules)
 #   ./make.sh --rebuild    # force-rebuild the Docker image, then make all
 #
 # The Docker image (solr-mixin-make:latest) is built automatically on first
diff --git a/solr/monitoring/mixin/tests/alerts_test.yml 
b/solr/monitoring/mixin/tests/alerts_test.yml
new file mode 100644
index 00000000000..a44b6cdfc6d
--- /dev/null
+++ b/solr/monitoring/mixin/tests/alerts_test.yml
@@ -0,0 +1,204 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Unit tests for the generated alert rules: promtool test rules tests/*.yml
+# (make test). Each case pins a property of the metrics the rules read, so
+# that a rewritten expression cannot quietly lose it.
+
+rule_files:
+  - ../../prometheus-solr-alerts.yml
+
+evaluation_interval: 1m
+
+tests:
+  # Generational ZGC reports the whole -Xmx as the limit of both its young and
+  # old pool. Summing those limits doubles the denominator and caps the ratio 
at
+  # 50%, so a heap at 95% must still alert with both limit series present.
+  - interval: 1m
+    name: heap usage under generational ZGC
+    input_series:
+      - series: 
'jvm_memory_used_bytes{job="solr",instance="zgc:8983",jvm_memory_type="heap",jvm_memory_pool_name="ZGC
 Young Generation"}'
+        values: '500000000+0x10'
+      - series: 
'jvm_memory_used_bytes{job="solr",instance="zgc:8983",jvm_memory_type="heap",jvm_memory_pool_name="ZGC
 Old Generation"}'
+        values: '10000000+0x10'
+      - series: 
'jvm_memory_committed_bytes{job="solr",instance="zgc:8983",jvm_memory_type="heap",jvm_memory_pool_name="ZGC
 Young Generation"}'
+        values: '536870912+0x10'
+      - series: 
'jvm_memory_committed_bytes{job="solr",instance="zgc:8983",jvm_memory_type="heap",jvm_memory_pool_name="ZGC
 Old Generation"}'
+        values: '0+0x10'
+      - series: 
'jvm_memory_limit_bytes{job="solr",instance="zgc:8983",jvm_memory_type="heap",jvm_memory_pool_name="ZGC
 Young Generation"}'
+        values: '536870912+0x10'
+      - series: 
'jvm_memory_limit_bytes{job="solr",instance="zgc:8983",jvm_memory_type="heap",jvm_memory_pool_name="ZGC
 Old Generation"}'
+        values: '536870912+0x10'
+    alert_rule_test:
+      - eval_time: 5m
+        alertname: SolrHighHeapUsage
+        exp_alerts:
+          - exp_labels:
+              severity: critical
+              instance: zgc:8983
+            exp_annotations:
+              summary: 'Solr node zgc:8983 has high JVM heap usage'
+              description: |
+                Node zgc:8983 is using 94.99% of its JVM
+                heap (threshold: 90%). Raise -Xmx, or reduce cache sizes.
+
+  # ParallelGC partitions the heap across three pools, each reporting its own
+  # share as both limit and committed. Taking the largest pool as the whole 
heap
+  # would read this 69% heap as 98% and alert.
+  - interval: 1m
+    name: heap usage under ParallelGC
+    input_series:
+      - series: 
'jvm_memory_used_bytes{job="solr",instance="parallel:8983",jvm_memory_type="heap",jvm_memory_pool_name="PS
 Eden Space"}'
+        values: '100000000+0x10'
+      - series: 
'jvm_memory_used_bytes{job="solr",instance="parallel:8983",jvm_memory_type="heap",jvm_memory_pool_name="PS
 Survivor Space"}'
+        values: '0+0x10'
+      - series: 
'jvm_memory_used_bytes{job="solr",instance="parallel:8983",jvm_memory_type="heap",jvm_memory_pool_name="PS
 Old Gen"}'
+        values: '250000000+0x10'
+      - series: 
'jvm_memory_committed_bytes{job="solr",instance="parallel:8983",jvm_memory_type="heap",jvm_memory_pool_name="PS
 Eden Space"}'
+        values: '134742016+0x10'
+      - series: 
'jvm_memory_committed_bytes{job="solr",instance="parallel:8983",jvm_memory_type="heap",jvm_memory_pool_name="PS
 Survivor Space"}'
+        values: '15728640+0x10'
+      - series: 
'jvm_memory_committed_bytes{job="solr",instance="parallel:8983",jvm_memory_type="heap",jvm_memory_pool_name="PS
 Old Gen"}'
+        values: '358088704+0x10'
+    alert_rule_test:
+      - eval_time: 5m
+        alertname: SolrHighHeapUsage
+        exp_alerts: []
+
+  # A handler with aggregateNodeLevelMetricsEnabled emits a node rollup under 
the
+  # same metric name, without the core attribute. Counting it would read this
+  # node's 0.8% error rate as 1.14% and alert.
+  - interval: 1m
+    name: error rate ignores node rollups
+    input_series:
+      - series: 
'solr_core_requests_total{job="solr",instance="solr1:8983",category="QUERY",collection="c",shard="shard1",core="c_shard1_replica_n1",handler="/select",internal="false"}'
+        values: '0+40x20'
+      - series: 
'solr_core_requests_total{job="solr",instance="solr1:8983",category="UPDATE",collection="c",shard="shard1",core="c_shard1_replica_n1",handler="/update"}'
+        values: '0+60x20'
+      - series: 
'solr_core_requests_errors_total{job="solr",instance="solr1:8983",category="QUERY",collection="c",shard="shard1",core="c_shard1_replica_n1",handler="/select",internal="false",source="client"}'
+        values: '0+0.8x20'
+      - series: 
'solr_core_requests_total{job="solr",instance="solr1:8983",category="QUERY",handler="/select",internal="false"}'
+        values: '0+40x20'
+      - series: 
'solr_core_requests_errors_total{job="solr",instance="solr1:8983",category="QUERY",handler="/select",internal="false",source="client"}'
+        values: '0+0.8x20'
+    alert_rule_test:
+      - eval_time: 15m
+        alertname: SolrHighErrorRate
+        exp_alerts: []
+
+  # The index-size gauge is in MiB (MetricUtils.bytesToMegabytes divides by
+  # 1024^2), so physical memory has to be converted the same way. Dividing by
+  # 1e6 inflates this 9.9% fit to 10.4% and the alert is missed.
+  - interval: 1m
+    name: mmap ratio converts bytes to MiB
+    input_series:
+      - series: 
'jvm_system_memory_bytes{job="solr",instance="solr1:8983",state="total"}'
+        values: '18970836992+0x10'
+      - series: 
'jvm_memory_committed_bytes{job="solr",instance="solr1:8983",jvm_memory_type="heap",jvm_memory_pool_name="G1
 Old Gen"}'
+        values: '8589934592+0x10'
+      - series: 
'solr_core_index_size_megabytes{job="solr",instance="solr1:8983",collection="c",shard="shard1",core="c_shard1_replica_n1"}'
+        values: '100000+0x10'
+    alert_rule_test:
+      - eval_time: 8m
+        alertname: SolrHighMmapRatio
+        exp_alerts:
+          - exp_labels:
+              severity: warning
+              instance: solr1:8983
+            exp_annotations:
+              summary: 'Little of the Solr index fits in memory on solr1:8983'
+              description: |
+                Only 9.9% of the index on solr1:8983 fits in the
+                memory left outside the JVM heap (threshold: 10%). The rest is 
read from
+                disk on every search that touches it.
+
+  # A node that stops answering scrapes.
+  - interval: 1m
+    name: unreachable node
+    input_series:
+      - series: 'up{job="solr",instance="solr1:8983"}'
+        values: '1 1 0+0x12'
+      - series: 
'solr_cores_loaded{job="solr",instance="solr1:8983",category="CONTAINER",type="permanent"}'
+        values: '2+0x14'
+    alert_rule_test:
+      # Scrapes started failing at 2m, so the 5m 'for' is satisfied at 7m.
+      - eval_time: 6m
+        alertname: SolrNodeDown
+        exp_alerts: []
+      - eval_time: 8m
+        alertname: SolrNodeDown
+        exp_alerts:
+          - exp_labels:
+              severity: warning
+              instance: solr1:8983
+              job: solr
+            exp_annotations:
+              summary: 'Solr node solr1:8983 is down or has stopped reporting'
+              description: |
+                solr1:8983 is failing scrapes, or has sent no metrics for
+                5m. Either the node is down, its metrics endpoint is 
unreachable, or
+                metrics collection is switched off. Where metrics arrive 
through an
+                OpenTelemetry collector, the label names the collector rather 
than the node
+                unless Solr sends service.instance.id.
+
+  # Pushed metrics: the scrape target is the collector, so 'up' stays 1 while
+  # the node behind it dies. What stops is the data, which is what must alert.
+  # _ marks the sample as missing, which is what a node that stopped pushing
+  # looks like once the collector has expired its last value.
+  - interval: 1m
+    name: node stops pushing while the collector stays up
+    input_series:
+      - series: 'up{job="solr",instance="otel-collector:9464"}'
+        values: '1+0x20'
+      - series: 
'solr_cores_loaded{job="solr",instance="solr1:8983",category="CONTAINER",type="permanent"}'
+        values: '2 2 2 2 2 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _'
+    alert_rule_test:
+      # Nothing yet: the node has been quiet for less than the 5m window.
+      - eval_time: 7m
+        alertname: SolrNodeDown
+        exp_alerts: []
+      # Detected at 10m, one window after the last sample, but still pending.
+      - eval_time: 12m
+        alertname: SolrNodeDown
+        exp_alerts: []
+      # Detected at 10m and held for the 5m 'for'.
+      - eval_time: 16m
+        alertname: SolrNodeDown
+        exp_alerts:
+          - exp_labels:
+              severity: warning
+              instance: solr1:8983
+              job: solr
+            exp_annotations:
+              summary: 'Solr node solr1:8983 is down or has stopped reporting'
+              description: |
+                solr1:8983 is failing scrapes, or has sent no metrics for
+                5m. Either the node is down, its metrics endpoint is 
unreachable, or
+                metrics collection is switched off. Where metrics arrive 
through an
+                OpenTelemetry collector, the label names the collector rather 
than the node
+                unless Solr sends service.instance.id.
+
+  # A healthy node must not alert from either branch.
+  - interval: 1m
+    name: healthy node does not alert
+    input_series:
+      - series: 'up{job="solr",instance="solr1:8983"}'
+        values: '1+0x20'
+      - series: 
'solr_cores_loaded{job="solr",instance="solr1:8983",category="CONTAINER",type="permanent"}'
+        values: '2+0x20'
+    alert_rule_test:
+      - eval_time: 18m
+        alertname: SolrNodeDown
+        exp_alerts: []
diff --git a/solr/monitoring/prometheus-solr-alerts.yml 
b/solr/monitoring/prometheus-solr-alerts.yml
index d1cefdcba1a..1b612d03639 100644
--- a/solr/monitoring/prometheus-solr-alerts.yml
+++ b/solr/monitoring/prometheus-solr-alerts.yml
@@ -16,15 +16,159 @@
 # This file is generated by mixin/alerts/alerts.libsonnet — do not edit 
directly.
 # To regenerate: cd mixin && make alerts
 groups:
-- name: SolrExampleAlerts
+- name: SolrAlerts
   rules:
-  - alert: SolrNodeDown
+  - alert: SolrHighHeapUsage
     annotations:
       description: |
-        Prometheus has failed to scrape {{ $labels.instance }} for 2 minutes.
-        Either the node is down or its metrics endpoint is unreachable.
-      summary: Solr node {{ $labels.instance }} is not responding to scrapes
-    expr: up{job="solr"} == 0
+        Node {{ $labels.instance }} is using {{ $value | humanizePercentage }} 
of its JVM
+        heap (threshold: 90%). Raise -Xmx, or reduce cache sizes.
+      summary: Solr node {{ $labels.instance }} has high JVM heap usage
+    expr: |
+      sum by (instance) (
+        max by (instance, jvm_memory_pool_name) (
+          jvm_memory_used_bytes{job="solr",jvm_memory_type="heap"}
+        )
+      )
+      /
+      sum by (instance) (
+        max by (instance, jvm_memory_pool_name) (
+          jvm_memory_committed_bytes{job="solr",jvm_memory_type="heap"}
+        )
+      )
+      > 0.9
     for: 2m
+    labels:
+      severity: critical
+  - alert: SolrJvmGcThrashing
+    annotations:
+      description: |
+        Node {{ $labels.instance }} spends {{ $value | humanize }} seconds per 
minute in
+        garbage collection (threshold: 10). Pauses show up as search latency;
+        check heap usage first, then heap sizing and GC settings.
+      summary: Solr node {{ $labels.instance }} is spending much of its time 
in GC
+    expr: |
+      sum by (instance) (
+        max by (instance, jvm_gc_name, jvm_gc_action) (
+          rate(jvm_gc_duration_seconds_sum{job="solr"}[5m])
+        )
+      ) * 60
+      > 10
+    for: 3m
+    labels:
+      severity: critical
+  - alert: SolrLowDiskSpace
+    annotations:
+      description: |
+        Node {{ $labels.instance }} has {{ $value | humanizePercentage }} of 
its disk free
+        (threshold: 15%). Indexing fails once the disk fills, and a merge needs
+        room for the segments it rewrites.
+      summary: Solr node {{ $labels.instance }} is low on disk space
+    expr: |
+      min by (instance) 
(solr_disk_space_megabytes{job="solr",type="usable_space"})
+      /
+      min by (instance) 
(solr_disk_space_megabytes{job="solr",type="total_space"})
+      < 0.15
+    for: 5m
+    labels:
+      severity: critical
+  - alert: SolrNodeDown
+    annotations:
+      description: |
+        {{ $labels.instance }} is failing scrapes, or has sent no metrics for
+        5m. Either the node is down, its metrics endpoint is unreachable, or
+        metrics collection is switched off. Where metrics arrive through an
+        OpenTelemetry collector, the label names the collector rather than the 
node
+        unless Solr sends service.instance.id.
+      summary: Solr node {{ $labels.instance }} is down or has stopped 
reporting
+    expr: |
+      max by (job, instance) (up{job="solr"} == 0)
+      or
+      (
+        count by (job, instance) (
+          max_over_time(solr_cores_loaded{job="solr"}[1h])
+        )
+        unless
+        count by (job, instance) (
+          max_over_time(solr_cores_loaded{job="solr"}[5m])
+        )
+      )
+    for: 5m
+    labels:
+      severity: warning
+  - alert: SolrHighSearchLatency
+    annotations:
+      description: |
+        Node {{ $labels.instance }} answers 99% of searches in {{ $value | 
humanize }}ms
+        (threshold: 1000ms). Usual causes are expensive queries or faceting, 
caches
+        too small for the working set, and GC pauses.
+      summary: Solr node {{ $labels.instance }} has high search latency
+    expr: |
+      histogram_quantile(0.99,
+        sum by (le, instance) (
+          rate(
+            
solr_core_requests_times_milliseconds_bucket{job="solr",handler=~"/select.*",internal="false",core!=""}[5m]
+          )
+        )
+      )
+      > 1000
+    for: 5m
+    labels:
+      severity: warning
+  - alert: SolrHighErrorRate
+    annotations:
+      description: |
+        {{ $value | humanizePercentage }} of requests to {{ $labels.instance 
}} are failing
+        (threshold: 1%). The Solr log carries the cause: invalid queries,
+        missing fields, cores that failed to load, or connectivity problems.
+      summary: Solr node {{ $labels.instance }} has a high request error rate
+    expr: |
+      sum by (instance) 
(rate(solr_core_requests_errors_total{job="solr",core!=""}[5m]))
+      /
+      sum by (instance) 
(rate(solr_core_requests_total{job="solr",core!=""}[5m]))
+      > 0.01
+    for: 5m
+    labels:
+      severity: warning
+  - alert: SolrOverseerQueueBuildup
+    annotations:
+      description: |
+        {{ $value }} collection operations are queued on {{ $labels.instance }}
+        (threshold: 50). The Overseer is falling behind: look for long-running
+        collection operations, a disrupted election, or slow ZooKeeper.
+      summary: Solr Overseer collection work queue is building up on {{ 
$labels.instance }}
+    expr: |
+      max by (instance) (solr_overseer_collection_work_queue_size{job="solr"})
+      > 50
+    for: 5m
+    labels:
+      severity: warning
+  - alert: SolrHighMmapRatio
+    annotations:
+      description: |
+        Only {{ $value | humanize }}% of the index on {{ $labels.instance }} 
fits in the
+        memory left outside the JVM heap (threshold: 10%). The rest is read 
from
+        disk on every search that touches it.
+      summary: Little of the Solr index fits in memory on {{ $labels.instance 
}}
+    expr: |
+      (
+        clamp_max(
+          (
+            max by (instance) 
(jvm_system_memory_bytes{job="solr",state="total"})
+            - sum by (instance) (
+              max by (instance, jvm_memory_pool_name) (
+                jvm_memory_committed_bytes{job="solr",jvm_memory_type="heap"}
+              )
+            )
+          )
+          / (1024 * 1024)
+          / sum by (instance) (solr_core_index_size_megabytes{job="solr"})
+          * 100,
+          100
+        ) < 10
+      )
+      and on (instance)
+        max by (instance) (jvm_system_memory_bytes{job="solr",state="total"}) 
> 0
+    for: 5m
     labels:
       severity: warning
diff --git 
a/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc
 
b/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc
index 3d2d720402b..3103c2d41cf 100644
--- 
a/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc
+++ 
b/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc
@@ -16,15 +16,9 @@
 
 [IMPORTANT]
 ====
-*Work in progress — the artifacts shipped today are placeholders.*
+Solr 10 removed the `solr-exporter` process and renamed the metrics, so 
dashboards and alert rules made for Solr 9 and earlier do not work.
 
-Solr 10 removed the standalone `solr-exporter` (the `prometheus-exporter` 
module) and now exposes metrics natively, under OpenTelemetry-based metric 
names.
-Dashboards and alert rules written against the old exporter therefore do not 
work on Solr 10 or later: the process they scraped is gone, and the metric 
names and labels they query have changed.
-Solr's own dashboard and alert rules are consequently being built from 
scratch, panel by panel and rule by rule.
-
-What is in `solr/monitoring/` right now is a two-panel dashboard and a single 
alert, present to prove the generation pipeline works — not a monitoring setup 
to deploy.
-The dashboard worth deploying arrives in 
https://issues.apache.org/jira/browse/SOLR-18534[SOLR-18534], the alert rules 
in https://issues.apache.org/jira/browse/SOLR-18535[SOLR-18535], and the OTLP 
Collector guidance in 
https://issues.apache.org/jira/browse/SOLR-18536[SOLR-18536].
-Expect both files, and this page, to change substantially before they are 
useful.
+The alert rules below are current. The dashboard is still a placeholder; the 
real one arrives in 
https://issues.apache.org/jira/browse/SOLR-18534[SOLR-18534] and OTLP Collector 
guidance in https://issues.apache.org/jira/browse/SOLR-18536[SOLR-18536].
 ====
 
 Solr ships two monitoring artifacts in `solr/monitoring/`:
@@ -101,16 +95,26 @@ Validate the file before deploying it, and after any edit:
 promtool check rules prometheus-solr-alerts.yml
 ----
 
-Rules carry a `severity` label for routing in Alertmanager.
-One placeholder rule is included today:
+Each rule alerts per node and carries a `severity` label for routing in 
Alertmanager:
 
-[cols="2,1,3",options="header"]
+[cols="2,1,4,2",options="header"]
 |===
-| Alert | Severity | Fires when
-| `SolrNodeDown` | warning | A Solr target has failed to scrape for 2 minutes
+| Alert | Severity | Fires when | Setting
+| `SolrHighHeapUsage` | critical | Heap use above 90% for 2 minutes | 
`heapUsageThreshold`
+| `SolrJvmGcThrashing` | critical | Over 10 seconds of GC per minute for 3 
minutes | `gcSecondsPerMinuteThreshold`
+| `SolrLowDiskSpace` | critical | Under 15% free on the Solr home partition 
for 5 minutes | `diskFreeThreshold`
+| `SolrNodeDown` | warning | Scrapes failing, or no metrics received for 5 
minutes, for 5 minutes | `nodeDownFor`, `nodeReportingWindow`, 
`nodeReportingLookback`
+| `SolrHighSearchLatency` | warning | `/select` p99 above 1000 ms for 5 
minutes | `searchLatencyThresholdMs`
+| `SolrHighErrorRate` | warning | Over 1% of requests failing for 5 minutes | 
`errorRateThreshold`
+| `SolrOverseerQueueBuildup` | warning | Over 50 queued collection operations 
for 5 minutes (SolrCloud only) | `overseerQueueThreshold`
+| `SolrHighMmapRatio` | warning | Under 10% of the index fits in memory 
outside the heap for 5 minutes | `mmapRatioThreshold`
 |===
 
-NOTE: The rules covering heap, GC, disk, latency, error rate and SolrCloud 
health arrive in https://issues.apache.org/jira/browse/SOLR-18535[SOLR-18535].
+`SolrNodeDown` has two branches, because `up` only describes what Prometheus 
scrapes.
+Where Solr pushes metrics to an OpenTelemetry collector, the scrape target is 
the collector, which stays up while the nodes behind it stop, so the rule also 
alerts on a node that reported within `nodeReportingLookback` but has sent 
nothing for `nodeReportingWindow`.
+That branch names the collector rather than the node, until the nodes 
themselves report a `service.instance.id` resource attribute for the collector 
to derive an `instance` label from.
+
+To change a threshold, edit its setting in `mixin/config.libsonnet` and 
regenerate — see <<customizing>>.
 
 [[customizing]]
 == Customizing the Artifacts

Reply via email to