Skip to content

Commit

Permalink
Provide metrics about write data rate to particular storage system dc…
Browse files Browse the repository at this point in the history
…m4che#2068

Provide metrics about read data rate from particular storage system fix dcm4che#2069
  • Loading branch information
gunterze committed Jul 4, 2019
1 parent 6e25f53 commit f132c9b
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ void configureKeyAndTrustStore(Device device) {
newMetricsDescriptor("db-update-on-store","DB Update Time on Store", "ms"),
newMetricsDescriptor("receive-from-STORESCU","Receive Data-rate from STORESCU", "MB/s"),
newMetricsDescriptor("send-to-STORESCP","Send Data-rate to STORESCP", "MB/s"),
newMetricsDescriptor("write-to-fs1","Write Data-rate to fs1", "MB/s")
newMetricsDescriptor("write-to-fs1","Write Data-rate to fs1", "MB/s"),
newMetricsDescriptor("read-from-fs1","Read Data-rate from fs1", "MB/s")
};

static final HL7OrderSPSStatus[] HL7_ORDER_SPS_STATUSES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ public Outcome export(ExportContext exportContext) throws Exception {
Location location = null;
try {
LOG.debug("Start copying {} to {}:\n", instanceLocations, storage.getStorageDescriptor());
long start = System.currentTimeMillis();
location = copyTo(retrieveContext, instanceLocations, storage, writeCtx);
double nanos = Math.max(1, System.currentTimeMillis() - start) * 1000.;
retrieveService.getMetricsService().accept("write-to-" + writeCtx.getStorageID(),
() -> writeCtx.getSize() / nanos);
storeService.replaceLocation(storeSession, instanceLocations.getInstancePk(),
location, locationsOnStorageByStatusOK.get(Boolean.FALSE));
storage.commitStorage(writeCtx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.dcm4chee.arc.entity.Metadata;
import org.dcm4chee.arc.entity.Series;
import org.dcm4chee.arc.event.SoftwareConfiguration;
import org.dcm4chee.arc.metrics.MetricsService;
import org.dcm4chee.arc.retrieve.RetrieveContext;
import org.dcm4chee.arc.retrieve.RetrieveService;
import org.dcm4chee.arc.storage.Storage;
Expand Down Expand Up @@ -94,9 +93,6 @@ public class UpdateMetadataScheduler extends Scheduler {
@Inject
private RetrieveService retrieveService;

@Inject
private MetricsService metricsService;

@Inject
private Event<SoftwareConfiguration> softwareConfigurationEvent;

Expand Down Expand Up @@ -207,7 +203,6 @@ private void updateMetadata(ArchiveDeviceExtension arcDev, Storage storage, Seri
storage.getStorageDescriptor());
WriteContext writeCtx = createWriteContext(storage, ctx.getMatches().iterator().next());
try {
long start = System.currentTimeMillis();
try (ZipOutputStream out = new ZipOutputStream(storage.openOutputStream(writeCtx))) {
for (InstanceLocations match : ctx.getMatches()) {
out.putNextEntry(new ZipEntry(match.getSopInstanceUID()));
Expand All @@ -218,9 +213,6 @@ private void updateMetadata(ArchiveDeviceExtension arcDev, Storage storage, Seri
}
out.finish();
}
double nanos = Math.max(1, System.currentTimeMillis() - start) * 1000.;
metricsService.accept("write-to-" + writeCtx.getStorageID(),
() -> writeCtx.getSize() / nanos);
storage.commitStorage(writeCtx);
ejb.commit(metadataUpdate.seriesPk, createMetadata(writeCtx));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public interface MetricsService {

boolean exists(String name);

void accept(String name, double value);

void acceptDataRate(String name, long bytes, long ms);

void accept(String name, DoubleSupplier valueSupplier);

void forEach(String name, int limit, int binSize, Consumer<DoubleSummaryStatistics> consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public boolean exists(String name) {
return device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class).hasMetricsDescriptor(name);
}

@Override
public void accept(String name, double value) {
accept(name, () -> value);
}

@Override
public void acceptDataRate(String name, long bytes, long ms) {
accept(name, () -> bytes / (Math.max(1, ms) * 1000.));
}

@Override
public void accept(String name, DoubleSupplier valueSupplier) {
MetricsDescriptor descriptor = getMetricsDescriptor(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ private boolean copy(InstanceLocations match) {
Location location = null;
try {
LOG.debug("Start copying {} to {}", match, storage.getStorageDescriptor());
long start = System.currentTimeMillis();
location = copyTo(match, storage, writeCtx);
double nanos = Math.max(1, System.currentTimeMillis() - start) * 1000.;
ctx.getRetrieveService().getMetricsService().accept("write-to-" + writeCtx.getStorageID(),
() -> writeCtx.getSize() / nanos);
StoreService storeService = ctx.getRetrieveService().getStoreService();
ApplicationEntity ae = ctx.getLocalApplicationEntity();
StoreSession storeSession = storeService.newStoreSession(ae).withObjectStorageID(storageID);
Expand Down
6 changes: 6 additions & 0 deletions dcm4chee-arc-storage-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-metrics</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-storage</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.dcm4che3.util.AttributesFormat;
import org.dcm4chee.arc.conf.BinaryPrefix;
import org.dcm4chee.arc.conf.StorageDescriptor;
import org.dcm4chee.arc.metrics.MetricsService;
import org.dcm4chee.arc.storage.AbstractStorage;
import org.dcm4chee.arc.storage.ReadContext;
import org.dcm4chee.arc.storage.WriteContext;
Expand Down Expand Up @@ -99,8 +100,8 @@ public WriteContext createWriteContext() {
return new CloudWriteContext(this);
}

protected CloudStorage(StorageDescriptor descriptor, Device device) {
super(descriptor);
protected CloudStorage(StorageDescriptor descriptor, MetricsService metricsService, Device device) {
super(descriptor, metricsService);
this.device = device;
pathFormat = new AttributesFormat(descriptor.getProperty("pathFormat", DEFAULT_PATH_FORMAT));
container = descriptor.getProperty("container", DEFAULT_CONTAINER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import org.dcm4che3.net.Device;
import org.dcm4chee.arc.conf.StorageDescriptor;
import org.dcm4chee.arc.metrics.MetricsService;
import org.dcm4chee.arc.storage.Storage;
import org.dcm4chee.arc.storage.StorageProvider;

Expand All @@ -60,8 +61,11 @@ public class CloudStorageProvider implements StorageProvider {
@Inject
private Device device;

@Inject
private MetricsService metricsService;

@Override
public Storage openStorage(StorageDescriptor descriptor) {
return new CloudStorage(descriptor, device);
return new CloudStorage(descriptor, metricsService, device);
}
}
6 changes: 6 additions & 0 deletions dcm4chee-arc-storage-emc-ecs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-metrics</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-storage</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.dcm4che3.util.TagUtils;
import org.dcm4chee.arc.conf.BinaryPrefix;
import org.dcm4chee.arc.conf.StorageDescriptor;
import org.dcm4chee.arc.metrics.MetricsService;
import org.dcm4chee.arc.storage.AbstractStorage;
import org.dcm4chee.arc.storage.ReadContext;
import org.dcm4chee.arc.storage.WriteContext;
Expand Down Expand Up @@ -91,8 +92,8 @@ public void upload(S3Client s3, InputStream in, long length, String container, S
private final long maxPartSize;
private int count;

public EMCECSStorage(StorageDescriptor descriptor, Device device) {
super(descriptor);
public EMCECSStorage(StorageDescriptor descriptor, MetricsService metricsService, Device device) {
super(descriptor, metricsService);
this.device = device;
pathFormat = new AttributesFormat(descriptor.getProperty("pathFormat", DEFAULT_PATH_FORMAT));
container = descriptor.getProperty("container", DEFAULT_CONTAINER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import org.dcm4che3.net.Device;
import org.dcm4chee.arc.conf.StorageDescriptor;
import org.dcm4chee.arc.metrics.MetricsService;
import org.dcm4chee.arc.storage.Storage;
import org.dcm4chee.arc.storage.StorageProvider;

Expand All @@ -60,8 +61,11 @@ class EMCECSStorageProvider implements StorageProvider {
@Inject
private Device device;

@Inject
private MetricsService metricsService;

@Override
public Storage openStorage(StorageDescriptor descriptor) {
return new EMCECSStorage(descriptor, device);
return new EMCECSStorage(descriptor, metricsService, device);
}
}
6 changes: 6 additions & 0 deletions dcm4chee-arc-storage-filesystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-metrics</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-storage</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import org.dcm4che3.util.AttributesFormat;
import org.dcm4chee.arc.conf.StorageDescriptor;
import org.dcm4chee.arc.metrics.MetricsService;
import org.dcm4chee.arc.storage.AbstractStorage;
import org.dcm4chee.arc.storage.ReadContext;
import org.dcm4chee.arc.storage.WriteContext;
Expand All @@ -67,8 +68,8 @@ public class FileSystemStorage extends AbstractStorage {
private final AttributesFormat pathFormat;
private final Path checkMountFilePath;

public FileSystemStorage(StorageDescriptor descriptor) {
super(descriptor);
public FileSystemStorage(StorageDescriptor descriptor, MetricsService metricsService) {
super(descriptor, metricsService);
rootURI = ensureTrailingSlash(descriptor.getStorageURI());
pathFormat = new AttributesFormat(descriptor.getProperty("pathFormat", DEFAULT_PATH_FORMAT));
String checkMountFile = descriptor.getProperty("checkMountFile", null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.dcm4chee.arc.storage.filesystem;

import org.dcm4chee.arc.conf.StorageDescriptor;
import org.dcm4chee.arc.metrics.MetricsService;
import org.dcm4chee.arc.storage.Storage;
import org.dcm4chee.arc.storage.StorageProvider;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
Expand All @@ -14,8 +16,11 @@
@ApplicationScoped
@Named("file")
class FileSystemStorageProvider implements StorageProvider {
@Inject
private MetricsService metricsService;

@Override
public Storage openStorage(StorageDescriptor descriptor) {
return new FileSystemStorage(descriptor);
return new FileSystemStorage(descriptor, metricsService);
}
}
8 changes: 7 additions & 1 deletion dcm4chee-arc-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-conf</artifactId>
<version>5.17.1</version>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-metrics</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
package org.dcm4chee.arc.storage;

import org.dcm4chee.arc.conf.StorageDescriptor;
import org.dcm4chee.arc.metrics.MetricsService;

import java.io.*;
import java.security.DigestInputStream;
Expand All @@ -56,9 +57,11 @@ public abstract class AbstractStorage implements Storage {
"{now,date,yyyy/MM/dd}/{0020000D,hash}/{0020000E,hash}/{00080018,hash}";

protected final StorageDescriptor descriptor;
protected final MetricsService metricsService;

protected AbstractStorage(StorageDescriptor descriptor) {
protected AbstractStorage(StorageDescriptor descriptor, MetricsService metricsService) {
this.descriptor = descriptor;
this.metricsService = metricsService;
}

@Override
Expand Down Expand Up @@ -108,6 +111,7 @@ public String toString() {
@Override
public OutputStream openOutputStream(final WriteContext ctx) throws IOException {
checkAccessable();
long start = System.currentTimeMillis();
OutputStream stream = openOutputStreamA(ctx);
if (ctx.getMessageDigest() != null) {
stream = new DigestOutputStream(stream, ctx.getMessageDigest());
Expand Down Expand Up @@ -140,6 +144,8 @@ public void close() throws IOException {
} finally {
try {
super.close();
metricsService.acceptDataRate("write-to-" + descriptor.getStorageID(),
ctx.getSize(), System.currentTimeMillis() - start);
} catch (IOException e) {
throw new StorageException(e);
} finally {
Expand All @@ -153,7 +159,10 @@ public void close() throws IOException {
@Override
public void copy(InputStream in, WriteContext ctx) throws IOException {
checkAccessable();
long start = System.currentTimeMillis();
copyA(in, ctx);
metricsService.acceptDataRate("write-to-" + descriptor.getStorageID(),
ctx.getContentLength(), System.currentTimeMillis() - start);
}

private void checkAccessable() throws IOException {
Expand Down Expand Up @@ -193,6 +202,7 @@ public void revokeStorage(WriteContext ctx) throws IOException {
@Override
public InputStream openInputStream(final ReadContext ctx) throws IOException {
checkAccessable();
long start = System.currentTimeMillis();
InputStream stream = openInputStreamA(ctx);
if (ctx.getMessageDigest() != null) {
stream = new DigestInputStream(stream, ctx.getMessageDigest());
Expand Down Expand Up @@ -248,6 +258,8 @@ public void close() throws IOException {
} finally {
try {
super.close();
metricsService.acceptDataRate("read-from-" + descriptor.getStorageID(),
ctx.getSize(), System.currentTimeMillis() - start);
} catch (IOException e) {
throw new StorageException(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public Storage getStorage() {
return storage;
}

@Override
public String getStorageID() {
return storage.getStorageDescriptor().getStorageID();
}

@Override
public String getStoragePath() {
return storagePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
public interface ReadContext {
Storage getStorage();

String getStorageID();

String getStoragePath();

void setStoragePath(String storagePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ private void store(StoreContext storeCtx) {
storeas.cstore(cuid, iuid, ctx.getPriority(),
ctx.getMoveOriginatorAETitle(), ctx.getMoveOriginatorMessageID(),
data, tsuid, rspHandler);
service.getMetricsService().accept("send-to-" + storeas.getRemoteAET(),
() -> data.getCount() / (Math.max(1, System.currentTimeMillis() - start) * 1000.));
service.getMetricsService().acceptDataRate("send-to-" + storeas.getRemoteAET(),
data.getCount(), System.currentTimeMillis() - start);
}
} catch (Exception e) {
ctx.incrementFailed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ private void store(InstanceLocations inst) {
storeas.cstore(cuid, iuid, priority,
data, tsuid, rspHandler);
}
service.getMetricsService().accept("send-to-" + storeas.getRemoteAET(),
() -> data.getCount() / (Math.max(1, System.currentTimeMillis() - start) * 1000.));
service.getMetricsService().acceptDataRate("send-to-" + storeas.getRemoteAET(),
data.getCount(), System.currentTimeMillis() - start);
}
} catch (Exception e) {
outstandingRSP.remove(inst);
Expand Down
Loading

0 comments on commit f132c9b

Please sign in to comment.