mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-11-01 01:21:18 +01:00 
			
		
		
		
	metrics
This commit is contained in:
		
							parent
							
								
									fd906d36dd
								
							
						
					
					
						commit
						5936e856f0
					
				@ -24,7 +24,7 @@ public class MetricsAggregatorService {
 | 
				
			|||||||
        this.postHogService = postHogService;
 | 
					        this.postHogService = postHogService;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Scheduled(fixedRate = 900000) // Run every 15 minutes
 | 
					    @Scheduled(fixedRate = 1800000) // Run every 30 minutes
 | 
				
			||||||
    public void aggregateAndSendMetrics() {
 | 
					    public void aggregateAndSendMetrics() {
 | 
				
			||||||
        Map<String, Object> metrics = new HashMap<>();
 | 
					        Map<String, Object> metrics = new HashMap<>();
 | 
				
			||||||
        Search.in(meterRegistry)
 | 
					        Search.in(meterRegistry)
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,7 @@ import java.util.TimeZone;
 | 
				
			|||||||
import org.apache.commons.lang3.StringUtils;
 | 
					import org.apache.commons.lang3.StringUtils;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Qualifier;
 | 
					import org.springframework.beans.factory.annotation.Qualifier;
 | 
				
			||||||
 | 
					import org.springframework.core.env.Environment;
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.posthog.java.PostHog;
 | 
					import com.posthog.java.PostHog;
 | 
				
			||||||
@ -26,19 +27,25 @@ import stirling.software.SPDF.model.ApplicationProperties;
 | 
				
			|||||||
public class PostHogService {
 | 
					public class PostHogService {
 | 
				
			||||||
    private final PostHog postHog;
 | 
					    private final PostHog postHog;
 | 
				
			||||||
    private final String uniqueId;
 | 
					    private final String uniqueId;
 | 
				
			||||||
 | 
					    private final String appVersion;
 | 
				
			||||||
    private final ApplicationProperties applicationProperties;
 | 
					    private final ApplicationProperties applicationProperties;
 | 
				
			||||||
    private final UserServiceInterface userService;
 | 
					    private final UserServiceInterface userService;
 | 
				
			||||||
 | 
					    private final Environment env;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    public PostHogService(
 | 
					    public PostHogService(
 | 
				
			||||||
            PostHog postHog,
 | 
					            PostHog postHog,
 | 
				
			||||||
            @Qualifier("UUID") String uuid,
 | 
					            @Qualifier("UUID") String uuid,
 | 
				
			||||||
 | 
					            @Qualifier("appVersion") String appVersion,
 | 
				
			||||||
            ApplicationProperties applicationProperties,
 | 
					            ApplicationProperties applicationProperties,
 | 
				
			||||||
            @Autowired(required = false) UserServiceInterface userService) {
 | 
					            @Autowired(required = false) UserServiceInterface userService,
 | 
				
			||||||
 | 
					            Environment env) {
 | 
				
			||||||
        this.postHog = postHog;
 | 
					        this.postHog = postHog;
 | 
				
			||||||
        this.uniqueId = uuid;
 | 
					        this.uniqueId = uuid;
 | 
				
			||||||
 | 
					        this.appVersion = appVersion;
 | 
				
			||||||
        this.applicationProperties = applicationProperties;
 | 
					        this.applicationProperties = applicationProperties;
 | 
				
			||||||
        this.userService = userService;
 | 
					        this.userService = userService;
 | 
				
			||||||
 | 
					        this.env = env;
 | 
				
			||||||
        captureSystemInfo();
 | 
					        captureSystemInfo();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,6 +71,16 @@ public class PostHogService {
 | 
				
			|||||||
        Map<String, Object> metrics = new HashMap<>();
 | 
					        Map<String, Object> metrics = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					        	//Application version
 | 
				
			||||||
 | 
					        	metrics.put("app_version", appVersion);
 | 
				
			||||||
 | 
					        	 String deploymentType = "JAR"; // default
 | 
				
			||||||
 | 
					             if ("true".equalsIgnoreCase(env.getProperty("BROWSER_OPEN"))) {
 | 
				
			||||||
 | 
					                 deploymentType = "EXE";
 | 
				
			||||||
 | 
					             } else if (isRunningInDocker()) {
 | 
				
			||||||
 | 
					                 deploymentType = "DOCKER";
 | 
				
			||||||
 | 
					             }
 | 
				
			||||||
 | 
					             metrics.put("deployment_type", deploymentType);
 | 
				
			||||||
 | 
					        	
 | 
				
			||||||
            // System info
 | 
					            // System info
 | 
				
			||||||
            metrics.put("os_name", System.getProperty("os.name"));
 | 
					            metrics.put("os_name", System.getProperty("os.name"));
 | 
				
			||||||
            metrics.put("os_version", System.getProperty("os.version"));
 | 
					            metrics.put("os_version", System.getProperty("os.version"));
 | 
				
			||||||
@ -132,7 +149,6 @@ public class PostHogService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            // Docker detection and stats
 | 
					            // Docker detection and stats
 | 
				
			||||||
            boolean isDocker = isRunningInDocker();
 | 
					            boolean isDocker = isRunningInDocker();
 | 
				
			||||||
            metrics.put("is_docker", isDocker);
 | 
					 | 
				
			||||||
            if (isDocker) {
 | 
					            if (isDocker) {
 | 
				
			||||||
                metrics.put("docker_metrics", getDockerMetrics());
 | 
					                metrics.put("docker_metrics", getDockerMetrics());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user