001/* 002 * Copyright (C) 2014 Jörg Prante 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.xbib.elasticsearch.plugin.jdbc.client; 017 018import org.elasticsearch.common.metrics.CounterMetric; 019import org.elasticsearch.common.metrics.MeanMetric; 020 021import java.util.HashSet; 022import java.util.Set; 023 024public class Metric { 025 026 private long started; 027 028 private final Set<String> indexNames = new HashSet<String>(); 029 030 private final MeanMetric totalIngest = new MeanMetric(); 031 032 private final CounterMetric totalIngestSizeInBytes = new CounterMetric(); 033 034 private final CounterMetric currentIngest = new CounterMetric(); 035 036 private final CounterMetric currentIngestNumDocs = new CounterMetric(); 037 038 private final CounterMetric submitted = new CounterMetric(); 039 040 private final CounterMetric succeeded = new CounterMetric(); 041 042 private final CounterMetric failed = new CounterMetric(); 043 044 public MeanMetric getTotalIngest() { 045 return totalIngest; 046 } 047 048 public CounterMetric getTotalIngestSizeInBytes() { 049 return totalIngestSizeInBytes; 050 } 051 052 public CounterMetric getCurrentIngest() { 053 return currentIngest; 054 } 055 056 public CounterMetric getCurrentIngestNumDocs() { 057 return currentIngestNumDocs; 058 } 059 060 public CounterMetric getSubmitted() { 061 return submitted; 062 } 063 064 public CounterMetric getSucceeded() { 065 return succeeded; 066 } 067 068 public CounterMetric getFailed() { 069 return failed; 070 } 071 072 public Metric start() { 073 this.started = System.nanoTime(); 074 return this; 075 } 076 077 public long elapsed() { 078 return System.nanoTime() - started; 079 } 080 081 public Metric startBulk(String indexName) { 082 synchronized (indexNames) { 083 indexNames.add(indexName); 084 } 085 return this; 086 } 087 088 public boolean isBulk(String indexName) { 089 return indexNames.contains(indexName); 090 } 091 092 public Metric stopBulk(String indexName) { 093 synchronized (indexNames) { 094 indexNames.remove(indexName); 095 } 096 return this; 097 } 098 099 public Set<String> indices() { 100 return indexNames; 101 } 102 103}