|
| 1 | +package models |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | +) |
| 6 | + |
| 7 | +// ToolCallMetric represents a single tool call event |
| 8 | +type ToolCallMetric struct { |
| 9 | + ID string `json:"id"` |
| 10 | + Timestamp time.Time `json:"timestamp"` |
| 11 | + ServerID string `json:"server_id"` |
| 12 | + SessionID *string `json:"session_id,omitempty"` |
| 13 | + ToolName string `json:"tool_name"` |
| 14 | + Parameters map[string]interface{} `json:"parameters,omitempty"` |
| 15 | + DurationMS int64 `json:"duration_ms"` |
| 16 | + Status string `json:"status"` // success, error, timeout |
| 17 | + ErrorMessage *string `json:"error_message,omitempty"` |
| 18 | + ErrorType *string `json:"error_type,omitempty"` |
| 19 | + ResultSize *int `json:"result_size,omitempty"` |
| 20 | + ProtocolVersion string `json:"protocol_version,omitempty"` |
| 21 | + ClientName string `json:"client_name,omitempty"` |
| 22 | + ClientVersion string `json:"client_version,omitempty"` |
| 23 | +} |
| 24 | + |
| 25 | +// ResourceAccessMetric represents a resource access event |
| 26 | +type ResourceAccessMetric struct { |
| 27 | + ID string `json:"id"` |
| 28 | + Timestamp time.Time `json:"timestamp"` |
| 29 | + ServerID string `json:"server_id"` |
| 30 | + SessionID *string `json:"session_id,omitempty"` |
| 31 | + ResourceURI string `json:"resource_uri"` |
| 32 | + AccessType string `json:"access_type"` // read, subscribe |
| 33 | + DurationMS int64 `json:"duration_ms"` |
| 34 | + CacheHit bool `json:"cache_hit"` |
| 35 | + Status string `json:"status"` |
| 36 | + Size *int `json:"size,omitempty"` |
| 37 | +} |
| 38 | + |
| 39 | +// SessionMetric represents a session lifecycle event |
| 40 | +type SessionMetric struct { |
| 41 | + ID string `json:"id"` |
| 42 | + ServerID string `json:"server_id"` |
| 43 | + StartTime time.Time `json:"start_time"` |
| 44 | + EndTime *time.Time `json:"end_time,omitempty"` |
| 45 | + DurationMS *int64 `json:"duration_ms,omitempty"` |
| 46 | + ToolCallCount int `json:"tool_call_count"` |
| 47 | + ResourceAccessCount int `json:"resource_access_count"` |
| 48 | + PromptInvocationCount int `json:"prompt_invocation_count"` |
| 49 | + ProtocolVersion string `json:"protocol_version"` |
| 50 | + ClientName string `json:"client_name"` |
| 51 | + ClientVersion string `json:"client_version"` |
| 52 | +} |
| 53 | + |
| 54 | +// ServerInfo represents metadata about an MCP server |
| 55 | +type ServerInfo struct { |
| 56 | + ID string `json:"id"` |
| 57 | + Name string `json:"name"` |
| 58 | + Description string `json:"description,omitempty"` |
| 59 | + Version string `json:"version,omitempty"` |
| 60 | + FirstSeen time.Time `json:"first_seen"` |
| 61 | + LastSeen time.Time `json:"last_seen"` |
| 62 | + Metadata map[string]interface{} `json:"metadata,omitempty"` |
| 63 | +} |
| 64 | + |
| 65 | +// ToolStatistics represents aggregated tool statistics |
| 66 | +type ToolStatistics struct { |
| 67 | + ToolName string `json:"tool_name"` |
| 68 | + TimeWindow time.Time `json:"time_window"` |
| 69 | + WindowSize string `json:"window_size"` // 1m, 5m, 1h, 1d |
| 70 | + CallCount int64 `json:"call_count"` |
| 71 | + SuccessCount int64 `json:"success_count"` |
| 72 | + ErrorCount int64 `json:"error_count"` |
| 73 | + TimeoutCount int64 `json:"timeout_count"` |
| 74 | + AvgDurationMS float64 `json:"avg_duration_ms"` |
| 75 | + P50DurationMS int64 `json:"p50_duration_ms"` |
| 76 | + P95DurationMS int64 `json:"p95_duration_ms"` |
| 77 | + P99DurationMS int64 `json:"p99_duration_ms"` |
| 78 | + MaxDurationMS int64 `json:"max_duration_ms"` |
| 79 | + MinDurationMS int64 `json:"min_duration_ms"` |
| 80 | +} |
| 81 | + |
| 82 | +// IngestRequest represents a batch of metrics to ingest |
| 83 | +type IngestRequest struct { |
| 84 | + Metrics []ToolCallMetric `json:"metrics"` |
| 85 | +} |
| 86 | + |
| 87 | +// IngestResponse represents the response from an ingest request |
| 88 | +type IngestResponse struct { |
| 89 | + Accepted int `json:"accepted"` |
| 90 | + Rejected int `json:"rejected"` |
| 91 | + Errors []IngestError `json:"errors,omitempty"` |
| 92 | +} |
| 93 | + |
| 94 | +// IngestError represents an error during ingestion |
| 95 | +type IngestError struct { |
| 96 | + Index int `json:"index"` |
| 97 | + Reason string `json:"reason"` |
| 98 | +} |
| 99 | + |
| 100 | +// ServerMetrics represents aggregated metrics for a server |
| 101 | +type ServerMetrics struct { |
| 102 | + ServerID string `json:"server_id"` |
| 103 | + TimeRange TimeRange `json:"time_range"` |
| 104 | + TotalCalls int64 `json:"total_calls"` |
| 105 | + SuccessRate float64 `json:"success_rate"` |
| 106 | + ErrorRate float64 `json:"error_rate"` |
| 107 | + AvgLatencyMS float64 `json:"avg_latency_ms"` |
| 108 | + P95LatencyMS int64 `json:"p95_latency_ms"` |
| 109 | + P99LatencyMS int64 `json:"p99_latency_ms"` |
| 110 | + ActiveSessions int `json:"active_sessions"` |
| 111 | + UniqueTools int `json:"unique_tools_used"` |
| 112 | + Timeline []TimelinePoint `json:"timeline,omitempty"` |
| 113 | +} |
| 114 | + |
| 115 | +// TimeRange represents a time range for queries |
| 116 | +type TimeRange struct { |
| 117 | + From time.Time `json:"from"` |
| 118 | + To time.Time `json:"to"` |
| 119 | +} |
| 120 | + |
| 121 | +// TimelinePoint represents a single point in a timeline |
| 122 | +type TimelinePoint struct { |
| 123 | + Timestamp time.Time `json:"timestamp"` |
| 124 | + Calls int64 `json:"calls"` |
| 125 | + Errors int64 `json:"errors"` |
| 126 | + AvgLatencyMS float64 `json:"avg_latency_ms"` |
| 127 | +} |
| 128 | + |
| 129 | +// ToolMetrics represents detailed metrics for a specific tool |
| 130 | +type ToolMetrics struct { |
| 131 | + ToolName string `json:"name"` |
| 132 | + CallCount int64 `json:"call_count"` |
| 133 | + SuccessCount int64 `json:"success_count"` |
| 134 | + ErrorCount int64 `json:"error_count"` |
| 135 | + SuccessRate float64 `json:"success_rate"` |
| 136 | + AvgDurationMS float64 `json:"avg_duration_ms"` |
| 137 | + P50DurationMS int64 `json:"p50_duration_ms"` |
| 138 | + P95DurationMS int64 `json:"p95_duration_ms"` |
| 139 | + P99DurationMS int64 `json:"p99_duration_ms"` |
| 140 | + LastCalled *time.Time `json:"last_called,omitempty"` |
| 141 | + LastError *time.Time `json:"last_error,omitempty"` |
| 142 | +} |
| 143 | + |
| 144 | +// ErrorInfo represents detailed information about an error |
| 145 | +type ErrorInfo struct { |
| 146 | + ID string `json:"id"` |
| 147 | + Timestamp time.Time `json:"timestamp"` |
| 148 | + ToolName string `json:"tool_name"` |
| 149 | + ErrorMessage string `json:"error_message"` |
| 150 | + ErrorType string `json:"error_type"` |
| 151 | + SessionID *string `json:"session_id,omitempty"` |
| 152 | + DurationMS int64 `json:"duration_ms"` |
| 153 | + Parameters map[string]interface{} `json:"parameters,omitempty"` |
| 154 | +} |
| 155 | + |
| 156 | +// SessionInfo represents detailed information about a session |
| 157 | +type SessionInfo struct { |
| 158 | + ID string `json:"id"` |
| 159 | + StartTime time.Time `json:"start_time"` |
| 160 | + EndTime *time.Time `json:"end_time,omitempty"` |
| 161 | + DurationMS *int64 `json:"duration_ms,omitempty"` |
| 162 | + ToolCallCount int `json:"tool_call_count"` |
| 163 | + ResourceAccessCount int `json:"resource_access_count"` |
| 164 | + Status string `json:"status"` |
| 165 | + ClientName string `json:"client_name"` |
| 166 | + ClientVersion string `json:"client_version"` |
| 167 | + ProtocolVersion string `json:"protocol_version"` |
| 168 | + LastActivity time.Time `json:"last_activity"` |
| 169 | +} |
| 170 | + |
| 171 | +// Anomaly represents a detected anomaly |
| 172 | +type Anomaly struct { |
| 173 | + Type string `json:"type"` |
| 174 | + ToolName string `json:"tool_name,omitempty"` |
| 175 | + DetectedAt time.Time `json:"detected_at"` |
| 176 | + Severity string `json:"severity"` |
| 177 | + Description string `json:"description"` |
| 178 | + BaselineValue float64 `json:"baseline_value"` |
| 179 | + CurrentValue float64 `json:"current_value"` |
| 180 | + Confidence float64 `json:"confidence"` |
| 181 | +} |
| 182 | + |
| 183 | +// Pagination represents pagination parameters and metadata |
| 184 | +type Pagination struct { |
| 185 | + Total int64 `json:"total"` |
| 186 | + Limit int `json:"limit"` |
| 187 | + Offset int `json:"offset"` |
| 188 | +} |
0 commit comments