@@ -0,0 +1,2126 @@
+/*%0A * #%25L%0A * servo%0A * %25%25%0A * Copyright (C) 2011 Netflix%0A * %25%25%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A *      http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A * #L%25%0A */%0Apackage com.netflix.servo.publish;%0A%0Aimport com.google.common.base.Preconditions;%0A%0Aimport java.io.File;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0Aimport java.io.Writer;%0A%0Aimport java.util.List;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A/**%0A * Writes observations to a file. The format is a basic text file with tabs%0A * separating the fields.%0A */%0Apublic final class FileMetricObserver implements MetricObserver %7B%0A%0A    private static final Logger LOGGER =%0A        LoggerFactory.getLogger(FileMetricObserver.class);%0A%0A    private final File mFile;%0A%0A    public FileMetricObserver(File file) %7B%0A        mFile = file;%0A    %7D%0A%0A    public void update(List%3CMetric%3E metrics) %7B%0A        Preconditions.checkNotNull(metrics);%0A        Writer out = null;%0A        try %7B%0A            out = new FileWriter(mFile, true);%0A            for (Metric m : metrics) %7B%0A                out.append(m.name()).append('%5Ct')%0A                   .append(m.tags().toString()).append('%5Ct')%0A                   .append(Long.toString(m.timestamp())).append('%5Ct')%0A                   .append(m.value().toString()).append('%5Cn');%0A            %7D%0A        %7D catch (IOException e) %7B%0A            LOGGER.error(%22failed to write update to file %22 + mFile, e);%0A        %7D finally %7B%0A            if (out != null) %7B%0A                try %7B%0A                    out.close();%0A                %7D catch (IOException e) %7B%0A                    LOGGER.warn(%22close failed for file %22 + mFile, e);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

add file metric observer