Search in sources :

Example 1 with Counter

use of com.automatak.dnp3.Counter in project solarnetwork-node by SolarNetwork.

the class OutstationService method changeSetForDatumCapturedEvent.

private OutstationChangeSet changeSetForDatumCapturedEvent(final Datum datum, final Event event) {
    Map<MeasurementType, List<MeasurementConfig>> map = measurementTypeMap(getMeasurementConfigs());
    Map<ControlType, List<ControlConfig>> controlMap = controlTypeMap(getControlConfigs());
    if (datum == null || ((map == null || map.isEmpty()) && (controlMap == null || controlMap.isEmpty()))) {
        return null;
    }
    final String sourceId = datum.getSourceId();
    final Instant timestamp = datum.getTimestamp();
    if (timestamp == null) {
        return null;
    }
    final long ts = timestamp.toEpochMilli();
    final Map<String, ?> datumProps = datum.getSampleData();
    OutstationChangeSet changes = null;
    if (map != null) {
        for (Map.Entry<MeasurementType, List<MeasurementConfig>> me : map.entrySet()) {
            MeasurementType type = me.getKey();
            List<MeasurementConfig> list = me.getValue();
            for (ListIterator<MeasurementConfig> itr = list.listIterator(); itr.hasNext(); ) {
                MeasurementConfig config = itr.next();
                if (sourceId.equals(config.getSourceId())) {
                    Object propVal = datumProps.get(config.getPropertyName());
                    if (propVal != null) {
                        if (propVal instanceof Number) {
                            if (config.getUnitMultiplier() != null) {
                                propVal = applyUnitMultiplier((Number) propVal, config.getUnitMultiplier());
                            }
                            if (config.getDecimalScale() >= 0) {
                                propVal = applyDecimalScale((Number) propVal, config.getDecimalScale());
                            }
                        }
                        if (changes == null) {
                            changes = new OutstationChangeSet();
                        }
                        log.debug("Updating DNP3 {}[{}] from [{}].{} -> {}", type, itr.previousIndex(), sourceId, config.getPropertyName(), propVal);
                        switch(type) {
                            case AnalogInput:
                                if (propVal instanceof Number) {
                                    changes.update(new AnalogInput(((Number) propVal).doubleValue(), (byte) AnalogQuality.ONLINE.toType(), ts), itr.previousIndex());
                                }
                                break;
                            case AnalogOutputStatus:
                                if (propVal instanceof Number) {
                                    changes.update(new AnalogOutputStatus(((Number) propVal).doubleValue(), (byte) AnalogOutputStatusQuality.ONLINE.toType(), ts), itr.previousIndex());
                                }
                                break;
                            case BinaryInput:
                                changes.update(new BinaryInput(booleanPropertyValue(propVal), (byte) BinaryQuality.ONLINE.toType(), ts), itr.previousIndex());
                                break;
                            case BinaryOutputStatus:
                                changes.update(new BinaryOutputStatus(booleanPropertyValue(propVal), (byte) BinaryOutputStatusQuality.ONLINE.toType(), ts), itr.previousIndex());
                                break;
                            case Counter:
                                if (propVal instanceof Number) {
                                    changes.update(new Counter(((Number) propVal).longValue(), (byte) CounterQuality.ONLINE.toType(), ts), itr.previousIndex());
                                }
                                break;
                            case DoubleBitBinaryInput:
                                changes.update(new DoubleBitBinaryInput(booleanPropertyValue(propVal) ? DoubleBit.DETERMINED_ON : DoubleBit.DETERMINED_OFF, (byte) DoubleBitBinaryQuality.ONLINE.toType(), ts), itr.previousIndex());
                                break;
                            case FrozenCounter:
                                if (propVal instanceof Number) {
                                    changes.update(new FrozenCounter(((Number) propVal).longValue(), (byte) FrozenCounterQuality.ONLINE.toType(), ts), itr.previousIndex());
                                }
                                break;
                        }
                    }
                }
            }
        }
        if (controlMap != null) {
            int analogStatusOffset = typeConfigCount(MeasurementType.AnalogOutputStatus, map);
            int binaryStatusOffset = typeConfigCount(MeasurementType.BinaryOutputStatus, map);
            for (Map.Entry<ControlType, List<ControlConfig>> me : controlMap.entrySet()) {
                ControlType type = me.getKey();
                List<ControlConfig> list = me.getValue();
                for (ListIterator<ControlConfig> itr = list.listIterator(); itr.hasNext(); ) {
                    ControlConfig config = itr.next();
                    if (sourceId.equals(config.getControlId())) {
                        if (changes == null) {
                            changes = new OutstationChangeSet();
                        }
                        int index = (type == ControlType.Analog ? analogStatusOffset : binaryStatusOffset) + itr.previousIndex();
                        Object propVal = datumProps.get("value");
                        log.debug("Updating DNP3 control {}[{}] from [{}].value -> {}", type, index, sourceId, propVal);
                        switch(type) {
                            case Analog:
                                try {
                                    Number n = null;
                                    if (propVal instanceof Number) {
                                        n = (Number) propVal;
                                    } else {
                                        n = new BigDecimal(propVal.toString());
                                    }
                                    changes.update(new AnalogOutputStatus(n.doubleValue(), (byte) AnalogOutputStatusQuality.ONLINE.toType(), ts), index);
                                } catch (NumberFormatException e) {
                                    log.warn("Cannot convert control [{}] value [{}] to number: {}", sourceId, propVal, e.getMessage());
                                }
                                break;
                            case Binary:
                                changes.update(new BinaryOutputStatus(booleanPropertyValue(propVal), (byte) BinaryOutputStatusQuality.ONLINE.toType(), ts), index);
                                break;
                        }
                    }
                }
            }
        }
    }
    return changes;
}
Also used : AnalogInput(com.automatak.dnp3.AnalogInput) Counter(com.automatak.dnp3.Counter) FrozenCounter(com.automatak.dnp3.FrozenCounter) DoubleBitBinaryInput(com.automatak.dnp3.DoubleBitBinaryInput) MeasurementType(net.solarnetwork.node.io.dnp3.domain.MeasurementType) List(java.util.List) ArrayList(java.util.ArrayList) BinaryOutputStatus(com.automatak.dnp3.BinaryOutputStatus) MeasurementConfig(net.solarnetwork.node.io.dnp3.domain.MeasurementConfig) BinaryInput(com.automatak.dnp3.BinaryInput) DoubleBitBinaryInput(com.automatak.dnp3.DoubleBitBinaryInput) ControlConfig(net.solarnetwork.node.io.dnp3.domain.ControlConfig) Instant(java.time.Instant) BigDecimal(java.math.BigDecimal) OutstationChangeSet(com.automatak.dnp3.OutstationChangeSet) FrozenCounter(com.automatak.dnp3.FrozenCounter) ControlType(net.solarnetwork.node.io.dnp3.domain.ControlType) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) AnalogOutputStatus(com.automatak.dnp3.AnalogOutputStatus)

Example 2 with Counter

use of com.automatak.dnp3.Counter in project solarnetwork-node by SolarNetwork.

the class OutstationDemo method run.

public static void run(DNP3Manager manager) throws Exception {
    // Create a tcp channel class that will connect to the loopback
    Channel channel = manager.addTCPServer("client", LogMasks.NORMAL | LogMasks.APP_COMMS, ServerAcceptMode.CloseNew, "127.0.0.1", 20000, new Slf4jChannelListener());
    // Create the default outstation configuration
    OutstationStackConfig config = new OutstationStackConfig(DatabaseConfig.allValues(5), EventBufferConfig.allTypes(50));
    // Create an Outstation instance, pass in a simple a command handler that responds successfully to everything
    Outstation outstation = channel.addOutstation("outstation", SuccessCommandHandler.getInstance(), DefaultOutstationApplication.getInstance(), config);
    outstation.enable();
    // all this stuff just to read a line of text in Java. Oh the humanity.
    String line = "";
    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);
    int i = 0;
    while (true) {
        System.out.println("Enter something to update a counter or type <quit> to exit");
        line = in.readLine();
        if (line.equals("quit"))
            break;
        else {
            OutstationChangeSet set = new OutstationChangeSet();
            set.update(new Counter(i, (byte) 0x01, 0), 0);
            outstation.apply(set);
            ++i;
        }
    }
}
Also used : Slf4jChannelListener(net.solarnetwork.dnp3.util.Slf4jChannelListener) Outstation(com.automatak.dnp3.Outstation) Counter(com.automatak.dnp3.Counter) InputStreamReader(java.io.InputStreamReader) OutstationChangeSet(com.automatak.dnp3.OutstationChangeSet) Channel(com.automatak.dnp3.Channel) OutstationStackConfig(com.automatak.dnp3.OutstationStackConfig) BufferedReader(java.io.BufferedReader)

Example 3 with Counter

use of com.automatak.dnp3.Counter in project box-c by UNC-Libraries.

the class DepositSupervisor method onEvent.

/*
     * Respond to job success with more job scheduling or finish
     *
     * @see
     * net.greghaines.jesque.worker.WorkerListener#onEvent(net.greghaines.jesque
     * .worker.WorkerEvent, net.greghaines.jesque.worker.Worker,
     * java.lang.String, net.greghaines.jesque.Job, java.lang.Object,
     * java.lang.Object, java.lang.Exception)
     */
@Override
public void onEvent(WorkerEvent event, Worker worker, String queue, Job job, Object runner, Object result, Throwable t) {
    if (WorkerEvent.WORKER_POLL != event) {
        LOG.debug("WorkerEvent {}, {}, {}, {}, {}, {}, {}", new Object[] { event, worker, queue, job, runner, result, t });
    }
    String depositUUID;
    AbstractDepositJob j;
    // Job-level status logging
    switch(event) {
        case WORKER_ERROR:
            LOG.error("Worker threw an error: {}", t);
        case WORKER_START:
        case WORKER_STOP:
        case WORKER_POLL:
        case JOB_PROCESS:
            return;
        default:
    }
    depositUUID = (String) job.getArgs()[1];
    Map<String, String> status = this.depositStatusFactory.get(depositUUID);
    j = (AbstractDepositJob) runner;
    switch(event) {
        case JOB_EXECUTE:
            jobStatusFactory.started(j.getJobUUID(), j.getDepositUUID(), j.getClass());
            if (!status.containsKey(DepositField.startTime.name())) {
                // Record the deposit start time
                long depositStartTime = System.currentTimeMillis();
                String strDepositStartTime = Long.toString(depositStartTime);
                depositStatusFactory.set(depositUUID, DepositField.startTime, strDepositStartTime);
                // Check to see how long the deposit has been on the redis queue
                String strQueuedStartTime = status.get(DepositField.submitTime.name());
                long queuedStartTime = Long.parseLong(strQueuedStartTime);
                long queuedTime = depositStartTime - queuedStartTime;
                queuedDepositHist.update(queuedTime);
            }
            break;
        case JOB_SUCCESS:
            jobStatusFactory.completed(j.getJobUUID());
            LOG.debug("Registering {} as completed for {}", j.getClass().getName(), depositUUID);
            break;
        case WORKER_ERROR:
        case JOB_FAILURE:
            String jobUUID = (String) job.getArgs()[0];
            if (j != null) {
                jobUUID = j.getJobUUID();
            }
            if (t instanceof JobInterruptedException) {
                LOG.info("Job {} in deposit {} was interrupted: {}", jobUUID, depositUUID, t.getMessage());
                jobStatusFactory.interrupted(jobUUID);
                return;
            }
            if (t != null) {
                LOG.error("Job " + jobUUID + " in deposit " + depositUUID + " failed with exception", t);
                if (t instanceof JobFailedException) {
                    String details = ((JobFailedException) t).getDetails();
                    if (details != null) {
                        LOG.error("Details for failed job " + jobUUID + " in deposit " + depositUUID + ": " + details);
                    }
                }
            } else {
                LOG.error("Job " + jobUUID + " in deposit " + depositUUID + " failed");
            }
            if (t instanceof JobFailedException) {
                jobStatusFactory.failed(jobUUID, t.getLocalizedMessage());
                depositStatusFactory.fail(depositUUID, t.getLocalizedMessage());
            } else {
                jobStatusFactory.failed(jobUUID);
                String serviceName = job.getClassName().substring(job.getClassName().lastIndexOf('.') + 1);
                depositStatusFactory.fail(depositUUID, "Failed while performing service " + serviceName);
            }
            // End job timer if failed
            depositDuration(depositUUID, status);
            final Counter failed = CounterFactory.createCounter(job.getClass(), "failed-deposits");
            failed.inc();
            depositEmailHandler.sendDepositResults(depositUUID);
            return;
        default:
            break;
    }
    // Now that state from the previous job is recorded, prevent further processing if interrupted
    if (isJobPaused(status)) {
        LOG.debug("Job {} has been paused", depositUUID);
        return;
    }
    if (CleanupDepositJob.class.getName().equals(job.getClassName())) {
        LOG.debug("Job {} is cleanup job, deposit state will expire", depositUUID);
        return;
    }
    // Deposit-level actions
    List<String> successfulJobs = this.jobStatusFactory.getSuccessfulJobNames(depositUUID);
    switch(event) {
        case JOB_EXECUTE:
            if (!DepositState.running.name().equals(status.get(DepositField.state.name()))) {
                depositStatusFactory.setState(depositUUID, DepositState.running);
            }
            break;
        case JOB_SUCCESS:
            try {
                queueNextJob(job, depositUUID, status, successfulJobs);
            } catch (DepositFailedException e) {
                LOG.error("Failed to enqueue next job for deposit " + depositUUID, e);
                depositStatusFactory.fail(depositUUID);
            }
            break;
        default:
            break;
    }
}
Also used : Counter(io.dropwizard.metrics5.Counter) CleanupDepositJob(edu.unc.lib.boxc.deposit.CleanupDepositJob)

Example 4 with Counter

use of com.automatak.dnp3.Counter in project box-c by UNC-Libraries.

the class DepositSupervisor method queueNextJob.

private void queueNextJob(Job job, String depositUUID, Map<String, String> status, List<String> successfulJobs, long delay) throws DepositFailedException {
    Job nextJob = getNextJob(depositUUID, status, successfulJobs);
    if (nextJob != null) {
        LOG.info("Queuing next job {} for deposit {}", nextJob.getClassName(), depositUUID);
        enqueueJob(nextJob, status, delay);
    } else {
        depositStatusFactory.setState(depositUUID, DepositState.finished);
        final Counter finished = CounterFactory.createCounter(job.getClass(), "finished-deposits");
        finished.inc();
        depositDuration(depositUUID, status);
        depositEmailHandler.sendDepositResults(depositUUID);
        // Send message indicating the deposit has completed
        sendDepositCompleteEvent(depositUUID);
        // schedule cleanup job after the configured delay
        Job cleanJob = makeJob(CleanupDepositJob.class, depositUUID);
        LOG.info("Queuing {} for deposit {}", cleanJob.getClassName(), depositUUID);
        enqueueJob(cleanJob, status, 1000 * this.getCleanupDelaySeconds());
    }
}
Also used : Counter(io.dropwizard.metrics5.Counter) UnpackDepositJob(edu.unc.lib.boxc.deposit.normalize.UnpackDepositJob) ValidateFileAvailabilityJob(edu.unc.lib.boxc.deposit.validate.ValidateFileAvailabilityJob) ValidateContentModelJob(edu.unc.lib.boxc.deposit.validate.ValidateContentModelJob) ValidateDescriptionJob(edu.unc.lib.boxc.deposit.validate.ValidateDescriptionJob) PackageIntegrityCheckJob(edu.unc.lib.boxc.deposit.validate.PackageIntegrityCheckJob) CleanupDepositJob(edu.unc.lib.boxc.deposit.CleanupDepositJob) Job(net.greghaines.jesque.Job) FixityCheckJob(edu.unc.lib.boxc.deposit.validate.FixityCheckJob) StaffOnlyPermissionJob(edu.unc.lib.boxc.deposit.fcrepo4.StaffOnlyPermissionJob) Simple2N3BagJob(edu.unc.lib.boxc.deposit.normalize.Simple2N3BagJob) ValidateDestinationJob(edu.unc.lib.boxc.deposit.validate.ValidateDestinationJob) VocabularyEnforcementJob(edu.unc.lib.boxc.deposit.normalize.VocabularyEnforcementJob) TransferBinariesToStorageJob(edu.unc.lib.boxc.deposit.transfer.TransferBinariesToStorageJob) IngestContentObjectsJob(edu.unc.lib.boxc.deposit.fcrepo4.IngestContentObjectsJob) VirusScanJob(edu.unc.lib.boxc.deposit.validate.VirusScanJob) NormalizeFileObjectsJob(edu.unc.lib.boxc.deposit.normalize.NormalizeFileObjectsJob) BagIt2N3BagJob(edu.unc.lib.boxc.deposit.normalize.BagIt2N3BagJob) CDRMETS2N3BagJob(edu.unc.lib.boxc.deposit.normalize.CDRMETS2N3BagJob) IngestDepositRecordJob(edu.unc.lib.boxc.deposit.fcrepo4.IngestDepositRecordJob) PreconstructedDepositJob(edu.unc.lib.boxc.deposit.normalize.PreconstructedDepositJob) DirectoryToBagJob(edu.unc.lib.boxc.deposit.normalize.DirectoryToBagJob) AssignStorageLocationsJob(edu.unc.lib.boxc.deposit.normalize.AssignStorageLocationsJob) ExtractTechnicalMetadataJob(edu.unc.lib.boxc.deposit.validate.ExtractTechnicalMetadataJob)

Example 5 with Counter

use of com.automatak.dnp3.Counter in project instrumentation-java by census-instrumentation.

the class DropWizardMetricsTest method collect.

@Test
public void collect() throws InterruptedException {
    // create dropwizard metrics
    Map<String, String> tags = new HashMap<>();
    tags.put("tag1", "value1");
    tags.put("tag2", "value2");
    List<LabelKey> labelKeys = new ArrayList<>();
    List<LabelValue> labelValues = new ArrayList<>();
    for (Map.Entry<String, String> e : tags.entrySet()) {
        labelKeys.add(LabelKey.create(e.getKey(), e.getKey()));
        labelValues.add(LabelValue.create(e.getValue()));
    }
    Counter evictions = metricRegistry.counter(new MetricName("cache_evictions", tags));
    evictions.inc();
    evictions.inc(3);
    evictions.dec();
    evictions.dec(2);
    metricRegistry.gauge(new MetricName("boolean_gauge", tags), BooleanGauge::new);
    metricRegistry.gauge(new MetricName("double_gauge", tags), DoubleGauge::new);
    metricRegistry.gauge(new MetricName("float_gauge", tags), FloatGauge::new);
    metricRegistry.gauge(new MetricName("integer_gauge", tags), IntegerGauge::new);
    metricRegistry.gauge(new MetricName("long_gauge", tags), LongGauge::new);
    metricRegistry.gauge(new MetricName("notags_boolean_gauge", Collections.emptyMap()), BooleanGauge::new);
    Meter getRequests = metricRegistry.meter(new MetricName("get_requests", tags));
    getRequests.mark();
    getRequests.mark();
    Histogram resultCounts = metricRegistry.histogram(new MetricName("result", tags));
    resultCounts.update(200);
    Timer timer = metricRegistry.timer(new MetricName("requests", tags));
    Timer.Context context = timer.time();
    Thread.sleep(1L);
    context.stop();
    ArrayList<Metric> metrics = new ArrayList<>(dropWizardMetrics.getMetrics());
    assertThat(metrics.size()).isEqualTo(10);
    assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_cache_evictions_counter", "Collected from dropwizard5 (metric=cache_evictions, " + "type=io.dropwizard.metrics5.Counter)", DEFAULT_UNIT, Type.GAUGE_INT64, labelKeys));
    assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(1));
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getStartTimestamp()).isNull();
    // boolean gauge with tags
    assertThat(metrics.get(1).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_boolean_gauge_gauge", "Collected from dropwizard5 (metric=boolean_gauge, " + "type=io.opencensus.contrib.dropwizard5.DropWizardMetricsTest$BooleanGauge)", DEFAULT_UNIT, Type.GAUGE_INT64, labelKeys));
    assertThat(metrics.get(1).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(1).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(1).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(1).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(1).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(1));
    assertThat(metrics.get(1).getTimeSeriesList().get(0).getStartTimestamp()).isNull();
    assertThat(metrics.get(2).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_double_gauge_gauge", "Collected from dropwizard5 (metric=double_gauge, " + "type=io.opencensus.contrib.dropwizard5.DropWizardMetricsTest$DoubleGauge)", DEFAULT_UNIT, Type.GAUGE_DOUBLE, labelKeys));
    assertThat(metrics.get(2).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(2).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(2).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(2).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(2).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.doubleValue(1.234));
    assertThat(metrics.get(2).getTimeSeriesList().get(0).getStartTimestamp()).isNull();
    assertThat(metrics.get(3).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_float_gauge_gauge", "Collected from dropwizard5 (metric=float_gauge, " + "type=io.opencensus.contrib.dropwizard5.DropWizardMetricsTest$FloatGauge)", DEFAULT_UNIT, Type.GAUGE_DOUBLE, labelKeys));
    assertThat(metrics.get(3).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(3).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(3).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(3).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(3).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.doubleValue(0.1234000027179718));
    assertThat(metrics.get(3).getTimeSeriesList().get(0).getStartTimestamp()).isNull();
    assertThat(metrics.get(4).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_integer_gauge_gauge", "Collected from dropwizard5 (metric=integer_gauge, " + "type=io.opencensus.contrib.dropwizard5.DropWizardMetricsTest$IntegerGauge)", DEFAULT_UNIT, Type.GAUGE_DOUBLE, labelKeys));
    assertThat(metrics.get(4).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(4).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(4).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(4).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(4).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.doubleValue(1234.0));
    assertThat(metrics.get(4).getTimeSeriesList().get(0).getStartTimestamp()).isNull();
    assertThat(metrics.get(5).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_long_gauge_gauge", "Collected from dropwizard5 (metric=long_gauge, " + "type=io.opencensus.contrib.dropwizard5.DropWizardMetricsTest$LongGauge)", DEFAULT_UNIT, Type.GAUGE_DOUBLE, labelKeys));
    assertThat(metrics.get(5).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(5).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(5).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(5).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(5).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.doubleValue(1234.0));
    assertThat(metrics.get(5).getTimeSeriesList().get(0).getStartTimestamp()).isNull();
    // boolean gauge with tags
    assertThat(metrics.get(6).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_notags_boolean_gauge_gauge", "Collected from dropwizard5 (metric=notags_boolean_gauge, " + "type=io.opencensus.contrib.dropwizard5.DropWizardMetricsTest$BooleanGauge)", DEFAULT_UNIT, Type.GAUGE_INT64, Collections.emptyList()));
    assertThat(metrics.get(6).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(6).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(0);
    assertThat(metrics.get(6).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(6).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(1));
    assertThat(metrics.get(6).getTimeSeriesList().get(0).getStartTimestamp()).isNull();
    assertThat(metrics.get(7).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_get_requests_meter", "Collected from dropwizard5 (metric=get_requests, " + "type=io.dropwizard.metrics5.Meter)", DEFAULT_UNIT, Type.CUMULATIVE_INT64, labelKeys));
    assertThat(metrics.get(7).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(7).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(7).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(7).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(7).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(2));
    assertThat(metrics.get(7).getTimeSeriesList().get(0).getStartTimestamp()).isNotNull();
    assertThat(metrics.get(8).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_result_histogram", "Collected from dropwizard5 (metric=result, " + "type=io.dropwizard.metrics5.Histogram)", DEFAULT_UNIT, Type.SUMMARY, labelKeys));
    assertThat(metrics.get(8).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(8).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(8).getTimeSeriesList().get(0).getLabelValues()).isEqualTo(labelValues);
    assertThat(metrics.get(8).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(8).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.summaryValue(Summary.create(1L, 0.0, Snapshot.create(1L, 0.0, Arrays.asList(ValueAtPercentile.create(50.0, 200.0), ValueAtPercentile.create(75.0, 200.0), ValueAtPercentile.create(98.0, 200.0), ValueAtPercentile.create(99.0, 200.0), ValueAtPercentile.create(99.9, 200.0))))));
    assertThat(metrics.get(8).getTimeSeriesList().get(0).getStartTimestamp()).isInstanceOf(Timestamp.class);
    assertThat(metrics.get(9).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("dropwizard5_requests_timer", "Collected from dropwizard5 (metric=requests, " + "type=io.dropwizard.metrics5.Timer)", NS_UNIT, Type.SUMMARY, labelKeys));
    assertThat(metrics.get(9).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(9).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(tags.size());
    assertThat(metrics.get(9).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(9).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.summaryValue(Summary.create(1L, 0.0, Snapshot.create(1L, 0.0, Arrays.asList(ValueAtPercentile.create(50.0, timer.getSnapshot().getMedian()), ValueAtPercentile.create(75.0, timer.getSnapshot().get75thPercentile()), ValueAtPercentile.create(98.0, timer.getSnapshot().get98thPercentile()), ValueAtPercentile.create(99.0, timer.getSnapshot().get99thPercentile()), ValueAtPercentile.create(99.9, timer.getSnapshot().get999thPercentile()))))));
    assertThat(metrics.get(9).getTimeSeriesList().get(0).getStartTimestamp()).isInstanceOf(Timestamp.class);
}
Also used : Histogram(io.dropwizard.metrics5.Histogram) LabelValue(io.opencensus.metrics.LabelValue) HashMap(java.util.HashMap) Meter(io.dropwizard.metrics5.Meter) ArrayList(java.util.ArrayList) MetricName(io.dropwizard.metrics5.MetricName) Counter(io.dropwizard.metrics5.Counter) Timer(io.dropwizard.metrics5.Timer) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Counter (edu.princeton.cs.algs4.Counter)5 Counter (io.dropwizard.metrics5.Counter)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Counter (com.automatak.dnp3.Counter)2 OutstationChangeSet (com.automatak.dnp3.OutstationChangeSet)2 CleanupDepositJob (edu.unc.lib.boxc.deposit.CleanupDepositJob)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ControlConfig (net.solarnetwork.node.io.dnp3.domain.ControlConfig)2 ControlType (net.solarnetwork.node.io.dnp3.domain.ControlType)2 MeasurementConfig (net.solarnetwork.node.io.dnp3.domain.MeasurementConfig)2 MeasurementType (net.solarnetwork.node.io.dnp3.domain.MeasurementType)2 AnalogInput (com.automatak.dnp3.AnalogInput)1 AnalogOutputStatus (com.automatak.dnp3.AnalogOutputStatus)1 BinaryInput (com.automatak.dnp3.BinaryInput)1 BinaryOutputStatus (com.automatak.dnp3.BinaryOutputStatus)1 Channel (com.automatak.dnp3.Channel)1 DatabaseConfig (com.automatak.dnp3.DatabaseConfig)1 DoubleBitBinaryInput (com.automatak.dnp3.DoubleBitBinaryInput)1