| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package ceph |
| 4 | |
| 5 | import ( |
| 6 | "net/url" |
| 7 | ) |
| 8 | |
| 9 | // https://docs.ceph.com/en/reef/mgr/ceph_api/ |
| 10 | |
| 11 | const ( |
| 12 | urlPathApiAuth = "/api/auth" |
| 13 | urlPathApiAuthCheck = "/api/auth/check" |
| 14 | urlPathApiAuthLogout = "/api/auth/logout" |
| 15 | urlPathApiHealthMinimal = "/api/health/minimal" |
| 16 | urlPathApiMonitor = "/api/monitor" |
| 17 | urlPathApiOsd = "/api/osd" |
| 18 | urlPathApiPool = "/api/pool" |
| 19 | ) |
| 20 | |
| 21 | var ( |
| 22 | urlQueryApiPool = url.Values{"stats": {"true"}}.Encode() |
| 23 | ) |
| 24 | |
| 25 | const ( |
| 26 | hdrAcceptVersion = "application/vnd.ceph.api.v1.0+json" |
| 27 | hdrContentTypeJson = "application/json" |
| 28 | ) |
| 29 | |
| 30 | type apiHealthMinimalResponse struct { |
| 31 | Health struct { |
| 32 | Status string `json:"status"` |
| 33 | } `json:"health"` |
| 34 | MonStatus struct { |
| 35 | MonMap struct { |
| 36 | Mons []any `json:"mons"` |
| 37 | } `json:"monmap"` |
| 38 | } `json:"mon_status"` |
| 39 | ScrubStatus string `json:"scrub_status"` |
| 40 | OsdMap struct { |
| 41 | Osds []struct { |
| 42 | In int64 `json:"in"` |
| 43 | Up int64 `json:"up"` |
| 44 | } `json:"osds"` |
| 45 | } `json:"osd_map"` |
| 46 | PgInfo struct { |
| 47 | ObjectStats struct { |
| 48 | NumObjects int64 `json:"num_objects"` |
| 49 | NumObjectsDegraded int64 `json:"num_objects_degraded"` |
| 50 | NumObjectsMisplaced int64 `json:"num_objects_misplaced"` |
| 51 | NumObjectsUnfound int64 `json:"num_objects_unfound"` |
| 52 | } `json:"object_stats"` |
| 53 | Statuses map[string]int64 `json:"statuses"` |
| 54 | PgsPerOsd float64 `json:"pgs_per_osd"` |
| 55 | } `json:"pg_info"` |
| 56 | Pools []any `json:"pools"` |
| 57 | MgrMap struct { |
| 58 | ActiveName string `json:"active_name"` |
| 59 | Standbys []struct { |
| 60 | Gid int `json:"gid"` |
| 61 | } `json:"standbys"` |
| 62 | } `json:"mgr_map"` |
| 63 | Df struct { |
| 64 | Stats struct { |
| 65 | TotalAvailBytes int64 `json:"total_avail_bytes"` |
| 66 | TotalBytes int64 `json:"total_bytes"` |
| 67 | TotalUsedRawBytes int64 `json:"total_used_raw_bytes"` |
| 68 | } `json:"stats"` |
| 69 | } `json:"df"` |
| 70 | ClientPerf struct { |
| 71 | ReadBytesSec float64 `json:"read_bytes_sec"` |
| 72 | ReadOpPerSec float64 `json:"read_op_per_sec"` |
| 73 | WriteBytesSec float64 `json:"write_bytes_sec"` |
| 74 | WriteOpPerSec float64 `json:"write_op_per_sec"` |
| 75 | RecoveringBytesPerSec float64 `json:"recovering_bytes_per_sec"` |
| 76 | } `json:"client_perf"` |
| 77 | Hosts int64 `json:"hosts"` |
| 78 | Rgw int64 `json:"rgw"` |
| 79 | IscsiDaemons struct { |
| 80 | Up int64 `json:"up"` |
| 81 | Down int64 `json:"down"` |
| 82 | } `json:"iscsi_daemons"` |
| 83 | } |
| 84 | |
| 85 | type apiOsdResponse struct { |
| 86 | UUID string `json:"uuid"` |
| 87 | ID int64 `json:"id"` |
| 88 | Up int64 `json:"up"` |
| 89 | In int64 `json:"in"` |
| 90 | OsdStats struct { |
| 91 | Statfs struct { |
| 92 | Total int64 `json:"total"` |
| 93 | Available int64 `json:"available"` |
| 94 | } `json:"statfs"` |
| 95 | PerfStat struct { |
| 96 | CommitLatencyMs float64 `json:"commit_latency_ms"` |
| 97 | ApplyLatencyMs float64 `json:"apply_latency_ms"` |
| 98 | } `json:"perf_stat"` |
| 99 | } `json:"osd_stats"` |
| 100 | Stats struct { |
| 101 | OpW float64 `json:"op_w"` |
| 102 | OpInBytes float64 `json:"op_in_bytes"` |
| 103 | OpR float64 `json:"op_r"` |
| 104 | OpOutBytes float64 `json:"op_out_bytes"` |
| 105 | } `json:"stats"` |
| 106 | Tree struct { |
| 107 | DeviceClass string `json:"device_class"` |
| 108 | Type string `json:"type"` |
| 109 | Name string `json:"name"` |
| 110 | } `json:"tree"` |
| 111 | } |
| 112 | |
| 113 | type apiPoolResponse struct { |
| 114 | PoolName string `json:"pool_name"` |
| 115 | Stats struct { |
| 116 | Stored struct{ Latest float64 } `json:"stored"` |
| 117 | Objects struct{ Latest float64 } `json:"objects"` |
| 118 | AvailRaw struct{ Latest float64 } `json:"avail_raw"` |
| 119 | BytesUsed struct{ Latest float64 } `json:"bytes_used"` |
| 120 | PercentUsed struct{ Latest float64 } `json:"percent_used"` |
| 121 | Reads struct{ Latest float64 } `json:"rd"` |
| 122 | ReadBytes struct{ Latest float64 } `json:"rd_bytes"` |
| 123 | Writes struct{ Latest float64 } `json:"wr"` |
| 124 | WrittenBytes struct{ Latest float64 } `json:"wr_bytes"` |
| 125 | } `json:"stats"` |
| 126 | } |