|
5 | 5 | package metrics
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "code.gitea.io/gitea/models" |
| 8 | + "code.gitea.io/gitea/modules/setting" |
9 | 9 |
|
10 | 10 | "github.com/prometheus/client_golang/prometheus"
|
11 | 11 | )
|
@@ -43,6 +43,8 @@ type Collector struct {
|
43 | 43 | Users *prometheus.Desc
|
44 | 44 | Watches *prometheus.Desc
|
45 | 45 | Webhooks *prometheus.Desc
|
| 46 | + |
| 47 | + StatisticsTime *prometheus.Desc |
46 | 48 | }
|
47 | 49 |
|
48 | 50 | // NewCollector returns a new Collector with all prometheus.Desc initialized
|
@@ -225,152 +227,152 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) {
|
225 | 227 |
|
226 | 228 | // Collect returns the metrics with values
|
227 | 229 | func (c Collector) Collect(ch chan<- prometheus.Metric) {
|
228 |
| - stats := models.GetStatistic() |
| 230 | + stats := GetStatistic(setting.Metrics.EstimateCounts, setting.Metrics.StatisticTTL) |
229 | 231 |
|
230 |
| - ch <- prometheus.MustNewConstMetric( |
| 232 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
231 | 233 | c.Accesses,
|
232 | 234 | prometheus.GaugeValue,
|
233 | 235 | float64(stats.Counter.Access),
|
234 |
| - ) |
235 |
| - ch <- prometheus.MustNewConstMetric( |
| 236 | + )) |
| 237 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
236 | 238 | c.Actions,
|
237 | 239 | prometheus.GaugeValue,
|
238 | 240 | float64(stats.Counter.Action),
|
239 |
| - ) |
240 |
| - ch <- prometheus.MustNewConstMetric( |
| 241 | + )) |
| 242 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
241 | 243 | c.Attachments,
|
242 | 244 | prometheus.GaugeValue,
|
243 | 245 | float64(stats.Counter.Attachment),
|
244 |
| - ) |
245 |
| - ch <- prometheus.MustNewConstMetric( |
| 246 | + )) |
| 247 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
246 | 248 | c.Comments,
|
247 | 249 | prometheus.GaugeValue,
|
248 | 250 | float64(stats.Counter.Comment),
|
249 |
| - ) |
250 |
| - ch <- prometheus.MustNewConstMetric( |
| 251 | + )) |
| 252 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
251 | 253 | c.Follows,
|
252 | 254 | prometheus.GaugeValue,
|
253 | 255 | float64(stats.Counter.Follow),
|
254 |
| - ) |
255 |
| - ch <- prometheus.MustNewConstMetric( |
| 256 | + )) |
| 257 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
256 | 258 | c.HookTasks,
|
257 | 259 | prometheus.GaugeValue,
|
258 | 260 | float64(stats.Counter.HookTask),
|
259 |
| - ) |
260 |
| - ch <- prometheus.MustNewConstMetric( |
| 261 | + )) |
| 262 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
261 | 263 | c.Issues,
|
262 | 264 | prometheus.GaugeValue,
|
263 | 265 | float64(stats.Counter.Issue),
|
264 |
| - ) |
| 266 | + )) |
265 | 267 | for _, il := range stats.Counter.IssueByLabel {
|
266 |
| - ch <- prometheus.MustNewConstMetric( |
| 268 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
267 | 269 | c.IssuesByLabel,
|
268 | 270 | prometheus.GaugeValue,
|
269 | 271 | float64(il.Count),
|
270 | 272 | il.Label,
|
271 |
| - ) |
| 273 | + )) |
272 | 274 | }
|
273 | 275 | for _, ir := range stats.Counter.IssueByRepository {
|
274 |
| - ch <- prometheus.MustNewConstMetric( |
| 276 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
275 | 277 | c.IssuesByRepository,
|
276 | 278 | prometheus.GaugeValue,
|
277 | 279 | float64(ir.Count),
|
278 | 280 | ir.OwnerName+"/"+ir.Repository,
|
279 |
| - ) |
| 281 | + )) |
280 | 282 | }
|
281 |
| - ch <- prometheus.MustNewConstMetric( |
| 283 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
282 | 284 | c.IssuesClosed,
|
283 | 285 | prometheus.GaugeValue,
|
284 | 286 | float64(stats.Counter.IssueClosed),
|
285 |
| - ) |
286 |
| - ch <- prometheus.MustNewConstMetric( |
| 287 | + )) |
| 288 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
287 | 289 | c.IssuesOpen,
|
288 | 290 | prometheus.GaugeValue,
|
289 | 291 | float64(stats.Counter.IssueOpen),
|
290 |
| - ) |
291 |
| - ch <- prometheus.MustNewConstMetric( |
| 292 | + )) |
| 293 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
292 | 294 | c.Labels,
|
293 | 295 | prometheus.GaugeValue,
|
294 | 296 | float64(stats.Counter.Label),
|
295 |
| - ) |
296 |
| - ch <- prometheus.MustNewConstMetric( |
| 297 | + )) |
| 298 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
297 | 299 | c.LoginSources,
|
298 | 300 | prometheus.GaugeValue,
|
299 | 301 | float64(stats.Counter.AuthSource),
|
300 |
| - ) |
301 |
| - ch <- prometheus.MustNewConstMetric( |
| 302 | + )) |
| 303 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
302 | 304 | c.Milestones,
|
303 | 305 | prometheus.GaugeValue,
|
304 | 306 | float64(stats.Counter.Milestone),
|
305 |
| - ) |
306 |
| - ch <- prometheus.MustNewConstMetric( |
| 307 | + )) |
| 308 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
307 | 309 | c.Mirrors,
|
308 | 310 | prometheus.GaugeValue,
|
309 | 311 | float64(stats.Counter.Mirror),
|
310 |
| - ) |
311 |
| - ch <- prometheus.MustNewConstMetric( |
| 312 | + )) |
| 313 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
312 | 314 | c.Oauths,
|
313 | 315 | prometheus.GaugeValue,
|
314 | 316 | float64(stats.Counter.Oauth),
|
315 |
| - ) |
316 |
| - ch <- prometheus.MustNewConstMetric( |
| 317 | + )) |
| 318 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
317 | 319 | c.Organizations,
|
318 | 320 | prometheus.GaugeValue,
|
319 | 321 | float64(stats.Counter.Org),
|
320 |
| - ) |
321 |
| - ch <- prometheus.MustNewConstMetric( |
| 322 | + )) |
| 323 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
322 | 324 | c.Projects,
|
323 | 325 | prometheus.GaugeValue,
|
324 | 326 | float64(stats.Counter.Project),
|
325 |
| - ) |
326 |
| - ch <- prometheus.MustNewConstMetric( |
| 327 | + )) |
| 328 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
327 | 329 | c.ProjectBoards,
|
328 | 330 | prometheus.GaugeValue,
|
329 | 331 | float64(stats.Counter.ProjectBoard),
|
330 |
| - ) |
331 |
| - ch <- prometheus.MustNewConstMetric( |
| 332 | + )) |
| 333 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
332 | 334 | c.PublicKeys,
|
333 | 335 | prometheus.GaugeValue,
|
334 | 336 | float64(stats.Counter.PublicKey),
|
335 |
| - ) |
336 |
| - ch <- prometheus.MustNewConstMetric( |
| 337 | + )) |
| 338 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
337 | 339 | c.Releases,
|
338 | 340 | prometheus.GaugeValue,
|
339 | 341 | float64(stats.Counter.Release),
|
340 |
| - ) |
341 |
| - ch <- prometheus.MustNewConstMetric( |
| 342 | + )) |
| 343 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
342 | 344 | c.Repositories,
|
343 | 345 | prometheus.GaugeValue,
|
344 | 346 | float64(stats.Counter.Repo),
|
345 |
| - ) |
346 |
| - ch <- prometheus.MustNewConstMetric( |
| 347 | + )) |
| 348 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
347 | 349 | c.Stars,
|
348 | 350 | prometheus.GaugeValue,
|
349 | 351 | float64(stats.Counter.Star),
|
350 |
| - ) |
351 |
| - ch <- prometheus.MustNewConstMetric( |
| 352 | + )) |
| 353 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
352 | 354 | c.Teams,
|
353 | 355 | prometheus.GaugeValue,
|
354 | 356 | float64(stats.Counter.Team),
|
355 |
| - ) |
356 |
| - ch <- prometheus.MustNewConstMetric( |
| 357 | + )) |
| 358 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
357 | 359 | c.UpdateTasks,
|
358 | 360 | prometheus.GaugeValue,
|
359 | 361 | float64(stats.Counter.UpdateTask),
|
360 |
| - ) |
361 |
| - ch <- prometheus.MustNewConstMetric( |
| 362 | + )) |
| 363 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
362 | 364 | c.Users,
|
363 | 365 | prometheus.GaugeValue,
|
364 | 366 | float64(stats.Counter.User),
|
365 |
| - ) |
366 |
| - ch <- prometheus.MustNewConstMetric( |
| 367 | + )) |
| 368 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
367 | 369 | c.Watches,
|
368 | 370 | prometheus.GaugeValue,
|
369 | 371 | float64(stats.Counter.Watch),
|
370 |
| - ) |
371 |
| - ch <- prometheus.MustNewConstMetric( |
| 372 | + )) |
| 373 | + ch <- prometheus.NewMetricWithTimestamp(stats.Time, prometheus.MustNewConstMetric( |
372 | 374 | c.Webhooks,
|
373 | 375 | prometheus.GaugeValue,
|
374 | 376 | float64(stats.Counter.Webhook),
|
375 |
| - ) |
| 377 | + )) |
376 | 378 | }
|
0 commit comments