Remove deprecated periodic stats command

This commit is contained in:
Moxie Marlinspike 2019-03-25 17:41:49 -07:00
parent 1185fad75c
commit 77142eb2df
3 changed files with 0 additions and 170 deletions

View File

@ -73,7 +73,6 @@ import org.whispersystems.textsecuregcm.websocket.WebSocketAccountAuthenticator;
import org.whispersystems.textsecuregcm.workers.CertificateCommand;
import org.whispersystems.textsecuregcm.workers.DeleteUserCommand;
import org.whispersystems.textsecuregcm.workers.DirectoryCommand;
import org.whispersystems.textsecuregcm.workers.PeriodicStatsCommand;
import org.whispersystems.textsecuregcm.workers.TrimMessagesCommand;
import org.whispersystems.textsecuregcm.workers.VacuumCommand;
import org.whispersystems.websocket.WebSocketResourceProviderFactory;
@ -110,7 +109,6 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
bootstrap.addCommand(new DirectoryCommand());
bootstrap.addCommand(new VacuumCommand());
bootstrap.addCommand(new TrimMessagesCommand());
bootstrap.addCommand(new PeriodicStatsCommand());
bootstrap.addCommand(new DeleteUserCommand());
bootstrap.addCommand(new CertificateCommand());
bootstrap.addBundle(new NameableMigrationsBundle<WhisperServerConfiguration>("accountdb", "accountsdb.xml") {

View File

@ -84,15 +84,6 @@ public abstract class Accounts {
@SqlQuery("SELECT * FROM accounts WHERE " + NUMBER + " > :from ORDER BY " + NUMBER + " LIMIT :limit")
public abstract List<Account> getAllFrom(@Bind("from") String from, @Bind("limit") int length);
@SqlQuery("SELECT COUNT(*) FROM accounts a, json_array_elements(a.data->'devices') devices WHERE devices->>'id' = '1' AND (devices->>'gcmId') is not null AND (devices->>'lastSeen')\\:\\:bigint >= :since")
public abstract int getAndroidActiveSinceCount(@Bind("since") long since);
@SqlQuery("SELECT COUNT(*) FROM accounts a, json_array_elements(a.data->'devices') devices WHERE devices->>'id' = '1' AND (devices->>'apnId') is not null AND (devices->>'lastSeen')\\:\\:bigint >= :since")
public abstract int getIosActiveSinceCount(@Bind("since") long since);
@SqlQuery("SELECT count(*) FROM accounts a, json_array_elements(a.data->'devices') devices WHERE devices->>'id' = '1' AND (devices->>'lastSeen')\\:\\:bigint >= :since AND (devices->>'signedPreKey') is null AND (devices->>'gcmId') is not null")
public abstract int getUnsignedKeysCount(@Bind("since") long since);
@Transaction(TransactionIsolationLevel.SERIALIZABLE)
public boolean create(Account account) {
int rows = removeAccount(account.getNumber());

View File

@ -1,159 +0,0 @@
package org.whispersystems.textsecuregcm.workers;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.ScheduledReporter;
import com.fasterxml.jackson.databind.DeserializationFeature;
import net.sourceforge.argparse4j.inf.Namespace;
import org.skife.jdbi.v2.DBI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.WhisperServerConfiguration;
import org.whispersystems.textsecuregcm.storage.Accounts;
import java.util.concurrent.TimeUnit;
import static com.codahale.metrics.MetricRegistry.name;
import io.dropwizard.Application;
import io.dropwizard.cli.EnvironmentCommand;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jdbi.ImmutableListContainerFactory;
import io.dropwizard.jdbi.ImmutableSetContainerFactory;
import io.dropwizard.jdbi.OptionalContainerFactory;
import io.dropwizard.jdbi.args.OptionalArgumentFactory;
import io.dropwizard.metrics.ReporterFactory;
import io.dropwizard.setup.Environment;
public class PeriodicStatsCommand extends EnvironmentCommand<WhisperServerConfiguration> {
private final Logger logger = LoggerFactory.getLogger(PeriodicStatsCommand.class);
public PeriodicStatsCommand() {
super(new Application<WhisperServerConfiguration>() {
@Override
public void run(WhisperServerConfiguration configuration, Environment environment)
throws Exception
{
}
}, "stats", "Update periodic stats.");
}
@Override
protected void run(Environment environment, Namespace namespace,
WhisperServerConfiguration configuration)
throws Exception
{
try {
environment.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
DataSourceFactory dbConfig = configuration.getReadDataSourceFactory();
if (dbConfig == null) {
logger.warn("No slave database configuration found!");
return;
}
DBI dbi = new DBI(dbConfig.getUrl(), dbConfig.getUser(), dbConfig.getPassword());
dbi.registerArgumentFactory(new OptionalArgumentFactory(dbConfig.getDriverClass()));
dbi.registerContainerFactory(new ImmutableListContainerFactory());
dbi.registerContainerFactory(new ImmutableSetContainerFactory());
dbi.registerContainerFactory(new OptionalContainerFactory());
Accounts accounts = dbi.onDemand(Accounts.class);
long yesterday = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis()) - 1;
long monthAgo = yesterday - 30;
logger.info("Calculating daily active");
final int dailyActiveAndroid = accounts.getAndroidActiveSinceCount(TimeUnit.DAYS.toMillis(yesterday));
final int dailyActiveIos = accounts.getIosActiveSinceCount(TimeUnit.DAYS.toMillis(yesterday));
logger.info("Calculating monthly active");
final int monthlyActiveAndroid = accounts.getAndroidActiveSinceCount(TimeUnit.DAYS.toMillis(monthAgo));
final int monthlyActiveIos = accounts.getIosActiveSinceCount(TimeUnit.DAYS.toMillis(monthAgo));
logger.info("Calculating daily signed keys");
final int dailyActiveNoSignedKeys = accounts.getUnsignedKeysCount(TimeUnit.DAYS.toMillis(yesterday));
logger.info("Calculating monthly signed keys");
final int monthlyActiveNoSignedKeys = accounts.getUnsignedKeysCount(TimeUnit.DAYS.toMillis(monthAgo ));
environment.metrics().register(name(PeriodicStatsCommand.class, "daily_active"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return dailyActiveAndroid + dailyActiveIos;
}
});
environment.metrics().register(name(PeriodicStatsCommand.class, "daily_active_android"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return dailyActiveAndroid;
}
});
environment.metrics().register(name(PeriodicStatsCommand.class, "daily_active_ios"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return dailyActiveIos;
}
});
environment.metrics().register(name(PeriodicStatsCommand.class, "monthly_active"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return monthlyActiveAndroid + monthlyActiveIos;
}
});
environment.metrics().register(name(PeriodicStatsCommand.class, "monthly_active_android"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return monthlyActiveAndroid;
}
});
environment.metrics().register(name(PeriodicStatsCommand.class, "monthly_active_ios"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return monthlyActiveIos;
}
});
environment.metrics().register(name(PeriodicStatsCommand.class, "daily_no_signed_keys"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return dailyActiveNoSignedKeys;
}
});
environment.metrics().register(name(PeriodicStatsCommand.class, "monthly_no_signed_keys"),
new Gauge<Integer>() {
@Override
public Integer getValue() {
return monthlyActiveNoSignedKeys;
}
});
for (ReporterFactory reporterFactory : configuration.getMetricsFactory().getReporters()) {
ScheduledReporter reporter = reporterFactory.build(environment.metrics());
logger.info("Reporting via: " + reporter);
reporter.report();
logger.info("Reporting finished...");
}
} catch (Exception ex) {
logger.warn("Directory Exception", ex);
throw new RuntimeException(ex);
} finally {
Thread.sleep(3000);
System.exit(0);
}
}
}