- 
                Notifications
    
You must be signed in to change notification settings  - Fork 206
 
WIP: stubbing out MySQL advanced monitoring support #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Draft
      
      
            bpkroth
  wants to merge
  5
  commits into
  cmu-db:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
bpkroth:mysql-advanced-monitoring
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +99
        
        
          −0
        
        
          
        
      
    
  
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      be477dc
              
                WIP: stubbing out MySQL advanced monitoring support
              
              
                bpkroth 209acd8
              
                Merge branch 'main' into mysql-advanced-monitoring
              
              
                bpkroth ba26317
              
                hack to enable advanced monitoring
              
              
                bpkroth 80bef73
              
                Merge branch 'main' into mysql-advanced-monitoring
              
              
                bpkroth 7cbb2b4
              
                Merge branch 'main' into mysql-advanced-monitoring
              
              
                bpkroth File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            95 changes: 95 additions & 0 deletions
          
          95 
        
  src/main/java/com/oltpbenchmark/api/collectors/monitoring/MySQLMonitor.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package com.oltpbenchmark.api.collectors.monitoring; | ||
| 
     | 
||
| import com.oltpbenchmark.BenchmarkState; | ||
| import com.oltpbenchmark.WorkloadConfiguration; | ||
| import com.oltpbenchmark.api.BenchmarkModule; | ||
| import com.oltpbenchmark.api.Worker; | ||
| import com.oltpbenchmark.util.MonitorInfo; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| 
     | 
||
| /** | ||
| * Implementation of a monitor specific to PostgreSQL. Uses the 'pg_stat_statements' add-on to | ||
| * extract relevant query and system information. | ||
| */ | ||
| public class MySQLMonitor extends DatabaseMonitor { | ||
| 
     | 
||
| // TODO: add support for per-query metrics using performance_schema | ||
| 
     | 
||
| // TODO: Expand to SHOW ENGINE INNODB STATUS as well? | ||
| private final String MYSQL_SYSTEM_METRICS = "SHOW GLOBAL STATUS;"; | ||
| 
     | 
||
| private final List<String> repeatedSystemProperties; | ||
| 
     | 
||
| public MySQLMonitor( | ||
| MonitorInfo monitorInfo, | ||
| BenchmarkState testState, | ||
| List<? extends Worker<? extends BenchmarkModule>> workers, | ||
| WorkloadConfiguration conf) { | ||
| super(monitorInfo, testState, workers, conf); | ||
| 
     | 
||
| this.repeatedSystemProperties = | ||
| new ArrayList<String>() { | ||
| { | ||
| add("bytes_received"); | ||
| add("bytes_sent"); | ||
| add("com_select"); | ||
| // ... | ||
| // TODO: Add more properties from SHOW STATUS here | ||
| } | ||
| }; | ||
| } | ||
| 
     | 
||
| @Override | ||
| protected String getCleanupStmt() { | ||
| // FIXME: Currently a no-op. | ||
| return "SELECT 1"; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Extract system events using the extraction query and properties defined above, will fail | ||
| * gracefully to not interrupt benchmarking. | ||
| */ | ||
| private void extractPerformanceMetrics(Instant instant) { | ||
| ImmutableRepeatedSystemEvent.Builder repeatedSystemEventBuilder = | ||
| ImmutableRepeatedSystemEvent.builder(); | ||
| repeatedSystemEventBuilder.instant(instant); | ||
| 
     | 
||
| // Extract OS performance events. | ||
| Map<String, String> propertyValues = new HashMap<String, String>(); | ||
| try (PreparedStatement stmt = conn.prepareStatement(MYSQL_SYSTEM_METRICS)) { | ||
| ResultSet rs = stmt.executeQuery(); | ||
| while (rs.next()) { | ||
| // Add property values. | ||
| String metric_name = rs.getString(1).trim(); | ||
| if (this.repeatedSystemProperties.contains(metric_name)) { | ||
| propertyValues.put(metric_name, rs.getString(2)); | ||
| } | ||
| } | ||
| } catch (SQLException sqlError) { | ||
| LOG.error("Error when extracting system metrics from MySQL."); | ||
| LOG.error(sqlError.getMessage()); | ||
| } | ||
| repeatedSystemEventBuilder.propertyValues(propertyValues); | ||
| this.repeatedSystemEvents.add(repeatedSystemEventBuilder.build()); | ||
| } | ||
| 
     | 
||
| @Override | ||
| protected void runExtraction() { | ||
| Instant time = Instant.now(); | ||
| 
     | 
||
| // TODO: extractQueryMetrics(time); | ||
| extractPerformanceMetrics(time); | ||
| } | ||
| 
     | 
||
| @Override | ||
| protected void writeSystemMetrics() { | ||
| this.writeRepeatedSystemEventsToCSV(); | ||
| } | ||
| } | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO