metrics.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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. // totalS3HeadObject is the metric that reports the total successful S3 head object requests
  259. totalS3HeadObject = promauto.NewCounter(prometheus.CounterOpts{
  260. Name: "sftpgo_s3_head_object",
  261. Help: "The total number of successful S3 head object requests",
  262. })
  263. // totalS3HeadObjectErrors is the metric that reports the total S3 head object errors
  264. totalS3HeadObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  265. Name: "sftpgo_s3_head_object_errors",
  266. Help: "The total number of S3 head object errors",
  267. })
  268. // totalS3HeadBucket is the metric that reports the total successful S3 head bucket requests
  269. totalS3HeadBucket = promauto.NewCounter(prometheus.CounterOpts{
  270. Name: "sftpgo_s3_head_bucket",
  271. Help: "The total number of successful S3 head bucket requests",
  272. })
  273. // totalS3HeadBucketErrors is the metric that reports the total S3 head bucket errors
  274. totalS3HeadBucketErrors = promauto.NewCounter(prometheus.CounterOpts{
  275. Name: "sftpgo_s3_head_bucket_errors",
  276. Help: "The total number of S3 head bucket errors",
  277. })
  278. // totalGCSUploads is the metric that reports the total number of successful GCS uploads
  279. totalGCSUploads = promauto.NewCounter(prometheus.CounterOpts{
  280. Name: "sftpgo_gcs_uploads_total",
  281. Help: "The total number of successful GCS uploads",
  282. })
  283. // totalGCSDownloads is the metric that reports the total number of successful GCS downloads
  284. totalGCSDownloads = promauto.NewCounter(prometheus.CounterOpts{
  285. Name: "sftpgo_gcs_downloads_total",
  286. Help: "The total number of successful GCS downloads",
  287. })
  288. // totalGCSUploadErrors is the metric that reports the total number of GCS upload errors
  289. totalGCSUploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  290. Name: "sftpgo_gcs_upload_errors_total",
  291. Help: "The total number of GCS upload errors",
  292. })
  293. // totalGCSDownloadErrors is the metric that reports the total number of GCS download errors
  294. totalGCSDownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  295. Name: "sftpgo_gcs_download_errors_total",
  296. Help: "The total number of GCS download errors",
  297. })
  298. // totalGCSUploadSize is the metric that reports the total GCS uploads size as bytes
  299. totalGCSUploadSize = promauto.NewCounter(prometheus.CounterOpts{
  300. Name: "sftpgo_gcs_upload_size",
  301. Help: "The total GCS upload size as bytes, partial uploads are included",
  302. })
  303. // totalGCSDownloadSize is the metric that reports the total GCS downloads size as bytes
  304. totalGCSDownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  305. Name: "sftpgo_gcs_download_size",
  306. Help: "The total GCS download size as bytes, partial downloads are included",
  307. })
  308. // totalGCSListObjects is the metric that reports the total successful GCS list objects requests
  309. totalGCSListObjects = promauto.NewCounter(prometheus.CounterOpts{
  310. Name: "sftpgo_gcs_list_objects",
  311. Help: "The total number of successful GCS list objects requests",
  312. })
  313. // totalGCSCopyObject is the metric that reports the total successful GCS copy object requests
  314. totalGCSCopyObject = promauto.NewCounter(prometheus.CounterOpts{
  315. Name: "sftpgo_gcs_copy_object",
  316. Help: "The total number of successful GCS copy object requests",
  317. })
  318. // totalGCSDeleteObject is the metric that reports the total successful GCS delete object requests
  319. totalGCSDeleteObject = promauto.NewCounter(prometheus.CounterOpts{
  320. Name: "sftpgo_gcs_delete_object",
  321. Help: "The total number of successful GCS delete object requests",
  322. })
  323. // totalGCSListObjectsError is the metric that reports the total GCS list objects errors
  324. totalGCSListObjectsErrors = promauto.NewCounter(prometheus.CounterOpts{
  325. Name: "sftpgo_gcs_list_objects_errors",
  326. Help: "The total number of GCS list objects errors",
  327. })
  328. // totalGCSCopyObjectErrors is the metric that reports the total GCS copy object errors
  329. totalGCSCopyObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  330. Name: "sftpgo_gcs_copy_object_errors",
  331. Help: "The total number of GCS copy object errors",
  332. })
  333. // totalGCSDeleteObjectErrors is the metric that reports the total GCS delete object errors
  334. totalGCSDeleteObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  335. Name: "sftpgo_gcs_delete_object_errors",
  336. Help: "The total number of GCS delete object errors",
  337. })
  338. // totalGCSHeadObject is the metric that reports the total successful GCS head object requests
  339. totalGCSHeadObject = promauto.NewCounter(prometheus.CounterOpts{
  340. Name: "sftpgo_gcs_head_object",
  341. Help: "The total number of successful GCS head object requests",
  342. })
  343. // totalGCSHeadObjectErrors is the metric that reports the total GCS head object errors
  344. totalGCSHeadObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  345. Name: "sftpgo_gcs_head_object_errors",
  346. Help: "The total number of GCS head object errors",
  347. })
  348. // totalGCSHeadBucket is the metric that reports the total successful GCS head bucket requests
  349. totalGCSHeadBucket = promauto.NewCounter(prometheus.CounterOpts{
  350. Name: "sftpgo_gcs_head_bucket",
  351. Help: "The total number of successful GCS head bucket requests",
  352. })
  353. // totalGCSHeadBucketErrors is the metric that reports the total GCS head bucket errors
  354. totalGCSHeadBucketErrors = promauto.NewCounter(prometheus.CounterOpts{
  355. Name: "sftpgo_gcs_head_bucket_errors",
  356. Help: "The total number of GCS head bucket errors",
  357. })
  358. // totalAZUploads is the metric that reports the total number of successful Azure uploads
  359. totalAZUploads = promauto.NewCounter(prometheus.CounterOpts{
  360. Name: "sftpgo_az_uploads_total",
  361. Help: "The total number of successful Azure uploads",
  362. })
  363. // totalAZDownloads is the metric that reports the total number of successful Azure downloads
  364. totalAZDownloads = promauto.NewCounter(prometheus.CounterOpts{
  365. Name: "sftpgo_az_downloads_total",
  366. Help: "The total number of successful Azure downloads",
  367. })
  368. // totalAZUploadErrors is the metric that reports the total number of Azure upload errors
  369. totalAZUploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  370. Name: "sftpgo_az_upload_errors_total",
  371. Help: "The total number of Azure upload errors",
  372. })
  373. // totalAZDownloadErrors is the metric that reports the total number of Azure download errors
  374. totalAZDownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  375. Name: "sftpgo_az_download_errors_total",
  376. Help: "The total number of Azure download errors",
  377. })
  378. // totalAZUploadSize is the metric that reports the total Azure uploads size as bytes
  379. totalAZUploadSize = promauto.NewCounter(prometheus.CounterOpts{
  380. Name: "sftpgo_az_upload_size",
  381. Help: "The total Azure upload size as bytes, partial uploads are included",
  382. })
  383. // totalAZDownloadSize is the metric that reports the total Azure downloads size as bytes
  384. totalAZDownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  385. Name: "sftpgo_az_download_size",
  386. Help: "The total Azure download size as bytes, partial downloads are included",
  387. })
  388. // totalAZListObjects is the metric that reports the total successful Azure list objects requests
  389. totalAZListObjects = promauto.NewCounter(prometheus.CounterOpts{
  390. Name: "sftpgo_az_list_objects",
  391. Help: "The total number of successful Azure list objects requests",
  392. })
  393. // totalAZCopyObject is the metric that reports the total successful Azure copy object requests
  394. totalAZCopyObject = promauto.NewCounter(prometheus.CounterOpts{
  395. Name: "sftpgo_az_copy_object",
  396. Help: "The total number of successful Azure copy object requests",
  397. })
  398. // totalAZDeleteObject is the metric that reports the total successful Azure delete object requests
  399. totalAZDeleteObject = promauto.NewCounter(prometheus.CounterOpts{
  400. Name: "sftpgo_az_delete_object",
  401. Help: "The total number of successful Azure delete object requests",
  402. })
  403. // totalAZListObjectsError is the metric that reports the total Azure list objects errors
  404. totalAZListObjectsErrors = promauto.NewCounter(prometheus.CounterOpts{
  405. Name: "sftpgo_az_list_objects_errors",
  406. Help: "The total number of Azure list objects errors",
  407. })
  408. // totalAZCopyObjectErrors is the metric that reports the total Azure copy object errors
  409. totalAZCopyObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  410. Name: "sftpgo_az_copy_object_errors",
  411. Help: "The total number of Azure copy object errors",
  412. })
  413. // totalAZDeleteObjectErrors is the metric that reports the total Azure delete object errors
  414. totalAZDeleteObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  415. Name: "sftpgo_az_delete_object_errors",
  416. Help: "The total number of Azure delete object errors",
  417. })
  418. // totalAZHeadObject is the metric that reports the total successful Azure head object requests
  419. totalAZHeadObject = promauto.NewCounter(prometheus.CounterOpts{
  420. Name: "sftpgo_az_head_object",
  421. Help: "The total number of successful Azure head object requests",
  422. })
  423. // totalAZHeadObjectErrors is the metric that reports the total Azure head object errors
  424. totalAZHeadObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  425. Name: "sftpgo_az_head_object_errors",
  426. Help: "The total number of Azure head object errors",
  427. })
  428. // totalAZHeadContainer is the metric that reports the total successful Azure head container requests
  429. totalAZHeadContainer = promauto.NewCounter(prometheus.CounterOpts{
  430. Name: "sftpgo_az_head_container",
  431. Help: "The total number of successful Azure head container requests",
  432. })
  433. // totalAZHeadContainerErrors is the metric that reports the total Azure head container errors
  434. totalAZHeadContainerErrors = promauto.NewCounter(prometheus.CounterOpts{
  435. Name: "sftpgo_az_head_container_errors",
  436. Help: "The total number of Azure head container errors",
  437. })
  438. )
  439. // AddMetricsEndpoint exposes metrics to the specified endpoint
  440. func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
  441. handler.Handle(metricsPath, promhttp.Handler())
  442. }
  443. // TransferCompleted updates metrics after an upload or a download
  444. func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error) {
  445. if transferKind == 0 {
  446. // upload
  447. if err == nil {
  448. totalUploads.Inc()
  449. } else {
  450. totalUploadErrors.Inc()
  451. }
  452. totalUploadSize.Add(float64(bytesReceived))
  453. } else {
  454. // download
  455. if err == nil {
  456. totalDownloads.Inc()
  457. } else {
  458. totalDownloadErrors.Inc()
  459. }
  460. totalDownloadSize.Add(float64(bytesSent))
  461. }
  462. }
  463. // S3TransferCompleted updates metrics after an S3 upload or a download
  464. func S3TransferCompleted(bytes int64, transferKind int, err error) {
  465. if transferKind == 0 {
  466. // upload
  467. if err == nil {
  468. totalS3Uploads.Inc()
  469. } else {
  470. totalS3UploadErrors.Inc()
  471. }
  472. totalS3UploadSize.Add(float64(bytes))
  473. } else {
  474. // download
  475. if err == nil {
  476. totalS3Downloads.Inc()
  477. } else {
  478. totalS3DownloadErrors.Inc()
  479. }
  480. totalS3DownloadSize.Add(float64(bytes))
  481. }
  482. }
  483. // S3ListObjectsCompleted updates metrics after an S3 list objects request terminates
  484. func S3ListObjectsCompleted(err error) {
  485. if err == nil {
  486. totalS3ListObjects.Inc()
  487. } else {
  488. totalS3ListObjectsErrors.Inc()
  489. }
  490. }
  491. // S3CopyObjectCompleted updates metrics after an S3 copy object request terminates
  492. func S3CopyObjectCompleted(err error) {
  493. if err == nil {
  494. totalS3CopyObject.Inc()
  495. } else {
  496. totalS3CopyObjectErrors.Inc()
  497. }
  498. }
  499. // S3DeleteObjectCompleted updates metrics after an S3 delete object request terminates
  500. func S3DeleteObjectCompleted(err error) {
  501. if err == nil {
  502. totalS3DeleteObject.Inc()
  503. } else {
  504. totalS3DeleteObjectErrors.Inc()
  505. }
  506. }
  507. // S3HeadObjectCompleted updates metrics after a S3 head object request terminates
  508. func S3HeadObjectCompleted(err error) {
  509. if err == nil {
  510. totalS3HeadObject.Inc()
  511. } else {
  512. totalS3HeadObjectErrors.Inc()
  513. }
  514. }
  515. // S3HeadBucketCompleted updates metrics after a S3 head bucket request terminates
  516. func S3HeadBucketCompleted(err error) {
  517. if err == nil {
  518. totalS3HeadBucket.Inc()
  519. } else {
  520. totalS3HeadBucketErrors.Inc()
  521. }
  522. }
  523. // GCSTransferCompleted updates metrics after a GCS upload or a download
  524. func GCSTransferCompleted(bytes int64, transferKind int, err error) {
  525. if transferKind == 0 {
  526. // upload
  527. if err == nil {
  528. totalGCSUploads.Inc()
  529. } else {
  530. totalGCSUploadErrors.Inc()
  531. }
  532. totalGCSUploadSize.Add(float64(bytes))
  533. } else {
  534. // download
  535. if err == nil {
  536. totalGCSDownloads.Inc()
  537. } else {
  538. totalGCSDownloadErrors.Inc()
  539. }
  540. totalGCSDownloadSize.Add(float64(bytes))
  541. }
  542. }
  543. // GCSListObjectsCompleted updates metrics after a GCS list objects request terminates
  544. func GCSListObjectsCompleted(err error) {
  545. if err == nil {
  546. totalGCSListObjects.Inc()
  547. } else {
  548. totalGCSListObjectsErrors.Inc()
  549. }
  550. }
  551. // GCSCopyObjectCompleted updates metrics after a GCS copy object request terminates
  552. func GCSCopyObjectCompleted(err error) {
  553. if err == nil {
  554. totalGCSCopyObject.Inc()
  555. } else {
  556. totalGCSCopyObjectErrors.Inc()
  557. }
  558. }
  559. // GCSDeleteObjectCompleted updates metrics after a GCS delete object request terminates
  560. func GCSDeleteObjectCompleted(err error) {
  561. if err == nil {
  562. totalGCSDeleteObject.Inc()
  563. } else {
  564. totalGCSDeleteObjectErrors.Inc()
  565. }
  566. }
  567. // GCSHeadObjectCompleted updates metrics after a GCS head object request terminates
  568. func GCSHeadObjectCompleted(err error) {
  569. if err == nil {
  570. totalGCSHeadObject.Inc()
  571. } else {
  572. totalGCSHeadObjectErrors.Inc()
  573. }
  574. }
  575. // GCSHeadBucketCompleted updates metrics after a GCS head bucket request terminates
  576. func GCSHeadBucketCompleted(err error) {
  577. if err == nil {
  578. totalGCSHeadBucket.Inc()
  579. } else {
  580. totalGCSHeadBucketErrors.Inc()
  581. }
  582. }
  583. // AZTransferCompleted updates metrics after a Azure upload or a download
  584. func AZTransferCompleted(bytes int64, transferKind int, err error) {
  585. if transferKind == 0 {
  586. // upload
  587. if err == nil {
  588. totalAZUploads.Inc()
  589. } else {
  590. totalAZUploadErrors.Inc()
  591. }
  592. totalAZUploadSize.Add(float64(bytes))
  593. } else {
  594. // download
  595. if err == nil {
  596. totalAZDownloads.Inc()
  597. } else {
  598. totalAZDownloadErrors.Inc()
  599. }
  600. totalAZDownloadSize.Add(float64(bytes))
  601. }
  602. }
  603. // AZListObjectsCompleted updates metrics after a Azure list objects request terminates
  604. func AZListObjectsCompleted(err error) {
  605. if err == nil {
  606. totalAZListObjects.Inc()
  607. } else {
  608. totalAZListObjectsErrors.Inc()
  609. }
  610. }
  611. // AZCopyObjectCompleted updates metrics after a Azure copy object request terminates
  612. func AZCopyObjectCompleted(err error) {
  613. if err == nil {
  614. totalAZCopyObject.Inc()
  615. } else {
  616. totalAZCopyObjectErrors.Inc()
  617. }
  618. }
  619. // AZDeleteObjectCompleted updates metrics after a Azure delete object request terminates
  620. func AZDeleteObjectCompleted(err error) {
  621. if err == nil {
  622. totalAZDeleteObject.Inc()
  623. } else {
  624. totalAZDeleteObjectErrors.Inc()
  625. }
  626. }
  627. // AZHeadObjectCompleted updates metrics after a Azure head object request terminates
  628. func AZHeadObjectCompleted(err error) {
  629. if err == nil {
  630. totalAZHeadObject.Inc()
  631. } else {
  632. totalAZHeadObjectErrors.Inc()
  633. }
  634. }
  635. // AZHeadContainerCompleted updates metrics after a Azure head container request terminates
  636. func AZHeadContainerCompleted(err error) {
  637. if err == nil {
  638. totalAZHeadContainer.Inc()
  639. } else {
  640. totalAZHeadContainerErrors.Inc()
  641. }
  642. }
  643. // SSHCommandCompleted update metrics after an SSH command terminates
  644. func SSHCommandCompleted(err error) {
  645. if err == nil {
  646. totalSSHCommands.Inc()
  647. } else {
  648. totalSSHCommandErrors.Inc()
  649. }
  650. }
  651. // UpdateDataProviderAvailability updates the metric for the data provider availability
  652. func UpdateDataProviderAvailability(err error) {
  653. if err == nil {
  654. dataproviderAvailability.Set(1)
  655. } else {
  656. dataproviderAvailability.Set(0)
  657. }
  658. }
  659. // AddLoginAttempt increments the metrics for login attempts
  660. func AddLoginAttempt(authMethod string) {
  661. totalLoginAttempts.Inc()
  662. switch authMethod {
  663. case loginMethodPublicKey:
  664. totalKeyLoginAttempts.Inc()
  665. case loginMethodKeyboardInteractive:
  666. totalInteractiveLoginAttempts.Inc()
  667. case loginMethodKeyAndPassword:
  668. totalKeyAndPasswordLoginAttempts.Inc()
  669. case loginMethodKeyAndKeyboardInt:
  670. totalKeyAndKeyIntLoginAttempts.Inc()
  671. default:
  672. totalPasswordLoginAttempts.Inc()
  673. }
  674. }
  675. // AddLoginResult increments the metrics for login results
  676. func AddLoginResult(authMethod string, err error) {
  677. if err == nil {
  678. totalLoginOK.Inc()
  679. switch authMethod {
  680. case loginMethodPublicKey:
  681. totalKeyLoginOK.Inc()
  682. case loginMethodKeyboardInteractive:
  683. totalInteractiveLoginOK.Inc()
  684. case loginMethodKeyAndPassword:
  685. totalKeyAndPasswordLoginOK.Inc()
  686. case loginMethodKeyAndKeyboardInt:
  687. totalKeyAndKeyIntLoginOK.Inc()
  688. default:
  689. totalPasswordLoginOK.Inc()
  690. }
  691. } else {
  692. totalLoginFailed.Inc()
  693. switch authMethod {
  694. case loginMethodPublicKey:
  695. totalKeyLoginFailed.Inc()
  696. case loginMethodKeyboardInteractive:
  697. totalInteractiveLoginFailed.Inc()
  698. case loginMethodKeyAndPassword:
  699. totalKeyAndPasswordLoginFailed.Inc()
  700. case loginMethodKeyAndKeyboardInt:
  701. totalKeyAndKeyIntLoginFailed.Inc()
  702. default:
  703. totalPasswordLoginFailed.Inc()
  704. }
  705. }
  706. }
  707. // AddNoAuthTryed increments the metric for clients disconnected
  708. // for inactivity before trying to login
  709. func AddNoAuthTryed() {
  710. totalNoAuthTryed.Inc()
  711. }
  712. // HTTPRequestServed increments the metrics for HTTP requests
  713. func HTTPRequestServed(status int) {
  714. totalHTTPRequests.Inc()
  715. if status >= 200 && status < 300 {
  716. totalHTTPOK.Inc()
  717. } else if status >= 400 && status < 500 {
  718. totalHTTPClientErrors.Inc()
  719. } else if status >= 500 {
  720. totalHTTPServerErrors.Inc()
  721. }
  722. }
  723. // UpdateActiveConnectionsSize sets the metric for active connections
  724. func UpdateActiveConnectionsSize(size int) {
  725. activeConnections.Set(float64(size))
  726. }