metrics.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. // +build !nometrics
  2. // Package metrics provides Prometheus metrics support
  3. package metrics
  4. import (
  5. "github.com/go-chi/chi"
  6. "github.com/prometheus/client_golang/prometheus"
  7. "github.com/prometheus/client_golang/prometheus/promauto"
  8. "github.com/prometheus/client_golang/prometheus/promhttp"
  9. "github.com/drakkan/sftpgo/version"
  10. )
  11. const (
  12. loginMethodPublicKey = "publickey"
  13. loginMethodKeyboardInteractive = "keyboard-interactive"
  14. loginMethodKeyAndPassword = "publickey+password"
  15. loginMethodKeyAndKeyboardInt = "publickey+keyboard-interactive"
  16. )
  17. func init() {
  18. version.AddFeature("+metrics")
  19. }
  20. var (
  21. // dataproviderAvailability is the metric that reports the availability for the configured data provider
  22. dataproviderAvailability = promauto.NewGauge(prometheus.GaugeOpts{
  23. Name: "sftpgo_dataprovider_availability",
  24. Help: "Availability for the configured data provider, 1 means OK, 0 KO",
  25. })
  26. // activeConnections is the metric that reports the total number of active connections
  27. activeConnections = promauto.NewGauge(prometheus.GaugeOpts{
  28. Name: "sftpgo_active_connections",
  29. Help: "Total number of logged in users",
  30. })
  31. // totalUploads is the metric that reports the total number of successful SFTP/SCP uploads
  32. totalUploads = promauto.NewCounter(prometheus.CounterOpts{
  33. Name: "sftpgo_uploads_total",
  34. Help: "The total number of successful SFTP/SCP uploads",
  35. })
  36. // totalDownloads is the metric that reports the total number of successful SFTP/SCP downloads
  37. totalDownloads = promauto.NewCounter(prometheus.CounterOpts{
  38. Name: "sftpgo_downloads_total",
  39. Help: "The total number of successful SFTP/SCP downloads",
  40. })
  41. // totalUploadErrors is the metric that reports the total number of SFTP/SCP upload errors
  42. totalUploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  43. Name: "sftpgo_upload_errors_total",
  44. Help: "The total number of SFTP/SCP upload errors",
  45. })
  46. // totalDownloadErrors is the metric that reports the total number of SFTP/SCP download errors
  47. totalDownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  48. Name: "sftpgo_download_errors_total",
  49. Help: "The total number of SFTP/SCP download errors",
  50. })
  51. // totalUploadSize is the metric that reports the total SFTP/SCP uploads size as bytes
  52. totalUploadSize = promauto.NewCounter(prometheus.CounterOpts{
  53. Name: "sftpgo_upload_size",
  54. Help: "The total SFTP/SCP upload size as bytes, partial uploads are included",
  55. })
  56. // totalDownloadSize is the metric that reports the total SFTP/SCP downloads size as bytes
  57. totalDownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  58. Name: "sftpgo_download_size",
  59. Help: "The total SFTP/SCP download size as bytes, partial downloads are included",
  60. })
  61. // totalSSHCommands is the metric that reports the total number of executed SSH commands
  62. totalSSHCommands = promauto.NewCounter(prometheus.CounterOpts{
  63. Name: "sftpgo_ssh_commands_total",
  64. Help: "The total number of executed SSH commands",
  65. })
  66. // totalSSHCommandErrors is the metric that reports the total number of SSH command errors
  67. totalSSHCommandErrors = promauto.NewCounter(prometheus.CounterOpts{
  68. Name: "sftpgo_ssh_command_errors_total",
  69. Help: "The total number of SSH command errors",
  70. })
  71. // totalLoginAttempts is the metric that reports the total number of login attempts
  72. totalLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  73. Name: "sftpgo_login_attempts_total",
  74. Help: "The total number of login attempts",
  75. })
  76. // totalLoginOK is the metric that reports the total number of successful logins
  77. totalLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  78. Name: "sftpgo_login_ok_total",
  79. Help: "The total number of successful logins",
  80. })
  81. // totalLoginFailed is the metric that reports the total number of failed logins
  82. totalLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  83. Name: "sftpgo_login_ko_total",
  84. Help: "The total number of failed logins",
  85. })
  86. // totalPasswordLoginAttempts is the metric that reports the total number of login attempts
  87. // using a password
  88. totalPasswordLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  89. Name: "sftpgo_password_login_attempts_total",
  90. Help: "The total number of login attempts using a password",
  91. })
  92. // totalPasswordLoginOK is the metric that reports the total number of successful logins
  93. // using a password
  94. totalPasswordLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  95. Name: "sftpgo_password_login_ok_total",
  96. Help: "The total number of successful logins using a password",
  97. })
  98. // totalPasswordLoginFailed is the metric that reports the total number of failed logins
  99. // using a password
  100. totalPasswordLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  101. Name: "sftpgo_password_login_ko_total",
  102. Help: "The total number of failed logins using a password",
  103. })
  104. // totalKeyLoginAttempts is the metric that reports the total number of login attempts
  105. // using a public key
  106. totalKeyLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  107. Name: "sftpgo_public_key_login_attempts_total",
  108. Help: "The total number of login attempts using a public key",
  109. })
  110. // totalKeyLoginOK is the metric that reports the total number of successful logins
  111. // using a public key
  112. totalKeyLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  113. Name: "sftpgo_public_key_login_ok_total",
  114. Help: "The total number of successful logins using a public key",
  115. })
  116. // totalKeyLoginFailed is the metric that reports the total number of failed logins
  117. // using a public key
  118. totalKeyLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  119. Name: "sftpgo_public_key_login_ko_total",
  120. Help: "The total number of failed logins using a public key",
  121. })
  122. // totalInteractiveLoginAttempts is the metric that reports the total number of login attempts
  123. // using keyboard interactive authentication
  124. totalInteractiveLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  125. Name: "sftpgo_keyboard_interactive_login_attempts_total",
  126. Help: "The total number of login attempts using keyboard interactive authentication",
  127. })
  128. // totalInteractiveLoginOK is the metric that reports the total number of successful logins
  129. // using keyboard interactive authentication
  130. totalInteractiveLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  131. Name: "sftpgo_keyboard_interactive_login_ok_total",
  132. Help: "The total number of successful logins using keyboard interactive authentication",
  133. })
  134. // totalInteractiveLoginFailed is the metric that reports the total number of failed logins
  135. // using keyboard interactive authentication
  136. totalInteractiveLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  137. Name: "sftpgo_keyboard_interactive_login_ko_total",
  138. Help: "The total number of failed logins using keyboard interactive authentication",
  139. })
  140. // totalKeyAndPasswordLoginAttempts is the metric that reports the total number of
  141. // login attempts using public key + password multi steps auth
  142. totalKeyAndPasswordLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  143. Name: "sftpgo_key_and_password_login_attempts_total",
  144. Help: "The total number of login attempts using public key + password",
  145. })
  146. // totalKeyAndPasswordLoginOK is the metric that reports the total number of
  147. // successful logins using public key + password multi steps auth
  148. totalKeyAndPasswordLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  149. Name: "sftpgo_key_and_password_login_ok_total",
  150. Help: "The total number of successful logins using public key + password",
  151. })
  152. // totalKeyAndPasswordLoginFailed is the metric that reports the total number of
  153. // failed logins using public key + password multi steps auth
  154. totalKeyAndPasswordLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  155. Name: "sftpgo_key_and_password_login_ko_total",
  156. Help: "The total number of failed logins using public key + password",
  157. })
  158. // totalKeyAndKeyIntLoginAttempts is the metric that reports the total number of
  159. // login attempts using public key + keyboard interactive multi steps auth
  160. totalKeyAndKeyIntLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  161. Name: "sftpgo_key_and_keyboard_int_login_attempts_total",
  162. Help: "The total number of login attempts using public key + keyboard interactive",
  163. })
  164. // totalKeyAndKeyIntLoginOK is the metric that reports the total number of
  165. // successful logins using public key + keyboard interactive multi steps auth
  166. totalKeyAndKeyIntLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  167. Name: "sftpgo_key_and_keyboard_int_login_ok_total",
  168. Help: "The total number of successful logins using public key + keyboard interactive",
  169. })
  170. // totalKeyAndKeyIntLoginFailed is the metric that reports the total number of
  171. // failed logins using public key + keyboard interactive multi steps auth
  172. totalKeyAndKeyIntLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  173. Name: "sftpgo_key_and_keyboard_int_login_ko_total",
  174. Help: "The total number of failed logins using public key + keyboard interactive",
  175. })
  176. totalHTTPRequests = promauto.NewCounter(prometheus.CounterOpts{
  177. Name: "sftpgo_http_req_total",
  178. Help: "The total number of HTTP requests served",
  179. })
  180. totalHTTPOK = promauto.NewCounter(prometheus.CounterOpts{
  181. Name: "sftpgo_http_req_ok_total",
  182. Help: "The total number of HTTP requests served with 2xx status code",
  183. })
  184. totalHTTPClientErrors = promauto.NewCounter(prometheus.CounterOpts{
  185. Name: "sftpgo_http_client_errors_total",
  186. Help: "The total number of HTTP requests served with 4xx status code",
  187. })
  188. totalHTTPServerErrors = promauto.NewCounter(prometheus.CounterOpts{
  189. Name: "sftpgo_http_server_errors_total",
  190. Help: "The total number of HTTP requests served with 5xx status code",
  191. })
  192. // totalS3Uploads is the metric that reports the total number of successful S3 uploads
  193. totalS3Uploads = promauto.NewCounter(prometheus.CounterOpts{
  194. Name: "sftpgo_s3_uploads_total",
  195. Help: "The total number of successful S3 uploads",
  196. })
  197. // totalS3Downloads is the metric that reports the total number of successful S3 downloads
  198. totalS3Downloads = promauto.NewCounter(prometheus.CounterOpts{
  199. Name: "sftpgo_s3_downloads_total",
  200. Help: "The total number of successful S3 downloads",
  201. })
  202. // totalS3UploadErrors is the metric that reports the total number of S3 upload errors
  203. totalS3UploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  204. Name: "sftpgo_s3_upload_errors_total",
  205. Help: "The total number of S3 upload errors",
  206. })
  207. // totalS3DownloadErrors is the metric that reports the total number of S3 download errors
  208. totalS3DownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  209. Name: "sftpgo_s3_download_errors_total",
  210. Help: "The total number of S3 download errors",
  211. })
  212. // totalS3UploadSize is the metric that reports the total S3 uploads size as bytes
  213. totalS3UploadSize = promauto.NewCounter(prometheus.CounterOpts{
  214. Name: "sftpgo_s3_upload_size",
  215. Help: "The total S3 upload size as bytes, partial uploads are included",
  216. })
  217. // totalS3DownloadSize is the metric that reports the total S3 downloads size as bytes
  218. totalS3DownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  219. Name: "sftpgo_s3_download_size",
  220. Help: "The total S3 download size as bytes, partial downloads are included",
  221. })
  222. // totalS3ListObjects is the metric that reports the total successful S3 list objects requests
  223. totalS3ListObjects = promauto.NewCounter(prometheus.CounterOpts{
  224. Name: "sftpgo_s3_list_objects",
  225. Help: "The total number of successful S3 list objects requests",
  226. })
  227. // totalS3CopyObject is the metric that reports the total successful S3 copy object requests
  228. totalS3CopyObject = promauto.NewCounter(prometheus.CounterOpts{
  229. Name: "sftpgo_s3_copy_object",
  230. Help: "The total number of successful S3 copy object requests",
  231. })
  232. // totalS3DeleteObject is the metric that reports the total successful S3 delete object requests
  233. totalS3DeleteObject = promauto.NewCounter(prometheus.CounterOpts{
  234. Name: "sftpgo_s3_delete_object",
  235. Help: "The total number of successful S3 delete object requests",
  236. })
  237. // totalS3ListObjectsError is the metric that reports the total S3 list objects errors
  238. totalS3ListObjectsErrors = promauto.NewCounter(prometheus.CounterOpts{
  239. Name: "sftpgo_s3_list_objects_errors",
  240. Help: "The total number of S3 list objects errors",
  241. })
  242. // totalS3CopyObjectErrors is the metric that reports the total S3 copy object errors
  243. totalS3CopyObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  244. Name: "sftpgo_s3_copy_object_errors",
  245. Help: "The total number of S3 copy object errors",
  246. })
  247. // totalS3DeleteObjectErrors is the metric that reports the total S3 delete object errors
  248. totalS3DeleteObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  249. Name: "sftpgo_s3_delete_object_errors",
  250. Help: "The total number of S3 delete object errors",
  251. })
  252. // totalS3HeadBucket is the metric that reports the total successful S3 head bucket requests
  253. totalS3HeadBucket = promauto.NewCounter(prometheus.CounterOpts{
  254. Name: "sftpgo_s3_head_bucket",
  255. Help: "The total number of successful S3 head bucket requests",
  256. })
  257. // totalS3HeadBucketErrors is the metric that reports the total S3 head bucket errors
  258. totalS3HeadBucketErrors = promauto.NewCounter(prometheus.CounterOpts{
  259. Name: "sftpgo_s3_head_bucket_errors",
  260. Help: "The total number of S3 head bucket errors",
  261. })
  262. // totalGCSUploads is the metric that reports the total number of successful GCS uploads
  263. totalGCSUploads = promauto.NewCounter(prometheus.CounterOpts{
  264. Name: "sftpgo_gcs_uploads_total",
  265. Help: "The total number of successful GCS uploads",
  266. })
  267. // totalGCSDownloads is the metric that reports the total number of successful GCS downloads
  268. totalGCSDownloads = promauto.NewCounter(prometheus.CounterOpts{
  269. Name: "sftpgo_gcs_downloads_total",
  270. Help: "The total number of successful GCS downloads",
  271. })
  272. // totalGCSUploadErrors is the metric that reports the total number of GCS upload errors
  273. totalGCSUploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  274. Name: "sftpgo_gcs_upload_errors_total",
  275. Help: "The total number of GCS upload errors",
  276. })
  277. // totalGCSDownloadErrors is the metric that reports the total number of GCS download errors
  278. totalGCSDownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  279. Name: "sftpgo_gcs_download_errors_total",
  280. Help: "The total number of GCS download errors",
  281. })
  282. // totalGCSUploadSize is the metric that reports the total GCS uploads size as bytes
  283. totalGCSUploadSize = promauto.NewCounter(prometheus.CounterOpts{
  284. Name: "sftpgo_gcs_upload_size",
  285. Help: "The total GCS upload size as bytes, partial uploads are included",
  286. })
  287. // totalGCSDownloadSize is the metric that reports the total GCS downloads size as bytes
  288. totalGCSDownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  289. Name: "sftpgo_gcs_download_size",
  290. Help: "The total GCS download size as bytes, partial downloads are included",
  291. })
  292. // totalS3ListObjects is the metric that reports the total successful GCS list objects requests
  293. totalGCSListObjects = promauto.NewCounter(prometheus.CounterOpts{
  294. Name: "sftpgo_gcs_list_objects",
  295. Help: "The total number of successful GCS list objects requests",
  296. })
  297. // totalGCSCopyObject is the metric that reports the total successful GCS copy object requests
  298. totalGCSCopyObject = promauto.NewCounter(prometheus.CounterOpts{
  299. Name: "sftpgo_gcs_copy_object",
  300. Help: "The total number of successful GCS copy object requests",
  301. })
  302. // totalGCSDeleteObject is the metric that reports the total successful S3 delete object requests
  303. totalGCSDeleteObject = promauto.NewCounter(prometheus.CounterOpts{
  304. Name: "sftpgo_gcs_delete_object",
  305. Help: "The total number of successful GCS delete object requests",
  306. })
  307. // totalGCSListObjectsError is the metric that reports the total GCS list objects errors
  308. totalGCSListObjectsErrors = promauto.NewCounter(prometheus.CounterOpts{
  309. Name: "sftpgo_gcs_list_objects_errors",
  310. Help: "The total number of GCS list objects errors",
  311. })
  312. // totalGCSCopyObjectErrors is the metric that reports the total GCS copy object errors
  313. totalGCSCopyObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  314. Name: "sftpgo_gcs_copy_object_errors",
  315. Help: "The total number of GCS copy object errors",
  316. })
  317. // totalGCSDeleteObjectErrors is the metric that reports the total GCS delete object errors
  318. totalGCSDeleteObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  319. Name: "sftpgo_gcs_delete_object_errors",
  320. Help: "The total number of GCS delete object errors",
  321. })
  322. // totalGCSHeadBucket is the metric that reports the total successful GCS head bucket requests
  323. totalGCSHeadBucket = promauto.NewCounter(prometheus.CounterOpts{
  324. Name: "sftpgo_gcs_head_bucket",
  325. Help: "The total number of successful GCS head bucket requests",
  326. })
  327. // totalGCSHeadBucketErrors is the metric that reports the total GCS head bucket errors
  328. totalGCSHeadBucketErrors = promauto.NewCounter(prometheus.CounterOpts{
  329. Name: "sftpgo_gcs_head_bucket_errors",
  330. Help: "The total number of GCS head bucket errors",
  331. })
  332. )
  333. // AddMetricsEndpoint exposes metrics to the specified endpoint
  334. func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
  335. handler.Handle(metricsPath, promhttp.Handler())
  336. }
  337. // TransferCompleted updates metrics after an upload or a download
  338. func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error) {
  339. if transferKind == 0 {
  340. // upload
  341. if err == nil {
  342. totalUploads.Inc()
  343. } else {
  344. totalUploadErrors.Inc()
  345. }
  346. totalUploadSize.Add(float64(bytesReceived))
  347. } else {
  348. // download
  349. if err == nil {
  350. totalDownloads.Inc()
  351. } else {
  352. totalDownloadErrors.Inc()
  353. }
  354. totalDownloadSize.Add(float64(bytesSent))
  355. }
  356. }
  357. // S3TransferCompleted updates metrics after an S3 upload or a download
  358. func S3TransferCompleted(bytes int64, transferKind int, err error) {
  359. if transferKind == 0 {
  360. // upload
  361. if err == nil {
  362. totalS3Uploads.Inc()
  363. } else {
  364. totalS3UploadErrors.Inc()
  365. }
  366. totalS3UploadSize.Add(float64(bytes))
  367. } else {
  368. // download
  369. if err == nil {
  370. totalS3Downloads.Inc()
  371. } else {
  372. totalS3DownloadErrors.Inc()
  373. }
  374. totalS3DownloadSize.Add(float64(bytes))
  375. }
  376. }
  377. // S3ListObjectsCompleted updates metrics after an S3 list objects request terminates
  378. func S3ListObjectsCompleted(err error) {
  379. if err == nil {
  380. totalS3ListObjects.Inc()
  381. } else {
  382. totalS3ListObjectsErrors.Inc()
  383. }
  384. }
  385. // S3CopyObjectCompleted updates metrics after an S3 copy object request terminates
  386. func S3CopyObjectCompleted(err error) {
  387. if err == nil {
  388. totalS3CopyObject.Inc()
  389. } else {
  390. totalS3CopyObjectErrors.Inc()
  391. }
  392. }
  393. // S3DeleteObjectCompleted updates metrics after an S3 delete object request terminates
  394. func S3DeleteObjectCompleted(err error) {
  395. if err == nil {
  396. totalS3DeleteObject.Inc()
  397. } else {
  398. totalS3DeleteObjectErrors.Inc()
  399. }
  400. }
  401. // S3HeadBucketCompleted updates metrics after an S3 head bucket request terminates
  402. func S3HeadBucketCompleted(err error) {
  403. if err == nil {
  404. totalS3HeadBucket.Inc()
  405. } else {
  406. totalS3HeadBucketErrors.Inc()
  407. }
  408. }
  409. // GCSTransferCompleted updates metrics after a GCS upload or a download
  410. func GCSTransferCompleted(bytes int64, transferKind int, err error) {
  411. if transferKind == 0 {
  412. // upload
  413. if err == nil {
  414. totalGCSUploads.Inc()
  415. } else {
  416. totalGCSUploadErrors.Inc()
  417. }
  418. totalGCSUploadSize.Add(float64(bytes))
  419. } else {
  420. // download
  421. if err == nil {
  422. totalGCSDownloads.Inc()
  423. } else {
  424. totalGCSDownloadErrors.Inc()
  425. }
  426. totalGCSDownloadSize.Add(float64(bytes))
  427. }
  428. }
  429. // GCSListObjectsCompleted updates metrics after a GCS list objects request terminates
  430. func GCSListObjectsCompleted(err error) {
  431. if err == nil {
  432. totalGCSListObjects.Inc()
  433. } else {
  434. totalGCSListObjectsErrors.Inc()
  435. }
  436. }
  437. // GCSCopyObjectCompleted updates metrics after a GCS copy object request terminates
  438. func GCSCopyObjectCompleted(err error) {
  439. if err == nil {
  440. totalGCSCopyObject.Inc()
  441. } else {
  442. totalGCSCopyObjectErrors.Inc()
  443. }
  444. }
  445. // GCSDeleteObjectCompleted updates metrics after a GCS delete object request terminates
  446. func GCSDeleteObjectCompleted(err error) {
  447. if err == nil {
  448. totalGCSDeleteObject.Inc()
  449. } else {
  450. totalGCSDeleteObjectErrors.Inc()
  451. }
  452. }
  453. // GCSHeadBucketCompleted updates metrics after a GCS head bucket request terminates
  454. func GCSHeadBucketCompleted(err error) {
  455. if err == nil {
  456. totalGCSHeadBucket.Inc()
  457. } else {
  458. totalGCSHeadBucketErrors.Inc()
  459. }
  460. }
  461. // SSHCommandCompleted update metrics after an SSH command terminates
  462. func SSHCommandCompleted(err error) {
  463. if err == nil {
  464. totalSSHCommands.Inc()
  465. } else {
  466. totalSSHCommandErrors.Inc()
  467. }
  468. }
  469. // UpdateDataProviderAvailability updates the metric for the data provider availability
  470. func UpdateDataProviderAvailability(err error) {
  471. if err == nil {
  472. dataproviderAvailability.Set(1)
  473. } else {
  474. dataproviderAvailability.Set(0)
  475. }
  476. }
  477. // AddLoginAttempt increments the metrics for login attempts
  478. func AddLoginAttempt(authMethod string) {
  479. totalLoginAttempts.Inc()
  480. switch authMethod {
  481. case loginMethodPublicKey:
  482. totalKeyLoginAttempts.Inc()
  483. case loginMethodKeyboardInteractive:
  484. totalInteractiveLoginAttempts.Inc()
  485. case loginMethodKeyAndPassword:
  486. totalKeyAndPasswordLoginAttempts.Inc()
  487. case loginMethodKeyAndKeyboardInt:
  488. totalKeyAndKeyIntLoginAttempts.Inc()
  489. default:
  490. totalPasswordLoginAttempts.Inc()
  491. }
  492. }
  493. // AddLoginResult increments the metrics for login results
  494. func AddLoginResult(authMethod string, err error) {
  495. if err == nil {
  496. totalLoginOK.Inc()
  497. switch authMethod {
  498. case loginMethodPublicKey:
  499. totalKeyLoginOK.Inc()
  500. case loginMethodKeyboardInteractive:
  501. totalInteractiveLoginOK.Inc()
  502. case loginMethodKeyAndPassword:
  503. totalKeyAndPasswordLoginOK.Inc()
  504. case loginMethodKeyAndKeyboardInt:
  505. totalKeyAndKeyIntLoginOK.Inc()
  506. default:
  507. totalPasswordLoginOK.Inc()
  508. }
  509. } else {
  510. totalLoginFailed.Inc()
  511. switch authMethod {
  512. case loginMethodPublicKey:
  513. totalKeyLoginFailed.Inc()
  514. case loginMethodKeyboardInteractive:
  515. totalInteractiveLoginFailed.Inc()
  516. case loginMethodKeyAndPassword:
  517. totalKeyAndPasswordLoginFailed.Inc()
  518. case loginMethodKeyAndKeyboardInt:
  519. totalKeyAndKeyIntLoginFailed.Inc()
  520. default:
  521. totalPasswordLoginFailed.Inc()
  522. }
  523. }
  524. }
  525. // HTTPRequestServed increments the metrics for HTTP requests
  526. func HTTPRequestServed(status int) {
  527. totalHTTPRequests.Inc()
  528. if status >= 200 && status < 300 {
  529. totalHTTPOK.Inc()
  530. } else if status >= 400 && status < 500 {
  531. totalHTTPClientErrors.Inc()
  532. } else if status >= 500 {
  533. totalHTTPServerErrors.Inc()
  534. }
  535. }
  536. // UpdateActiveConnectionsSize sets the metric for active connections
  537. func UpdateActiveConnectionsSize(size int) {
  538. activeConnections.Set(float64(size))
  539. }