2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.collectors.datafile.model;
23 import java.time.Instant;
24 import java.util.concurrent.atomic.AtomicInteger;
27 * Various counters that can be shown via a REST API.
30 public class Counters {
32 private long noOfCollectedFiles = 0;
33 private long noOfFailedFtpAttempts = 0;
34 private long noOfFailedHttpAttempts = 0;
35 private long noOfFailedFtp = 0;
36 private long noOfFailedHttp = 0;
37 private long noOfFailedPublishAttempts = 0;
38 private long totalPublishedFiles = 0;
39 private long noOfFailedPublish = 0;
40 private Instant lastPublishedTime = Instant.MIN;
41 private long totalReceivedEvents = 0;
42 private Instant lastEventTime = Instant.MIN;
44 public final AtomicInteger threadPoolQueueSize = new AtomicInteger();
46 public synchronized void incNoOfReceivedEvents() {
47 totalReceivedEvents++;
48 lastEventTime = Instant.now();
51 public synchronized void incNoOfCollectedFiles() {
55 public synchronized void incNoOfFailedFtpAttempts() {
56 noOfFailedFtpAttempts++;
59 public synchronized void incNoOfFailedHttpAttempts() {
60 noOfFailedHttpAttempts++;
63 public synchronized void incNoOfFailedFtp() {
67 public synchronized void incNoOfFailedHttp() {
71 public synchronized void incNoOfFailedPublishAttempts() {
72 noOfFailedPublishAttempts++;
75 public synchronized void incTotalPublishedFiles() {
76 totalPublishedFiles++;
77 lastPublishedTime = Instant.now();
80 public synchronized void incNoOfFailedPublish() {
85 public synchronized String toString() {
86 StringBuilder str = new StringBuilder();
87 str.append(format("totalReceivedEvents", totalReceivedEvents));
88 str.append(format("lastEventTime", lastEventTime));
90 str.append(format("collectedFiles", noOfCollectedFiles));
91 str.append(format("failedFtpAttempts", noOfFailedFtpAttempts));
92 str.append(format("failedHttpAttempts", noOfFailedHttpAttempts));
93 str.append(format("failedFtp", noOfFailedFtp));
94 str.append(format("failedHttp", noOfFailedHttp));
96 str.append(format("totalPublishedFiles", totalPublishedFiles));
97 str.append(format("lastPublishedTime", lastPublishedTime));
99 str.append(format("failedPublishAttempts", noOfFailedPublishAttempts));
100 str.append(format("noOfFailedPublish", noOfFailedPublish));
102 return str.toString();
105 private static String format(String name, Object value) {
106 String header = name + ":";
107 return String.format("%-24s%-22s%n", header, value);
110 public long getNoOfCollectedFiles() {
111 return noOfCollectedFiles;
114 public long getNoOfFailedFtpAttempts() {
115 return noOfFailedFtpAttempts;
118 public long getNoOfFailedHttpAttempts() {
119 return noOfFailedHttpAttempts;
122 public long getNoOfFailedFtp() {
123 return noOfFailedFtp;
126 public long getNoOfFailedHttp() {
127 return noOfFailedHttp;
130 public long getNoOfFailedPublishAttempts() {
131 return noOfFailedPublishAttempts;
134 public long getTotalPublishedFiles() {
135 return totalPublishedFiles;
138 public long getNoOfFailedPublish() {
139 return noOfFailedPublish;
142 public long getTotalReceivedEvents() {
143 return totalReceivedEvents;