| 43 | } |
| 44 | |
| 45 | func NewMetrics(logger slog.Logger) *Metrics { |
| 46 | log := logger.Named("provisionerd_server_metrics") |
| 47 | |
| 48 | return &Metrics{ |
| 49 | logger: log, |
| 50 | workspaceCreationTimings: prometheus.NewHistogramVec(prometheus.HistogramOpts{ |
| 51 | Namespace: "coderd", |
| 52 | Name: "workspace_creation_duration_seconds", |
| 53 | Help: "Time to create a workspace by organization, template, preset, and type (regular or prebuild).", |
| 54 | Buckets: []float64{ |
| 55 | 1, // 1s |
| 56 | 10, |
| 57 | 30, |
| 58 | 60, // 1min |
| 59 | 60 * 5, |
| 60 | 60 * 10, |
| 61 | 60 * 30, // 30min |
| 62 | 60 * 60, // 1hr |
| 63 | }, |
| 64 | NativeHistogramBucketFactor: 1.1, |
| 65 | // Max number of native buckets kept at once to bound memory. |
| 66 | NativeHistogramMaxBucketNumber: 100, |
| 67 | // Merge/flush small buckets periodically to control churn. |
| 68 | NativeHistogramMinResetDuration: time.Hour, |
| 69 | // Treat tiny values as zero (helps with noisy near-zero latencies). |
| 70 | NativeHistogramZeroThreshold: 0, |
| 71 | NativeHistogramMaxZeroThreshold: 0, |
| 72 | }, []string{"organization_name", "template_name", "preset_name", "type"}), |
| 73 | workspaceClaimTimings: prometheus.NewHistogramVec(prometheus.HistogramOpts{ |
| 74 | Namespace: "coderd", |
| 75 | Name: "prebuilt_workspace_claim_duration_seconds", |
| 76 | Help: "Time to claim a prebuilt workspace by organization, template, and preset.", |
| 77 | // Higher resolution between 1–5m to show typical prebuild claim times. |
| 78 | // Cap at 5m since longer claims diminish prebuild value. |
| 79 | Buckets: []float64{ |
| 80 | 1, // 1s |
| 81 | 5, |
| 82 | 10, |
| 83 | 20, |
| 84 | 30, |
| 85 | 60, // 1m |
| 86 | 120, // 2m |
| 87 | 180, // 3m |
| 88 | 240, // 4m |
| 89 | 300, // 5m |
| 90 | }, |
| 91 | NativeHistogramBucketFactor: 1.1, |
| 92 | // Max number of native buckets kept at once to bound memory. |
| 93 | NativeHistogramMaxBucketNumber: 100, |
| 94 | // Merge/flush small buckets periodically to control churn. |
| 95 | NativeHistogramMinResetDuration: time.Hour, |
| 96 | // Treat tiny values as zero (helps with noisy near-zero latencies). |
| 97 | NativeHistogramZeroThreshold: 0, |
| 98 | NativeHistogramMaxZeroThreshold: 0, |
| 99 | }, []string{"organization_name", "template_name", "preset_name"}), |
| 100 | jobQueueWait: prometheus.NewHistogramVec(prometheus.HistogramOpts{ |
| 101 | Namespace: "coderd", |
| 102 | Name: "provisioner_job_queue_wait_seconds", |