mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-29 18:38:28 +00:00 
			
		
		
		
	feat: add label 'state' to metric 'gitea_users' (#34326)
This PR adds the label _state_ to the metric _gitea_users_. With the
change, _gitea_users_ would be reported like this:
```
...
# HELP gitea_users Number of Users
# TYPE gitea_users gauge
gitea_users{state="active"} 20
gitea_users{state="inactive"} 10
...
```
The metrics above would be from a Gitea instance with 30 user accounts.
20 of the accounts are active and 10 of the accounts are not active.
Resolve #34325
			
			
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							dd886d729f
						
					
				
				
					commit
					020e774b91
				
			| @@ -17,13 +17,15 @@ import ( | ||||
| 	repo_model "code.gitea.io/gitea/models/repo" | ||||
| 	user_model "code.gitea.io/gitea/models/user" | ||||
| 	"code.gitea.io/gitea/models/webhook" | ||||
| 	"code.gitea.io/gitea/modules/optional" | ||||
| 	"code.gitea.io/gitea/modules/setting" | ||||
| ) | ||||
|  | ||||
| // Statistic contains the database statistics | ||||
| type Statistic struct { | ||||
| 	Counter struct { | ||||
| 		User, Org, PublicKey, | ||||
| 		UsersActive, UsersNotActive, | ||||
| 		Org, PublicKey, | ||||
| 		Repo, Watch, Star, Access, | ||||
| 		Issue, IssueClosed, IssueOpen, | ||||
| 		Comment, Oauth, Follow, | ||||
| @@ -53,7 +55,19 @@ type IssueByRepositoryCount struct { | ||||
| // GetStatistic returns the database statistics | ||||
| func GetStatistic(ctx context.Context) (stats Statistic) { | ||||
| 	e := db.GetEngine(ctx) | ||||
| 	stats.Counter.User = user_model.CountUsers(ctx, nil) | ||||
|  | ||||
| 	// Number of active users | ||||
| 	usersActiveOpts := user_model.CountUserFilter{ | ||||
| 		IsActive: optional.Some(true), | ||||
| 	} | ||||
| 	stats.Counter.UsersActive = user_model.CountUsers(ctx, &usersActiveOpts) | ||||
|  | ||||
| 	// Number of inactive users | ||||
| 	usersNotActiveOpts := user_model.CountUserFilter{ | ||||
| 		IsActive: optional.Some(false), | ||||
| 	} | ||||
| 	stats.Counter.UsersNotActive = user_model.CountUsers(ctx, &usersNotActiveOpts) | ||||
|  | ||||
| 	stats.Counter.Org, _ = db.Count[organization.Organization](ctx, organization.FindOrgOptions{IncludePrivate: true}) | ||||
| 	stats.Counter.PublicKey, _ = e.Count(new(asymkey_model.PublicKey)) | ||||
| 	stats.Counter.Repo, _ = repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{}) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user