Package org.platformlayer.ops.metrics.collectd

Source Code of org.platformlayer.ops.metrics.collectd.CollectdMetricSet

package org.platformlayer.ops.metrics.collectd;

import java.io.File;

import org.platformlayer.ResourceUtils;
import org.platformlayer.ops.Handler;
import org.platformlayer.ops.Injection;
import org.platformlayer.ops.OpsException;
import org.platformlayer.ops.filesystem.TemplatedFile;
import org.platformlayer.ops.model.metrics.MetricConfig;
import org.platformlayer.ops.tree.OpsTreeBase;

public class CollectdMetricSet extends OpsTreeBase {
  String metricKey;

  @Handler
  public void doOperation() throws OpsException {
  }

  MetricConfig metrics = null;

  public MetricConfig getMetricsInfo() throws OpsException {
    if (metrics == null) {
      metrics = ResourceUtils.findResource(getClass(), getMetricKey() + ".metrics", MetricConfig.class);
      if (metrics == null) {
        // Empty to stop reload attempts
        metrics = new MetricConfig();
      }
    }
    return metrics;
  }

  public static CollectdMetricSet build(String metricKey) {
    CollectdMetricSet metricSet = Injection.getInstance(CollectdMetricSet.class);
    metricSet.setMetricKey(metricKey);
    return metricSet;
  }

  public String getMetricKey() {
    return metricKey;
  }

  public void setMetricKey(String metricKey) {
    this.metricKey = metricKey;
  }

  @Override
  protected void addChildren() throws OpsException {
    File confDir = new File("/etc/collectd/conf");
    TemplatedFile confFile = TemplatedFile.build(Injection.getInstance(CollectdModelBuilder.class), new File(
        confDir, getMetricKey() + ".conf"));
    addChild(confFile);
  }
}
TOP

Related Classes of org.platformlayer.ops.metrics.collectd.CollectdMetricSet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.