metrics.go 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. // +build !nometrics
  2. // Package metrics provides Prometheus metrics support
  3. package metrics
  4. import (
  5. "github.com/go-chi/chi/v5"
  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/v2/version"
  10. )
  11. const (
  12. loginMethodPublicKey = "publickey"
  13. loginMethodKeyboardInteractive = "keyboard-interactive"
  14. loginMethodKeyAndPassword = "publickey+password"
  15. loginMethodKeyAndKeyboardInt = "publickey+keyboard-interactive"
  16. loginMethodTLSCertificate = "TLSCertificate"
  17. loginMethodTLSCertificateAndPwd = "TLSCertificate+password"
  18. )
  19. func init() {
  20. version.AddFeature("+metrics")
  21. }
  22. var (
  23. // dataproviderAvailability is the metric that reports the availability for the configured data provider
  24. dataproviderAvailability = promauto.NewGauge(prometheus.GaugeOpts{
  25. Name: "sftpgo_dataprovider_availability",
  26. Help: "Availability for the configured data provider, 1 means OK, 0 KO",
  27. })
  28. // activeConnections is the metric that reports the total number of active connections
  29. activeConnections = promauto.NewGauge(prometheus.GaugeOpts{
  30. Name: "sftpgo_active_connections",
  31. Help: "Total number of logged in users",
  32. })
  33. // totalUploads is the metric that reports the total number of successful uploads
  34. totalUploads = promauto.NewCounter(prometheus.CounterOpts{
  35. Name: "sftpgo_uploads_total",
  36. Help: "The total number of successful uploads",
  37. })
  38. // totalDownloads is the metric that reports the total number of successful downloads
  39. totalDownloads = promauto.NewCounter(prometheus.CounterOpts{
  40. Name: "sftpgo_downloads_total",
  41. Help: "The total number of successful downloads",
  42. })
  43. // totalUploadErrors is the metric that reports the total number of upload errors
  44. totalUploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  45. Name: "sftpgo_upload_errors_total",
  46. Help: "The total number of upload errors",
  47. })
  48. // totalDownloadErrors is the metric that reports the total number of download errors
  49. totalDownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  50. Name: "sftpgo_download_errors_total",
  51. Help: "The total number of download errors",
  52. })
  53. // totalUploadSize is the metric that reports the total uploads size as bytes
  54. totalUploadSize = promauto.NewCounter(prometheus.CounterOpts{
  55. Name: "sftpgo_upload_size",
  56. Help: "The total upload size as bytes, partial uploads are included",
  57. })
  58. // totalDownloadSize is the metric that reports the total downloads size as bytes
  59. totalDownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  60. Name: "sftpgo_download_size",
  61. Help: "The total download size as bytes, partial downloads are included",
  62. })
  63. // totalSSHCommands is the metric that reports the total number of executed SSH commands
  64. totalSSHCommands = promauto.NewCounter(prometheus.CounterOpts{
  65. Name: "sftpgo_ssh_commands_total",
  66. Help: "The total number of executed SSH commands",
  67. })
  68. // totalSSHCommandErrors is the metric that reports the total number of SSH command errors
  69. totalSSHCommandErrors = promauto.NewCounter(prometheus.CounterOpts{
  70. Name: "sftpgo_ssh_command_errors_total",
  71. Help: "The total number of SSH command errors",
  72. })
  73. // totalLoginAttempts is the metric that reports the total number of login attempts
  74. totalLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  75. Name: "sftpgo_login_attempts_total",
  76. Help: "The total number of login attempts",
  77. })
  78. // totalNoAuthTryed is te metric that reports the total number of clients disconnected
  79. // for inactivity before trying to login
  80. totalNoAuthTryed = promauto.NewCounter(prometheus.CounterOpts{
  81. Name: "sftpgo_no_auth_total",
  82. Help: "The total number of clients disconnected for inactivity before trying to login",
  83. })
  84. // totalLoginOK is the metric that reports the total number of successful logins
  85. totalLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  86. Name: "sftpgo_login_ok_total",
  87. Help: "The total number of successful logins",
  88. })
  89. // totalLoginFailed is the metric that reports the total number of failed logins
  90. totalLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  91. Name: "sftpgo_login_ko_total",
  92. Help: "The total number of failed logins",
  93. })
  94. // totalPasswordLoginAttempts is the metric that reports the total number of login attempts
  95. // using a password
  96. totalPasswordLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  97. Name: "sftpgo_password_login_attempts_total",
  98. Help: "The total number of login attempts using a password",
  99. })
  100. // totalPasswordLoginOK is the metric that reports the total number of successful logins
  101. // using a password
  102. totalPasswordLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  103. Name: "sftpgo_password_login_ok_total",
  104. Help: "The total number of successful logins using a password",
  105. })
  106. // totalPasswordLoginFailed is the metric that reports the total number of failed logins
  107. // using a password
  108. totalPasswordLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  109. Name: "sftpgo_password_login_ko_total",
  110. Help: "The total number of failed logins using a password",
  111. })
  112. // totalKeyLoginAttempts is the metric that reports the total number of login attempts
  113. // using a public key
  114. totalKeyLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  115. Name: "sftpgo_public_key_login_attempts_total",
  116. Help: "The total number of login attempts using a public key",
  117. })
  118. // totalKeyLoginOK is the metric that reports the total number of successful logins
  119. // using a public key
  120. totalKeyLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  121. Name: "sftpgo_public_key_login_ok_total",
  122. Help: "The total number of successful logins using a public key",
  123. })
  124. // totalKeyLoginFailed is the metric that reports the total number of failed logins
  125. // using a public key
  126. totalKeyLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  127. Name: "sftpgo_public_key_login_ko_total",
  128. Help: "The total number of failed logins using a public key",
  129. })
  130. // totalTLSCertLoginAttempts is the metric that reports the total number of login attempts
  131. // using a TLS certificate
  132. totalTLSCertLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  133. Name: "sftpgo_tls_cert_login_attempts_total",
  134. Help: "The total number of login attempts using a TLS certificate",
  135. })
  136. // totalTLSCertLoginOK is the metric that reports the total number of successful logins
  137. // using a TLS certificate
  138. totalTLSCertLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  139. Name: "sftpgo_tls_cert_login_ok_total",
  140. Help: "The total number of successful logins using a TLS certificate",
  141. })
  142. // totalTLSCertLoginFailed is the metric that reports the total number of failed logins
  143. // using a TLS certificate
  144. totalTLSCertLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  145. Name: "sftpgo_tls_cert_login_ko_total",
  146. Help: "The total number of failed logins using a TLS certificate",
  147. })
  148. // totalTLSCertAndPwdLoginAttempts is the metric that reports the total number of login attempts
  149. // using a TLS certificate+password
  150. totalTLSCertAndPwdLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  151. Name: "sftpgo_tls_cert_and_pwd_login_attempts_total",
  152. Help: "The total number of login attempts using a TLS certificate+password",
  153. })
  154. // totalTLSCertLoginOK is the metric that reports the total number of successful logins
  155. // using a TLS certificate+password
  156. totalTLSCertAndPwdLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  157. Name: "sftpgo_tls_cert_and_pwd_login_ok_total",
  158. Help: "The total number of successful logins using a TLS certificate+password",
  159. })
  160. // totalTLSCertAndPwdLoginFailed is the metric that reports the total number of failed logins
  161. // using a TLS certificate+password
  162. totalTLSCertAndPwdLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  163. Name: "sftpgo_tls_cert_and_pwd_login_ko_total",
  164. Help: "The total number of failed logins using a TLS certificate+password",
  165. })
  166. // totalInteractiveLoginAttempts is the metric that reports the total number of login attempts
  167. // using keyboard interactive authentication
  168. totalInteractiveLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  169. Name: "sftpgo_keyboard_interactive_login_attempts_total",
  170. Help: "The total number of login attempts using keyboard interactive authentication",
  171. })
  172. // totalInteractiveLoginOK is the metric that reports the total number of successful logins
  173. // using keyboard interactive authentication
  174. totalInteractiveLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  175. Name: "sftpgo_keyboard_interactive_login_ok_total",
  176. Help: "The total number of successful logins using keyboard interactive authentication",
  177. })
  178. // totalInteractiveLoginFailed is the metric that reports the total number of failed logins
  179. // using keyboard interactive authentication
  180. totalInteractiveLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  181. Name: "sftpgo_keyboard_interactive_login_ko_total",
  182. Help: "The total number of failed logins using keyboard interactive authentication",
  183. })
  184. // totalKeyAndPasswordLoginAttempts is the metric that reports the total number of
  185. // login attempts using public key + password multi steps auth
  186. totalKeyAndPasswordLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  187. Name: "sftpgo_key_and_password_login_attempts_total",
  188. Help: "The total number of login attempts using public key + password",
  189. })
  190. // totalKeyAndPasswordLoginOK is the metric that reports the total number of
  191. // successful logins using public key + password multi steps auth
  192. totalKeyAndPasswordLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  193. Name: "sftpgo_key_and_password_login_ok_total",
  194. Help: "The total number of successful logins using public key + password",
  195. })
  196. // totalKeyAndPasswordLoginFailed is the metric that reports the total number of
  197. // failed logins using public key + password multi steps auth
  198. totalKeyAndPasswordLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  199. Name: "sftpgo_key_and_password_login_ko_total",
  200. Help: "The total number of failed logins using public key + password",
  201. })
  202. // totalKeyAndKeyIntLoginAttempts is the metric that reports the total number of
  203. // login attempts using public key + keyboard interactive multi steps auth
  204. totalKeyAndKeyIntLoginAttempts = promauto.NewCounter(prometheus.CounterOpts{
  205. Name: "sftpgo_key_and_keyboard_int_login_attempts_total",
  206. Help: "The total number of login attempts using public key + keyboard interactive",
  207. })
  208. // totalKeyAndKeyIntLoginOK is the metric that reports the total number of
  209. // successful logins using public key + keyboard interactive multi steps auth
  210. totalKeyAndKeyIntLoginOK = promauto.NewCounter(prometheus.CounterOpts{
  211. Name: "sftpgo_key_and_keyboard_int_login_ok_total",
  212. Help: "The total number of successful logins using public key + keyboard interactive",
  213. })
  214. // totalKeyAndKeyIntLoginFailed is the metric that reports the total number of
  215. // failed logins using public key + keyboard interactive multi steps auth
  216. totalKeyAndKeyIntLoginFailed = promauto.NewCounter(prometheus.CounterOpts{
  217. Name: "sftpgo_key_and_keyboard_int_login_ko_total",
  218. Help: "The total number of failed logins using public key + keyboard interactive",
  219. })
  220. totalHTTPRequests = promauto.NewCounter(prometheus.CounterOpts{
  221. Name: "sftpgo_http_req_total",
  222. Help: "The total number of HTTP requests served",
  223. })
  224. totalHTTPOK = promauto.NewCounter(prometheus.CounterOpts{
  225. Name: "sftpgo_http_req_ok_total",
  226. Help: "The total number of HTTP requests served with 2xx status code",
  227. })
  228. totalHTTPClientErrors = promauto.NewCounter(prometheus.CounterOpts{
  229. Name: "sftpgo_http_client_errors_total",
  230. Help: "The total number of HTTP requests served with 4xx status code",
  231. })
  232. totalHTTPServerErrors = promauto.NewCounter(prometheus.CounterOpts{
  233. Name: "sftpgo_http_server_errors_total",
  234. Help: "The total number of HTTP requests served with 5xx status code",
  235. })
  236. // totalS3Uploads is the metric that reports the total number of successful S3 uploads
  237. totalS3Uploads = promauto.NewCounter(prometheus.CounterOpts{
  238. Name: "sftpgo_s3_uploads_total",
  239. Help: "The total number of successful S3 uploads",
  240. })
  241. // totalS3Downloads is the metric that reports the total number of successful S3 downloads
  242. totalS3Downloads = promauto.NewCounter(prometheus.CounterOpts{
  243. Name: "sftpgo_s3_downloads_total",
  244. Help: "The total number of successful S3 downloads",
  245. })
  246. // totalS3UploadErrors is the metric that reports the total number of S3 upload errors
  247. totalS3UploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  248. Name: "sftpgo_s3_upload_errors_total",
  249. Help: "The total number of S3 upload errors",
  250. })
  251. // totalS3DownloadErrors is the metric that reports the total number of S3 download errors
  252. totalS3DownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  253. Name: "sftpgo_s3_download_errors_total",
  254. Help: "The total number of S3 download errors",
  255. })
  256. // totalS3UploadSize is the metric that reports the total S3 uploads size as bytes
  257. totalS3UploadSize = promauto.NewCounter(prometheus.CounterOpts{
  258. Name: "sftpgo_s3_upload_size",
  259. Help: "The total S3 upload size as bytes, partial uploads are included",
  260. })
  261. // totalS3DownloadSize is the metric that reports the total S3 downloads size as bytes
  262. totalS3DownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  263. Name: "sftpgo_s3_download_size",
  264. Help: "The total S3 download size as bytes, partial downloads are included",
  265. })
  266. // totalS3ListObjects is the metric that reports the total successful S3 list objects requests
  267. totalS3ListObjects = promauto.NewCounter(prometheus.CounterOpts{
  268. Name: "sftpgo_s3_list_objects",
  269. Help: "The total number of successful S3 list objects requests",
  270. })
  271. // totalS3CopyObject is the metric that reports the total successful S3 copy object requests
  272. totalS3CopyObject = promauto.NewCounter(prometheus.CounterOpts{
  273. Name: "sftpgo_s3_copy_object",
  274. Help: "The total number of successful S3 copy object requests",
  275. })
  276. // totalS3DeleteObject is the metric that reports the total successful S3 delete object requests
  277. totalS3DeleteObject = promauto.NewCounter(prometheus.CounterOpts{
  278. Name: "sftpgo_s3_delete_object",
  279. Help: "The total number of successful S3 delete object requests",
  280. })
  281. // totalS3ListObjectsError is the metric that reports the total S3 list objects errors
  282. totalS3ListObjectsErrors = promauto.NewCounter(prometheus.CounterOpts{
  283. Name: "sftpgo_s3_list_objects_errors",
  284. Help: "The total number of S3 list objects errors",
  285. })
  286. // totalS3CopyObjectErrors is the metric that reports the total S3 copy object errors
  287. totalS3CopyObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  288. Name: "sftpgo_s3_copy_object_errors",
  289. Help: "The total number of S3 copy object errors",
  290. })
  291. // totalS3DeleteObjectErrors is the metric that reports the total S3 delete object errors
  292. totalS3DeleteObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  293. Name: "sftpgo_s3_delete_object_errors",
  294. Help: "The total number of S3 delete object errors",
  295. })
  296. // totalS3HeadObject is the metric that reports the total successful S3 head object requests
  297. totalS3HeadObject = promauto.NewCounter(prometheus.CounterOpts{
  298. Name: "sftpgo_s3_head_object",
  299. Help: "The total number of successful S3 head object requests",
  300. })
  301. // totalS3HeadObjectErrors is the metric that reports the total S3 head object errors
  302. totalS3HeadObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  303. Name: "sftpgo_s3_head_object_errors",
  304. Help: "The total number of S3 head object errors",
  305. })
  306. // totalS3HeadBucket is the metric that reports the total successful S3 head bucket requests
  307. totalS3HeadBucket = promauto.NewCounter(prometheus.CounterOpts{
  308. Name: "sftpgo_s3_head_bucket",
  309. Help: "The total number of successful S3 head bucket requests",
  310. })
  311. // totalS3HeadBucketErrors is the metric that reports the total S3 head bucket errors
  312. totalS3HeadBucketErrors = promauto.NewCounter(prometheus.CounterOpts{
  313. Name: "sftpgo_s3_head_bucket_errors",
  314. Help: "The total number of S3 head bucket errors",
  315. })
  316. // totalGCSUploads is the metric that reports the total number of successful GCS uploads
  317. totalGCSUploads = promauto.NewCounter(prometheus.CounterOpts{
  318. Name: "sftpgo_gcs_uploads_total",
  319. Help: "The total number of successful GCS uploads",
  320. })
  321. // totalGCSDownloads is the metric that reports the total number of successful GCS downloads
  322. totalGCSDownloads = promauto.NewCounter(prometheus.CounterOpts{
  323. Name: "sftpgo_gcs_downloads_total",
  324. Help: "The total number of successful GCS downloads",
  325. })
  326. // totalGCSUploadErrors is the metric that reports the total number of GCS upload errors
  327. totalGCSUploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  328. Name: "sftpgo_gcs_upload_errors_total",
  329. Help: "The total number of GCS upload errors",
  330. })
  331. // totalGCSDownloadErrors is the metric that reports the total number of GCS download errors
  332. totalGCSDownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  333. Name: "sftpgo_gcs_download_errors_total",
  334. Help: "The total number of GCS download errors",
  335. })
  336. // totalGCSUploadSize is the metric that reports the total GCS uploads size as bytes
  337. totalGCSUploadSize = promauto.NewCounter(prometheus.CounterOpts{
  338. Name: "sftpgo_gcs_upload_size",
  339. Help: "The total GCS upload size as bytes, partial uploads are included",
  340. })
  341. // totalGCSDownloadSize is the metric that reports the total GCS downloads size as bytes
  342. totalGCSDownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  343. Name: "sftpgo_gcs_download_size",
  344. Help: "The total GCS download size as bytes, partial downloads are included",
  345. })
  346. // totalGCSListObjects is the metric that reports the total successful GCS list objects requests
  347. totalGCSListObjects = promauto.NewCounter(prometheus.CounterOpts{
  348. Name: "sftpgo_gcs_list_objects",
  349. Help: "The total number of successful GCS list objects requests",
  350. })
  351. // totalGCSCopyObject is the metric that reports the total successful GCS copy object requests
  352. totalGCSCopyObject = promauto.NewCounter(prometheus.CounterOpts{
  353. Name: "sftpgo_gcs_copy_object",
  354. Help: "The total number of successful GCS copy object requests",
  355. })
  356. // totalGCSDeleteObject is the metric that reports the total successful GCS delete object requests
  357. totalGCSDeleteObject = promauto.NewCounter(prometheus.CounterOpts{
  358. Name: "sftpgo_gcs_delete_object",
  359. Help: "The total number of successful GCS delete object requests",
  360. })
  361. // totalGCSListObjectsError is the metric that reports the total GCS list objects errors
  362. totalGCSListObjectsErrors = promauto.NewCounter(prometheus.CounterOpts{
  363. Name: "sftpgo_gcs_list_objects_errors",
  364. Help: "The total number of GCS list objects errors",
  365. })
  366. // totalGCSCopyObjectErrors is the metric that reports the total GCS copy object errors
  367. totalGCSCopyObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  368. Name: "sftpgo_gcs_copy_object_errors",
  369. Help: "The total number of GCS copy object errors",
  370. })
  371. // totalGCSDeleteObjectErrors is the metric that reports the total GCS delete object errors
  372. totalGCSDeleteObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  373. Name: "sftpgo_gcs_delete_object_errors",
  374. Help: "The total number of GCS delete object errors",
  375. })
  376. // totalGCSHeadObject is the metric that reports the total successful GCS head object requests
  377. totalGCSHeadObject = promauto.NewCounter(prometheus.CounterOpts{
  378. Name: "sftpgo_gcs_head_object",
  379. Help: "The total number of successful GCS head object requests",
  380. })
  381. // totalGCSHeadObjectErrors is the metric that reports the total GCS head object errors
  382. totalGCSHeadObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  383. Name: "sftpgo_gcs_head_object_errors",
  384. Help: "The total number of GCS head object errors",
  385. })
  386. // totalGCSHeadBucket is the metric that reports the total successful GCS head bucket requests
  387. totalGCSHeadBucket = promauto.NewCounter(prometheus.CounterOpts{
  388. Name: "sftpgo_gcs_head_bucket",
  389. Help: "The total number of successful GCS head bucket requests",
  390. })
  391. // totalGCSHeadBucketErrors is the metric that reports the total GCS head bucket errors
  392. totalGCSHeadBucketErrors = promauto.NewCounter(prometheus.CounterOpts{
  393. Name: "sftpgo_gcs_head_bucket_errors",
  394. Help: "The total number of GCS head bucket errors",
  395. })
  396. // totalAZUploads is the metric that reports the total number of successful Azure uploads
  397. totalAZUploads = promauto.NewCounter(prometheus.CounterOpts{
  398. Name: "sftpgo_az_uploads_total",
  399. Help: "The total number of successful Azure uploads",
  400. })
  401. // totalAZDownloads is the metric that reports the total number of successful Azure downloads
  402. totalAZDownloads = promauto.NewCounter(prometheus.CounterOpts{
  403. Name: "sftpgo_az_downloads_total",
  404. Help: "The total number of successful Azure downloads",
  405. })
  406. // totalAZUploadErrors is the metric that reports the total number of Azure upload errors
  407. totalAZUploadErrors = promauto.NewCounter(prometheus.CounterOpts{
  408. Name: "sftpgo_az_upload_errors_total",
  409. Help: "The total number of Azure upload errors",
  410. })
  411. // totalAZDownloadErrors is the metric that reports the total number of Azure download errors
  412. totalAZDownloadErrors = promauto.NewCounter(prometheus.CounterOpts{
  413. Name: "sftpgo_az_download_errors_total",
  414. Help: "The total number of Azure download errors",
  415. })
  416. // totalAZUploadSize is the metric that reports the total Azure uploads size as bytes
  417. totalAZUploadSize = promauto.NewCounter(prometheus.CounterOpts{
  418. Name: "sftpgo_az_upload_size",
  419. Help: "The total Azure upload size as bytes, partial uploads are included",
  420. })
  421. // totalAZDownloadSize is the metric that reports the total Azure downloads size as bytes
  422. totalAZDownloadSize = promauto.NewCounter(prometheus.CounterOpts{
  423. Name: "sftpgo_az_download_size",
  424. Help: "The total Azure download size as bytes, partial downloads are included",
  425. })
  426. // totalAZListObjects is the metric that reports the total successful Azure list objects requests
  427. totalAZListObjects = promauto.NewCounter(prometheus.CounterOpts{
  428. Name: "sftpgo_az_list_objects",
  429. Help: "The total number of successful Azure list objects requests",
  430. })
  431. // totalAZCopyObject is the metric that reports the total successful Azure copy object requests
  432. totalAZCopyObject = promauto.NewCounter(prometheus.CounterOpts{
  433. Name: "sftpgo_az_copy_object",
  434. Help: "The total number of successful Azure copy object requests",
  435. })
  436. // totalAZDeleteObject is the metric that reports the total successful Azure delete object requests
  437. totalAZDeleteObject = promauto.NewCounter(prometheus.CounterOpts{
  438. Name: "sftpgo_az_delete_object",
  439. Help: "The total number of successful Azure delete object requests",
  440. })
  441. // totalAZListObjectsError is the metric that reports the total Azure list objects errors
  442. totalAZListObjectsErrors = promauto.NewCounter(prometheus.CounterOpts{
  443. Name: "sftpgo_az_list_objects_errors",
  444. Help: "The total number of Azure list objects errors",
  445. })
  446. // totalAZCopyObjectErrors is the metric that reports the total Azure copy object errors
  447. totalAZCopyObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  448. Name: "sftpgo_az_copy_object_errors",
  449. Help: "The total number of Azure copy object errors",
  450. })
  451. // totalAZDeleteObjectErrors is the metric that reports the total Azure delete object errors
  452. totalAZDeleteObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  453. Name: "sftpgo_az_delete_object_errors",
  454. Help: "The total number of Azure delete object errors",
  455. })
  456. // totalAZHeadObject is the metric that reports the total successful Azure head object requests
  457. totalAZHeadObject = promauto.NewCounter(prometheus.CounterOpts{
  458. Name: "sftpgo_az_head_object",
  459. Help: "The total number of successful Azure head object requests",
  460. })
  461. // totalAZHeadObjectErrors is the metric that reports the total Azure head object errors
  462. totalAZHeadObjectErrors = promauto.NewCounter(prometheus.CounterOpts{
  463. Name: "sftpgo_az_head_object_errors",
  464. Help: "The total number of Azure head object errors",
  465. })
  466. // totalAZHeadContainer is the metric that reports the total successful Azure head container requests
  467. totalAZHeadContainer = promauto.NewCounter(prometheus.CounterOpts{
  468. Name: "sftpgo_az_head_container",
  469. Help: "The total number of successful Azure head container requests",
  470. })
  471. // totalAZHeadContainerErrors is the metric that reports the total Azure head container errors
  472. totalAZHeadContainerErrors = promauto.NewCounter(prometheus.CounterOpts{
  473. Name: "sftpgo_az_head_container_errors",
  474. Help: "The total number of Azure head container errors",
  475. })
  476. )
  477. // AddMetricsEndpoint exposes metrics to the specified endpoint
  478. func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
  479. handler.Handle(metricsPath, promhttp.Handler())
  480. }
  481. // TransferCompleted updates metrics after an upload or a download
  482. func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error) {
  483. if transferKind == 0 {
  484. // upload
  485. if err == nil {
  486. totalUploads.Inc()
  487. } else {
  488. totalUploadErrors.Inc()
  489. }
  490. totalUploadSize.Add(float64(bytesReceived))
  491. } else {
  492. // download
  493. if err == nil {
  494. totalDownloads.Inc()
  495. } else {
  496. totalDownloadErrors.Inc()
  497. }
  498. totalDownloadSize.Add(float64(bytesSent))
  499. }
  500. }
  501. // S3TransferCompleted updates metrics after an S3 upload or a download
  502. func S3TransferCompleted(bytes int64, transferKind int, err error) {
  503. if transferKind == 0 {
  504. // upload
  505. if err == nil {
  506. totalS3Uploads.Inc()
  507. } else {
  508. totalS3UploadErrors.Inc()
  509. }
  510. totalS3UploadSize.Add(float64(bytes))
  511. } else {
  512. // download
  513. if err == nil {
  514. totalS3Downloads.Inc()
  515. } else {
  516. totalS3DownloadErrors.Inc()
  517. }
  518. totalS3DownloadSize.Add(float64(bytes))
  519. }
  520. }
  521. // S3ListObjectsCompleted updates metrics after an S3 list objects request terminates
  522. func S3ListObjectsCompleted(err error) {
  523. if err == nil {
  524. totalS3ListObjects.Inc()
  525. } else {
  526. totalS3ListObjectsErrors.Inc()
  527. }
  528. }
  529. // S3CopyObjectCompleted updates metrics after an S3 copy object request terminates
  530. func S3CopyObjectCompleted(err error) {
  531. if err == nil {
  532. totalS3CopyObject.Inc()
  533. } else {
  534. totalS3CopyObjectErrors.Inc()
  535. }
  536. }
  537. // S3DeleteObjectCompleted updates metrics after an S3 delete object request terminates
  538. func S3DeleteObjectCompleted(err error) {
  539. if err == nil {
  540. totalS3DeleteObject.Inc()
  541. } else {
  542. totalS3DeleteObjectErrors.Inc()
  543. }
  544. }
  545. // S3HeadObjectCompleted updates metrics after a S3 head object request terminates
  546. func S3HeadObjectCompleted(err error) {
  547. if err == nil {
  548. totalS3HeadObject.Inc()
  549. } else {
  550. totalS3HeadObjectErrors.Inc()
  551. }
  552. }
  553. // S3HeadBucketCompleted updates metrics after a S3 head bucket request terminates
  554. func S3HeadBucketCompleted(err error) {
  555. if err == nil {
  556. totalS3HeadBucket.Inc()
  557. } else {
  558. totalS3HeadBucketErrors.Inc()
  559. }
  560. }
  561. // GCSTransferCompleted updates metrics after a GCS upload or a download
  562. func GCSTransferCompleted(bytes int64, transferKind int, err error) {
  563. if transferKind == 0 {
  564. // upload
  565. if err == nil {
  566. totalGCSUploads.Inc()
  567. } else {
  568. totalGCSUploadErrors.Inc()
  569. }
  570. totalGCSUploadSize.Add(float64(bytes))
  571. } else {
  572. // download
  573. if err == nil {
  574. totalGCSDownloads.Inc()
  575. } else {
  576. totalGCSDownloadErrors.Inc()
  577. }
  578. totalGCSDownloadSize.Add(float64(bytes))
  579. }
  580. }
  581. // GCSListObjectsCompleted updates metrics after a GCS list objects request terminates
  582. func GCSListObjectsCompleted(err error) {
  583. if err == nil {
  584. totalGCSListObjects.Inc()
  585. } else {
  586. totalGCSListObjectsErrors.Inc()
  587. }
  588. }
  589. // GCSCopyObjectCompleted updates metrics after a GCS copy object request terminates
  590. func GCSCopyObjectCompleted(err error) {
  591. if err == nil {
  592. totalGCSCopyObject.Inc()
  593. } else {
  594. totalGCSCopyObjectErrors.Inc()
  595. }
  596. }
  597. // GCSDeleteObjectCompleted updates metrics after a GCS delete object request terminates
  598. func GCSDeleteObjectCompleted(err error) {
  599. if err == nil {
  600. totalGCSDeleteObject.Inc()
  601. } else {
  602. totalGCSDeleteObjectErrors.Inc()
  603. }
  604. }
  605. // GCSHeadObjectCompleted updates metrics after a GCS head object request terminates
  606. func GCSHeadObjectCompleted(err error) {
  607. if err == nil {
  608. totalGCSHeadObject.Inc()
  609. } else {
  610. totalGCSHeadObjectErrors.Inc()
  611. }
  612. }
  613. // GCSHeadBucketCompleted updates metrics after a GCS head bucket request terminates
  614. func GCSHeadBucketCompleted(err error) {
  615. if err == nil {
  616. totalGCSHeadBucket.Inc()
  617. } else {
  618. totalGCSHeadBucketErrors.Inc()
  619. }
  620. }
  621. // AZTransferCompleted updates metrics after a Azure upload or a download
  622. func AZTransferCompleted(bytes int64, transferKind int, err error) {
  623. if transferKind == 0 {
  624. // upload
  625. if err == nil {
  626. totalAZUploads.Inc()
  627. } else {
  628. totalAZUploadErrors.Inc()
  629. }
  630. totalAZUploadSize.Add(float64(bytes))
  631. } else {
  632. // download
  633. if err == nil {
  634. totalAZDownloads.Inc()
  635. } else {
  636. totalAZDownloadErrors.Inc()
  637. }
  638. totalAZDownloadSize.Add(float64(bytes))
  639. }
  640. }
  641. // AZListObjectsCompleted updates metrics after a Azure list objects request terminates
  642. func AZListObjectsCompleted(err error) {
  643. if err == nil {
  644. totalAZListObjects.Inc()
  645. } else {
  646. totalAZListObjectsErrors.Inc()
  647. }
  648. }
  649. // AZCopyObjectCompleted updates metrics after a Azure copy object request terminates
  650. func AZCopyObjectCompleted(err error) {
  651. if err == nil {
  652. totalAZCopyObject.Inc()
  653. } else {
  654. totalAZCopyObjectErrors.Inc()
  655. }
  656. }
  657. // AZDeleteObjectCompleted updates metrics after a Azure delete object request terminates
  658. func AZDeleteObjectCompleted(err error) {
  659. if err == nil {
  660. totalAZDeleteObject.Inc()
  661. } else {
  662. totalAZDeleteObjectErrors.Inc()
  663. }
  664. }
  665. // AZHeadObjectCompleted updates metrics after a Azure head object request terminates
  666. func AZHeadObjectCompleted(err error) {
  667. if err == nil {
  668. totalAZHeadObject.Inc()
  669. } else {
  670. totalAZHeadObjectErrors.Inc()
  671. }
  672. }
  673. // AZHeadContainerCompleted updates metrics after a Azure head container request terminates
  674. func AZHeadContainerCompleted(err error) {
  675. if err == nil {
  676. totalAZHeadContainer.Inc()
  677. } else {
  678. totalAZHeadContainerErrors.Inc()
  679. }
  680. }
  681. // SSHCommandCompleted update metrics after an SSH command terminates
  682. func SSHCommandCompleted(err error) {
  683. if err == nil {
  684. totalSSHCommands.Inc()
  685. } else {
  686. totalSSHCommandErrors.Inc()
  687. }
  688. }
  689. // UpdateDataProviderAvailability updates the metric for the data provider availability
  690. func UpdateDataProviderAvailability(err error) {
  691. if err == nil {
  692. dataproviderAvailability.Set(1)
  693. } else {
  694. dataproviderAvailability.Set(0)
  695. }
  696. }
  697. // AddLoginAttempt increments the metrics for login attempts
  698. func AddLoginAttempt(authMethod string) {
  699. totalLoginAttempts.Inc()
  700. switch authMethod {
  701. case loginMethodPublicKey:
  702. totalKeyLoginAttempts.Inc()
  703. case loginMethodKeyboardInteractive:
  704. totalInteractiveLoginAttempts.Inc()
  705. case loginMethodKeyAndPassword:
  706. totalKeyAndPasswordLoginAttempts.Inc()
  707. case loginMethodKeyAndKeyboardInt:
  708. totalKeyAndKeyIntLoginAttempts.Inc()
  709. case loginMethodTLSCertificate:
  710. totalTLSCertLoginAttempts.Inc()
  711. case loginMethodTLSCertificateAndPwd:
  712. totalTLSCertAndPwdLoginAttempts.Inc()
  713. default:
  714. totalPasswordLoginAttempts.Inc()
  715. }
  716. }
  717. func incLoginOK(authMethod string) {
  718. totalLoginOK.Inc()
  719. switch authMethod {
  720. case loginMethodPublicKey:
  721. totalKeyLoginOK.Inc()
  722. case loginMethodKeyboardInteractive:
  723. totalInteractiveLoginOK.Inc()
  724. case loginMethodKeyAndPassword:
  725. totalKeyAndPasswordLoginOK.Inc()
  726. case loginMethodKeyAndKeyboardInt:
  727. totalKeyAndKeyIntLoginOK.Inc()
  728. case loginMethodTLSCertificate:
  729. totalTLSCertLoginOK.Inc()
  730. case loginMethodTLSCertificateAndPwd:
  731. totalTLSCertAndPwdLoginOK.Inc()
  732. default:
  733. totalPasswordLoginOK.Inc()
  734. }
  735. }
  736. func incLoginFailed(authMethod string) {
  737. totalLoginFailed.Inc()
  738. switch authMethod {
  739. case loginMethodPublicKey:
  740. totalKeyLoginFailed.Inc()
  741. case loginMethodKeyboardInteractive:
  742. totalInteractiveLoginFailed.Inc()
  743. case loginMethodKeyAndPassword:
  744. totalKeyAndPasswordLoginFailed.Inc()
  745. case loginMethodKeyAndKeyboardInt:
  746. totalKeyAndKeyIntLoginFailed.Inc()
  747. case loginMethodTLSCertificate:
  748. totalTLSCertLoginFailed.Inc()
  749. case loginMethodTLSCertificateAndPwd:
  750. totalTLSCertAndPwdLoginFailed.Inc()
  751. default:
  752. totalPasswordLoginFailed.Inc()
  753. }
  754. }
  755. // AddLoginResult increments the metrics for login results
  756. func AddLoginResult(authMethod string, err error) {
  757. if err == nil {
  758. incLoginOK(authMethod)
  759. } else {
  760. incLoginFailed(authMethod)
  761. }
  762. }
  763. // AddNoAuthTryed increments the metric for clients disconnected
  764. // for inactivity before trying to login
  765. func AddNoAuthTryed() {
  766. totalNoAuthTryed.Inc()
  767. }
  768. // HTTPRequestServed increments the metrics for HTTP requests
  769. func HTTPRequestServed(status int) {
  770. totalHTTPRequests.Inc()
  771. if status >= 200 && status < 300 {
  772. totalHTTPOK.Inc()
  773. } else if status >= 400 && status < 500 {
  774. totalHTTPClientErrors.Inc()
  775. } else if status >= 500 {
  776. totalHTTPServerErrors.Inc()
  777. }
  778. }
  779. // UpdateActiveConnectionsSize sets the metric for active connections
  780. func UpdateActiveConnectionsSize(size int) {
  781. activeConnections.Set(float64(size))
  782. }