<commit_before>package com.hubspot.singularity.s3uploader;

import java.util.concurrent.TimeUnit;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.google.inject.Inject;

public class SingularityS3UploaderMetrics {

  private final MetricRegistry registry;
  private final Counter uploaderCounter;
  private final Counter expiringUploaderCounter;
  private final Counter uploadCounter;
  private final Counter errorCounter;
  private final Timer uploadTimer;
  private final Meter filesystemEventsMeter;
  
  private long timeOfLastSuccessUpload;
  private int lastUploadDuration;
  private long startUploadsAt;
  
  @Inject
  public SingularityS3UploaderMetrics(MetricRegistry registry) {
    this.registry = registry;
    this.uploaderCounter = registry.counter(name("uploaders", "total"));
    this.expiringUploaderCounter = registry.counter(name("uploaders", "expiring"));
    this.uploadCounter = registry.counter(name("uploads", "success"));
    this.errorCounter = registry.counter(name("uploads", "errors"));
    this.uploadTimer = registry.timer(name("uploads", "timer"));
    
    registry.register(name("uploads", "millissincelast"), new Gauge<Integer>() {

      @Override
      public Integer getValue() {
        return Integer.valueOf((int) (System.currentTimeMillis() - timeOfLastSuccessUpload));
      }
      
    });
    
    registry.register(name("uploads", "lastdurationmillis"), new Gauge<Integer>() {

      @Override
      public Integer getValue() {
        return lastUploadDuration;
      }
      
    });
    
    this.filesystemEventsMeter = registry.meter(name("filesystem", "events"));
    
    startJmxReporter();
  }
  <commit_msg>return -1 when not initialized.<commit_after>package com.hubspot.singularity.s3uploader;

import java.util.concurrent.TimeUnit;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.google.inject.Inject;

public class SingularityS3UploaderMetrics {

  private final MetricRegistry registry;
  private final Counter uploaderCounter;
  private final Counter expiringUploaderCounter;
  private final Counter uploadCounter;
  private final Counter errorCounter;
  private final Timer uploadTimer;
  private final Meter filesystemEventsMeter;
  
  private long timeOfLastSuccessUpload;
  private int lastUploadDuration;
  private long startUploadsAt;
  
  @Inject
  public SingularityS3UploaderMetrics(MetricRegistry registry) {
    this.registry = registry;
    this.uploaderCounter = registry.counter(name("uploaders", "total"));
    this.expiringUploaderCounter = registry.counter(name("uploaders", "expiring"));
    this.uploadCounter = registry.counter(name("uploads", "success"));
    this.errorCounter = registry.counter(name("uploads", "errors"));
    this.uploadTimer = registry.timer(name("uploads", "timer"));
    
    this.timeOfLastSuccessUpload = -1;
    
    registry.register(name("uploads", "millissincelast"), new Gauge<Integer>() {

      @Override
      public Integer getValue() {
        if (timeOfLastSuccessUpload == -1) {
          return -1;
        }
        
        return Integer.valueOf((int) (System.currentTimeMillis() - timeOfLastSuccessUpload));
      }
      
    });
    
    registry.register(name("uploads", "lastdurationmillis"), new Gauge<Integer>() {

      @Override
      public Integer getValue() {
        return lastUploadDuration;
      }
      
    });
    
    this.filesystemEventsMeter = registry.meter(name("filesystem", "events"));
    
    startJmxReporter();
  }
  
{'fraction_non_alphanumeric': 0.1066147859922179, 'fraction_numerical': 0.0025940337224383916, 'mean_word_length': 4.127659574468085, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '23440', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1085, 'n_words': 221}