|
| 1 | +# Indicator Metric Design for Sysdig Dashboard Auto-Discovery |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document analyzes the requirements and provides recommendations for implementing an indicator metric (`ibm_codeengine_instance_resources`) that Sysdig will use to automatically show built-in dashboards. |
| 6 | + |
| 7 | +## Requirements Analysis |
| 8 | + |
| 9 | +### Purpose |
| 10 | +- Signal to Sysdig that Code Engine metrics are available |
| 11 | +- Trigger automatic display of pre-configured dashboards |
| 12 | +- Indicate the health/readiness status of the metrics collector |
| 13 | + |
| 14 | +### Sysdig Recommendation |
| 15 | +- **Metric Type**: Gauge |
| 16 | +- **Metric Name**: `ibm_codeengine_instance_resources` |
| 17 | +- **Status Label**: Should indicate readiness (value: `ready`) |
| 18 | + |
| 19 | +## Design Recommendations |
| 20 | + |
| 21 | +### ✅ YES - This Metric Makes Sense |
| 22 | + |
| 23 | +**Reasons:** |
| 24 | +1. **Dashboard Discovery**: Sysdig can detect the presence of Code Engine metrics and automatically enable relevant dashboards |
| 25 | +2. **Health Indicator**: Provides a simple way to monitor if the metrics collector is functioning |
| 26 | +3. **Low Cardinality**: When designed properly, it adds minimal overhead |
| 27 | +4. **Industry Standard**: Similar patterns used by other monitoring integrations (e.g., `up` metric in Prometheus exporters) |
| 28 | + |
| 29 | +### Metric Design |
| 30 | + |
| 31 | +#### Recommended Approach: Single Instance Gauge |
| 32 | + |
| 33 | +```prometheus |
| 34 | +# HELP ibm_codeengine_instance_resources Indicator metric for IBM Code Engine resource monitoring |
| 35 | +# TYPE ibm_codeengine_instance_resources gauge |
| 36 | +ibm_codeengine_instance_resources{status="ready"} 1 |
| 37 | +``` |
| 38 | + |
| 39 | +**Characteristics:** |
| 40 | +- **Value**: Always `1` when collector is running and healthy |
| 41 | +- **Single time series**: Only one metric instance per collector |
| 42 | +- **Minimal cardinality**: Only 1 time series regardless of number of pods/apps/jobs |
| 43 | + |
| 44 | +#### Alternative Approach: Per-Namespace Gauge (If Multiple Namespaces) |
| 45 | + |
| 46 | +```prometheus |
| 47 | +# HELP ibm_codeengine_instance_resources Indicator metric for IBM Code Engine resource monitoring |
| 48 | +# TYPE ibm_codeengine_instance_resources gauge |
| 49 | +ibm_codeengine_instance_resources{namespace="my-project-namespace",status="ready"} 1 |
| 50 | +``` |
| 51 | + |
| 52 | +**Use this if:** |
| 53 | +- You plan to monitor multiple Code Engine projects from a single collector |
| 54 | +- You need namespace-level visibility |
| 55 | + |
| 56 | +**Cardinality**: 1 time series per namespace (still very low) |
| 57 | + |
| 58 | +### Label Design |
| 59 | + |
| 60 | +#### Recommended Labels |
| 61 | + |
| 62 | +**Minimal (Recommended):** |
| 63 | +```go |
| 64 | +status="ready" // Indicates collector is operational |
| 65 | +``` |
| 66 | + |
| 67 | +**Extended (Optional):** |
| 68 | +```go |
| 69 | +status="ready" // Collector status |
| 70 | +namespace="my-project-namespace" // Code Engine project namespace |
| 71 | +collector_version="1.0.0" // Collector version for troubleshooting |
| 72 | +``` |
| 73 | + |
| 74 | +#### Status Values |
| 75 | + |
| 76 | +| Status | Value | Meaning | Use Case | |
| 77 | +|--------|-------|---------|----------| |
| 78 | +| Ready | `ready` | Collector is operational and collecting metrics | Normal operation | |
| 79 | +| Degraded | `degraded` | Collector is running but experiencing issues | Partial failures | |
| 80 | +| Starting | `starting` | Collector is initializing | Startup phase | |
| 81 | + |
| 82 | +**Recommendation**: Start with only `ready` status. Add others only if needed for operational visibility. |
| 83 | + |
| 84 | +### Cardinality Analysis |
| 85 | + |
| 86 | +#### Current Metrics Cardinality |
| 87 | +Looking at your existing metrics: |
| 88 | +``` |
| 89 | +ibm_codeengine_instance_cpu_usage_millicores{ |
| 90 | + ibm_codeengine_instance_name="pod-xyz", |
| 91 | + ibm_codeengine_component_type="app", |
| 92 | + ibm_codeengine_component_name="my-app" |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +**Cardinality**: N time series (where N = number of pods) |
| 97 | +- If you have 100 pods, you have 100 time series per metric type |
| 98 | +- Total: 100 pods × 4 metrics = 400 time series |
| 99 | + |
| 100 | +#### Indicator Metric Cardinality |
| 101 | + |
| 102 | +**Option 1: Single Instance (Recommended)** |
| 103 | +``` |
| 104 | +ibm_codeengine_instance_resources{status="ready"} 1 |
| 105 | +``` |
| 106 | +**Cardinality**: 1 time series (constant, regardless of pod count) |
| 107 | +**Impact**: Negligible (~0.25% overhead for 100 pods) |
| 108 | + |
| 109 | +**Option 2: Per-Namespace** |
| 110 | +``` |
| 111 | +ibm_codeengine_instance_resources{namespace="ns1",status="ready"} 1 |
| 112 | +ibm_codeengine_instance_resources{namespace="ns2",status="ready"} 1 |
| 113 | +``` |
| 114 | +**Cardinality**: M time series (where M = number of namespaces) |
| 115 | +**Impact**: Still negligible for typical use cases (1-10 namespaces) |
| 116 | + |
| 117 | +**Option 3: Per-Component (NOT RECOMMENDED)** |
| 118 | +``` |
| 119 | +ibm_codeengine_instance_resources{component_name="app1",status="ready"} 1 |
| 120 | +ibm_codeengine_instance_resources{component_name="app2",status="ready"} 1 |
| 121 | +``` |
| 122 | +**Cardinality**: K time series (where K = number of components) |
| 123 | +**Impact**: Defeats the purpose of an indicator metric; use existing metrics instead |
| 124 | + |
| 125 | +### Gauge Value Recommendations |
| 126 | + |
| 127 | +#### Option 1: Binary Indicator (Recommended) |
| 128 | +```go |
| 129 | +Value: 1 // Collector is running |
| 130 | +Value: 0 // Collector is stopped (metric disappears) |
| 131 | +``` |
| 132 | + |
| 133 | +**Advantages:** |
| 134 | +- Simple and clear |
| 135 | +- Standard pattern (like Prometheus `up` metric) |
| 136 | +- Easy to alert on: `ibm_codeengine_instance_resources == 0` |
| 137 | + |
| 138 | +#### Option 2: Timestamp |
| 139 | +```go |
| 140 | +Value: 1710950400 // Unix timestamp of last successful collection |
| 141 | +``` |
| 142 | + |
| 143 | +**Advantages:** |
| 144 | +- Can detect stale metrics |
| 145 | +- Useful for debugging collection delays |
| 146 | + |
| 147 | +**Disadvantages:** |
| 148 | +- More complex to interpret |
| 149 | +- Not necessary if Prometheus already tracks metric timestamps |
| 150 | + |
| 151 | +#### Option 3: Count of Monitored Resources |
| 152 | +```go |
| 153 | +Value: 42 // Number of pods being monitored |
| 154 | +``` |
| 155 | + |
| 156 | +**Advantages:** |
| 157 | +- Provides additional context |
| 158 | +- Can alert on unexpected changes |
| 159 | + |
| 160 | +**Disadvantages:** |
| 161 | +- Adds complexity |
| 162 | +- Information already available from other metrics |
| 163 | + |
| 164 | +**Recommendation**: Use **Option 1 (Binary Indicator)** with value `1` |
| 165 | + |
| 166 | +### Implementation Strategy |
| 167 | + |
| 168 | +#### When to Emit the Metric |
| 169 | + |
| 170 | +**Option A: Always Emit (Recommended)** |
| 171 | +```go |
| 172 | +// Emit on every metrics collection cycle |
| 173 | +// Value: 1 (constant) |
| 174 | +``` |
| 175 | + |
| 176 | +**Option B: Conditional Emit** |
| 177 | +```go |
| 178 | +// Only emit if collection was successful |
| 179 | +// Value: 1 if success, 0 or absent if failure |
| 180 | +``` |
| 181 | + |
| 182 | +**Recommendation**: Use Option A for simplicity. The metric's presence indicates the collector is running. |
| 183 | + |
| 184 | +#### Where to Add in Code |
| 185 | + |
| 186 | +Add to [`formatPrometheusMetrics()`](main.go:81) function after existing metrics: |
| 187 | + |
| 188 | +```go |
| 189 | +// After line 189 (after internal stats) |
| 190 | +sb.WriteString("# HELP ibm_codeengine_instance_resources Indicator metric for IBM Code Engine resource monitoring\n") |
| 191 | +sb.WriteString("# TYPE ibm_codeengine_instance_resources gauge\n") |
| 192 | +sb.WriteString("ibm_codeengine_instance_resources{status=\"ready\"} 1\n") |
| 193 | +sb.WriteString("\n") |
| 194 | +``` |
| 195 | + |
| 196 | +### Complete Metric Specification |
| 197 | + |
| 198 | +```prometheus |
| 199 | +# HELP ibm_codeengine_instance_resources Indicator metric for IBM Code Engine resource monitoring |
| 200 | +# TYPE ibm_codeengine_instance_resources gauge |
| 201 | +ibm_codeengine_instance_resources{status="ready"} 1 |
| 202 | +``` |
| 203 | + |
| 204 | +**Metric Properties:** |
| 205 | +- **Name**: `ibm_codeengine_instance_resources` |
| 206 | +- **Type**: Gauge |
| 207 | +- **Value**: `1` (constant) |
| 208 | +- **Labels**: |
| 209 | + - `status`: `"ready"` (indicates collector is operational) |
| 210 | +- **Cardinality**: 1 time series per collector instance |
| 211 | +- **Update Frequency**: Every metrics scrape (same as other metrics) |
| 212 | + |
| 213 | +### Alerting Examples |
| 214 | + |
| 215 | +Once implemented, you can create alerts: |
| 216 | + |
| 217 | +```promql |
| 218 | +# Alert if collector is down |
| 219 | +absent(ibm_codeengine_instance_resources{status="ready"}) |
| 220 | +
|
| 221 | +# Alert if collector hasn't reported in 5 minutes |
| 222 | +time() - timestamp(ibm_codeengine_instance_resources{status="ready"}) > 300 |
| 223 | +``` |
| 224 | + |
| 225 | +### Dashboard Auto-Discovery |
| 226 | + |
| 227 | +Sysdig will use this metric to: |
| 228 | +1. Detect Code Engine metrics are available |
| 229 | +2. Automatically enable the "IBM Code Engine - Container Resource Overview" dashboard |
| 230 | +3. Show the dashboard in the user's dashboard list |
| 231 | + |
| 232 | +**Detection Query Example:** |
| 233 | +```promql |
| 234 | +count(ibm_codeengine_instance_resources{status="ready"}) > 0 |
| 235 | +``` |
| 236 | + |
| 237 | +## Summary |
| 238 | + |
| 239 | +### ✅ Recommended Implementation |
| 240 | + |
| 241 | +```go |
| 242 | +// Add to formatPrometheusMetrics() function |
| 243 | +sb.WriteString("# HELP ibm_codeengine_instance_resources Indicator metric for IBM Code Engine resource monitoring\n") |
| 244 | +sb.WriteString("# TYPE ibm_codeengine_instance_resources gauge\n") |
| 245 | +sb.WriteString("ibm_codeengine_instance_resources{status=\"ready\"} 1\n") |
| 246 | +sb.WriteString("\n") |
| 247 | +``` |
| 248 | + |
| 249 | +### Key Benefits |
| 250 | + |
| 251 | +1. **Minimal Cardinality**: Only 1 time series (0.25% overhead) |
| 252 | +2. **Simple Design**: Binary indicator (value = 1) |
| 253 | +3. **Standard Pattern**: Follows Prometheus exporter conventions |
| 254 | +4. **Operational Value**: Can be used for health checks and alerting |
| 255 | +5. **Dashboard Discovery**: Enables Sysdig auto-discovery feature |
| 256 | + |
| 257 | +### Cardinality Impact |
| 258 | + |
| 259 | +| Scenario | Existing Metrics | Indicator Metric | Total | Overhead | |
| 260 | +|----------|------------------|------------------|-------|----------| |
| 261 | +| 10 pods | 40 | 1 | 41 | 2.5% | |
| 262 | +| 100 pods | 400 | 1 | 401 | 0.25% | |
| 263 | +| 1000 pods | 4000 | 1 | 4001 | 0.025% | |
| 264 | + |
| 265 | +**Conclusion**: The indicator metric adds negligible cardinality overhead while providing significant operational value. |
| 266 | + |
| 267 | +## Next Steps |
| 268 | + |
| 269 | +1. Implement the metric in [`main.go`](main.go:81) |
| 270 | +2. Test with Sysdig to verify dashboard auto-discovery |
| 271 | +3. Update documentation with the new metric |
| 272 | +4. Consider adding to the dashboard JSON if needed for visibility |
0 commit comments