metrics.go 23 KB

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