From: <gla...@hy...> - 2009-11-13 20:26:24
|
Author: glaullon Date: 2009-11-13 12:26:13 -0800 (Fri, 13 Nov 2009) New Revision: 13945 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=13945 Added: trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/Service.java trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraMeasurement.java Modified: trunk/plugins/zimbra/etc/hq-plugin.xml trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraCollector.java trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraServerDetector.java Log: NPE solved and Zimbra 6 support Modified: trunk/plugins/zimbra/etc/hq-plugin.xml =================================================================== --- trunk/plugins/zimbra/etc/hq-plugin.xml 2009-11-13 19:53:35 UTC (rev 13944) +++ trunk/plugins/zimbra/etc/hq-plugin.xml 2009-11-13 20:26:13 UTC (rev 13945) @@ -335,10 +335,7 @@ default="Pid.PidFile.eq=%installpath%/cyrus-sasl/state/saslauthd.pid" description="PTQL for Zimbra Cyrus SASL"/> </config> - <metric name="Availability" - template="sigar:Type=ProcState,Arg=%process.query%:State" - indicator="true"/> - &process-metrics; + &multi-process-metrics; </service> <service name="Apache Httpd"> @@ -361,10 +358,7 @@ default="Pid.SudoPidFile.eq=%installpath%/log/amavisd.pid" description="PTQL for Zimbra AMaViS"/> </config> - <metric name="Availability" - template="sigar:Type=ProcState,Arg=%process.query%:State" - indicator="true"/> - &process-metrics; + &multi-process-metrics; </service> @@ -427,6 +421,59 @@ </server> + <metrics name="multi-process"> + <metric name="Availability" template="sigar:Type=ProcState,Arg=Pid.SudoPidFile.eq=%process.status%:State" indicator="true"/> + <metric name="Number of Processes" + alias="NumProcesses" + template="sigar:Type=MultiProcCpu,Arg=%process.query%:Processes" + category="UTILIZATION" + units="none" + collectionType="dynamic"/> + + <metric name="Memory Size" + alias="MemSize" + template="sigar:Type=MultiProcMem,Arg=%process.query%:Size" + category="UTILIZATION" + units="B" + collectionType="dynamic"/> + + <metric name="Resident Memory Size" + alias="ResidentMemSize" + template="sigar:Type=MultiProcMem,Arg=%process.query%:Resident" + category="UTILIZATION" + units="B" + collectionType="dynamic"/> + + <metric name="Cpu System Time" + alias="SystemTime" + template="sigar:Type=MultiProcCpu,Arg=%process.query%:Sys" + category="UTILIZATION" + units="ms" + collectionType="trendsup"/> + + <metric name="Cpu User Time" + alias="UserTime" + template="sigar:Type=MultiProcCpu,Arg=%process.query%:User" + category="UTILIZATION" + units="ms" + collectionType="trendsup"/> + + <metric name="Cpu Total Time" + alias="TotalTime" + template="sigar:Type=MultiProcCpu,Arg=%process.query%:Total" + category="UTILIZATION" + units="ms" + collectionType="trendsup"/> + + <metric name="Cpu Usage" + alias="Usage" + template="sigar:Type=MultiProcCpu,Arg=%process.query%:Percent" + category="UTILIZATION" + indicator="true" + units="percentage" + collectionType="dynamic"/> + </metrics> + <filter name="template_mailboxd" value="zimbra-stats:statsfile=%installpath%/zmstat/mailboxd.csv:${alias}"/> <filter name="template_mysql" value="zimbra-stats:statsfile=%installpath%/zmstat/mysql.csv:${alias}"/> <filter name="template_cpu" value="zimbra-stats:statsfile=%installpath%/zmstat/cpu.csv:${alias}"/> @@ -894,8 +941,9 @@ <service name="Cyrus SASL"> <config> <option name="process.query" description="Sigar PTQL Process Query"/> + <option name="process.status" description="Process PID file"/> </config> - &multi-process-metrics; + <metrics include="multi-process"/> </service> <!-- --> @@ -904,8 +952,9 @@ <plugin type="log_track" class="org.hyperic.hq.product.LogFileTailPlugin"/> <config> <option name="process.query" description="Sigar PTQL Process Query"/> + <option name="process.status" description="Process PID file"/> </config> - &multi-process-metrics; + <metrics include="multi-process"/> </service> <!-- --> @@ -913,8 +962,9 @@ <service name="HTTPD"> <config> <option name="process.query" description="Sigar PTQL Process Query"/> + <option name="process.status" description="Process PID file"/> </config> - &multi-process-metrics; + <metrics include="multi-process"/> </service> <!-- --> @@ -922,18 +972,20 @@ <service name="AMaViS" description="A Mail Virus Scanner"> <config> <option name="process.query" description="Sigar PTQL Process Query"/> + <option name="process.status" description="Process PID file"/> </config> - &multi-process-metrics; + <metrics include="multi-process"/> </service> <!-- --> - + <!-- convertd --> <service name="Convertd"> <plugin type="log_track" class="org.hyperic.hq.product.Log4JLogTrackPlugin"/> <config> <option name="process.query" default="State.Name.eq=java,Args.*.eq=com.zimbra.cs.convertd.TransformationServer" description="Sigar PTQL Process Query"/> + <option name="process.status" description="Process PID file"/> </config> - &multi-process-metrics; + <metrics include="multi-process"/> </service> <!-- --> @@ -979,7 +1031,10 @@ </service> </server> - + + <server name="Zimbra" version="6.0.x" include="Zimbra 5.0.x"> + </server> + <!-- ==================== Plugin Help =========================== --> <help name="Zimbra"> <![CDATA[ Added: trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/Service.java =================================================================== --- trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/Service.java (rev 0) +++ trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/Service.java 2009-11-13 20:26:13 UTC (rev 13945) @@ -0,0 +1,60 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.hyperic.hq.plugin.zimbra.five; + +/** + * + * @author laullon + */ +public class Service { + + private String name, pidFile, log, process; + + public Service(String name, String pidFile, String log, String process) { + this.name = name; + this.pidFile = pidFile; + this.log = log; + this.process = process; + } + + public Service(String name, String pidFile, String log) { + this.name = name; + this.pidFile = pidFile; + this.log = log; + } + + public Service(String name, String pidFile) { + this.name = name; + this.pidFile = pidFile; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the pidFile + */ + public String getPidFile() { + return pidFile; + } + + /** + * @return the log + */ + public String getLog() { + return log; + } + + /** + * @return the process + */ + public String getProcess() { + return process; + } +} Modified: trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraCollector.java =================================================================== --- trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraCollector.java 2009-11-13 19:53:35 UTC (rev 13944) +++ trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraCollector.java 2009-11-13 20:26:13 UTC (rev 13945) @@ -37,13 +37,24 @@ protected void init() { BufferedReader buffer = null; - log.debug("init() (" + getProperties() + ")"); + log.debug("init() prop=" + getProperties()); + log.debug("init() PConfig=" + getPlugin().getConfig()); try { // read 1st line of filename and create a List or String[] of the field names assert (getProperties().getProperty(STATSFILE) != null); - myStatsFile = new File(getProperties().getProperty(STATSFILE)); + String file = getProperties().getProperty(STATSFILE); + if (file == null) { + log.error("propertie '" + STATSFILE + "' not found"); + return; + } + myStatsFile = new File(file); + if (!myStatsFile.exists()) { + log.error("File '" + myStatsFile + "' no found"); + return; + } + buffer = new BufferedReader(new FileReader(myStatsFile)); String line = buffer.readLine(); if (line == null) { @@ -55,8 +66,8 @@ myAliasMap.put(new Integer(i), metrics[i].trim().replaceAll(":", "_")); } - // XXX mejorar esto // read complete file to found last line + //buffer.skip(myStatsFile.length() - 1000); while ((line = buffer.readLine()) != null) { lastLine = line; } @@ -107,7 +118,7 @@ log.debug("collect() (" + getProperties() + ")"); } if (log.isTraceEnabled()) { - log.trace("myLastLine=" + lastLine); + log.trace("[collect] ("+getProperties().getProperty("statsfile")+") myLastLine=" + lastLine); } try { if (lastLine == null) { Added: trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraMeasurement.java =================================================================== --- trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraMeasurement.java (rev 0) +++ trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraMeasurement.java 2009-11-13 20:26:13 UTC (rev 13945) @@ -0,0 +1,40 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.hyperic.hq.plugin.zimbra.five; + +import java.util.Arrays; +import org.hyperic.hq.product.MeasurementInfo; +import org.hyperic.hq.product.SigarMeasurementPlugin; +import org.hyperic.hq.product.Metric; +import org.hyperic.hq.product.MetricNotFoundException; +import org.hyperic.hq.product.MetricUnreachableException; +import org.hyperic.hq.product.MetricValue; +import org.hyperic.hq.product.PluginException; +import org.hyperic.hq.product.TypeInfo; + +/** + * + * @author laullon + */ +public class ZimbraMeasurement extends SigarMeasurementPlugin { + + public MetricValue getValue(Metric metric) throws PluginException, MetricNotFoundException, MetricUnreachableException { + MetricValue res = null; + try { + res = super.getValue(metric); + getLog().debug("--->" + res + " (" + metric + ")"); + } catch (Exception e) { + getLog().debug(e); + } + return res; + } + + public MeasurementInfo[] getMeasurements(TypeInfo info) { + getLog().debug("[getMeasurements] (" + info + ")"); + MeasurementInfo[] res = super.getMeasurements(info); + getLog().debug("[getMeasurements] (" + Arrays.asList(res) + ")"); + return res; + } +} Modified: trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraServerDetector.java =================================================================== --- trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraServerDetector.java 2009-11-13 19:53:35 UTC (rev 13944) +++ trunk/plugins/zimbra/src/org/hyperic/hq/plugin/zimbra/five/ZimbraServerDetector.java 2009-11-13 20:26:13 UTC (rev 13945) @@ -1,5 +1,6 @@ package org.hyperic.hq.plugin.zimbra.five; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FilenameFilter; import java.text.MessageFormat; @@ -12,221 +13,286 @@ import org.apache.commons.logging.LogFactory; import org.hyperic.hq.product.AutoServerDetector; import org.hyperic.hq.product.LogFileTrackPlugin; +import org.hyperic.hq.product.LogTrackPlugin; import org.hyperic.hq.product.PluginException; import org.hyperic.hq.product.ServerControlPlugin; import org.hyperic.hq.product.ServerDetector; import org.hyperic.hq.product.ServerResource; import org.hyperic.hq.product.ServiceResource; import org.hyperic.util.config.ConfigResponse; +import org.hyperic.util.exec.Execute; +import org.hyperic.util.exec.PumpStreamHandler; public class ZimbraServerDetector extends ServerDetector implements AutoServerDetector { - private static final String PROCESS_NAME = "zmmailboxdmgr"; - private static final String PROCESS_DIR = "/libexec"; - private static final String ZMSTATS_DIR = "zmstat"; - private static final String PTQL_QUERY = "State.Name.eq={0}"; - private static final String PROCESS_PID_QUERY = "Pid.SudoPidFile.eq={0}"; - private static final String PROCESS_EXEC = "State.Name.eq={0}"; - // private static final String PROCESS_CHILD_QUERY = "State.Ppid.eq={0,number,#}"; + private static final String PROCESS_NAME = "zmmailboxdmgr"; + private static final String PROCESS_DIR = "/libexec"; + private static final String ZMSTATS_DIR = "zmstat"; + private static final String PTQL_QUERY = "State.Name.eq={0}"; + private static final String PROCESS_PID_QUERY = "Pid.SudoPidFile.eq={0}"; + private static final String PROCESS_EXEC = "State.Name.eq={0}"; + private static final String PROCESS_EXEC_2 = "State.Name.ct={0}"; + // private static final String PROCESS_CHILD_QUERY = "State.Ppid.eq={0,number,#}"; + private static Log log = LogFactory.getLog(ZimbraServerDetector.class); - private static Log log = LogFactory.getLog(ZimbraServerDetector.class); + public List getServerResources(ConfigResponse platformConfig) throws PluginException { + log.debug("getServerResources(" + platformConfig + ")"); - public List getServerResources(ConfigResponse platformConfig) throws PluginException { - log.debug("getServerResources(" + platformConfig + ")"); + Object args[] = {PROCESS_NAME}; + long[] pids = getPids(MessageFormat.format(PTQL_QUERY, args)); + List list_servers = new ArrayList(); + for (int n = 0; n < pids.length; n++) { + long pid = pids[n]; + try { + String exe = getProcExe(pid); + String path = exe.substring(0, exe.length() - (PROCESS_DIR + File.separator + PROCESS_NAME).length()); + log.debug("[getServerResources] proc: (" + pid + ") " + exe + " (" + path + ")"); - String args[] = { PROCESS_NAME }; - long[] pids = getPids(MessageFormat.format(PTQL_QUERY, args)); - List list_servers = new ArrayList(); - for (int n = 0; n < pids.length; n++) { - long pid = pids[n]; - try { - String exe = getProcExe(pid); - String path = exe.substring(0, exe.length() - (PROCESS_DIR + File.separator + PROCESS_NAME).length()); - log.debug("proc: (" + pid + ") " + exe + " (" + path + ")"); - if (new File(path, ZMSTATS_DIR).exists()) { - ConfigResponse productConfig = new ConfigResponse(); - productConfig.setValue("installpath", path); + // check version + if (!checkVersion(path, getTypeInfo().getVersion())) { + return list_servers; + } + //************** - ServerResource server = new ServerResource(); - server.setType(this); - server.setName(getPlatformName() + " " + getTypeInfo().getName()); - server.setInstallPath(path); - server.setIdentifier("zimbra " + path); + File zmStatsDir = new File(path, ZMSTATS_DIR); + log.debug("[getServerResources] zmStatsDir=" + zmStatsDir.getCanonicalPath() + " (" + (zmStatsDir.exists() ? "OK" : "No OK") + ")"); + if (zmStatsDir.exists()) { + ConfigResponse productConfig = new ConfigResponse(); + productConfig.setValue("installpath", path); - // server.setProductConfig(productConfig); - setProductConfig(server, productConfig); + ServerResource server = new ServerResource(); + server.setType(this); + server.setName(getPlatformName() + " " + getTypeInfo().getName()); + server.setInstallPath(path); + server.setIdentifier("zimbra " + path); - ConfigResponse metricConfig = new ConfigResponse(); - metricConfig.setValue(LogFileTrackPlugin.PROP_FILES_SERVER, - "log/mailbox.log"); - server.setMeasurementConfig(metricConfig, - LogFileTrackPlugin.LOGLEVEL_WARN, - false); - - ConfigResponse controlConfig = new ConfigResponse(); - controlConfig.setValue(ServerControlPlugin.PROP_PROGRAMPREFIX, "/usr/bin/sudo -u zimbra"); // RHEL 5.0 - controlConfig.setValue(ServerControlPlugin.PROP_TIMEOUT, "300"); - server.setControlConfig(controlConfig); - - list_servers.add(server); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - } - } - - return list_servers; - } + // server.setProductConfig(productConfig); + setProductConfig(server, productConfig); - private final static String[][] SERVICES = { { "MySQL", "/db/mysql.pid" }, { "Postfix", "/data/postfix/spool/pid/master.pid" }, { "Log Watch", "/log/logswatch.pid" }, { "Logger MySQL", "/logger/db/mysql.pid" }, { "OpenLDAP", "/openldap/var/run/slapd.pid" }, { "Swatch", "/log/swatch.pid" }, { "MTA Config", "/log/zmmtaconfig.pid" }, { "memcached", "/log/memcached.pid" }, { "ClamAV", "/log/clamd.pid","log/clamd.log" }, { "Convertd Monitor", "/log/zmconvertdmon.pid","log/zmconvertd.log" }, { "Jetty Process", "/log/zmmailboxd_java.pid" } }; - private final static String[][] MULTI_SERVICES = { { "AMaViS", "/log/amavisd.pid" }, { "HTTPD", "/log/httpd.pid" }, { "NGINX", "/log/nginx.pid","log/nginx.log" }, { "Cyrus SASL", "/cyrus-sasl/state/saslauthd.pid" } }; - private final static String[][] OTHER_SERVICES = { { "MTAQueue Stats", "/zmstat/mtaqueue.csv" }, { "VM Stats", "/zmstat/vm.csv" } }; - - protected List discoverServices(ConfigResponse config) throws PluginException { - log.debug("discoverServices(" + config + ")"); - List services = new ArrayList(); + ConfigResponse metricConfig = new ConfigResponse(); + metricConfig.setValue(LogFileTrackPlugin.PROP_FILES_SERVER, + "log/mailbox.log"); + server.setMeasurementConfig(metricConfig, + LogFileTrackPlugin.LOGLEVEL_WARN, + false); - for (int n = 0; n < OTHER_SERVICES.length; n++) { - String[] serviceSata = OTHER_SERVICES[n]; - File csvFile = new File(config.getValue("installpath"), serviceSata[1]); - if (csvFile.exists()) { - ServiceResource service = new ServiceResource(); - service.setServiceName(serviceSata[0]); - service.setType(this, serviceSata[0]); - service.setDescription(csvFile.getAbsolutePath()); + ConfigResponse controlConfig = new ConfigResponse(); + controlConfig.setValue(ServerControlPlugin.PROP_PROGRAMPREFIX, "/usr/bin/sudo -u zimbra"); // RHEL 5.0 + controlConfig.setValue(ServerControlPlugin.PROP_TIMEOUT, "300"); + server.setControlConfig(controlConfig); - ConfigResponse props = new ConfigResponse(); - setProductConfig(service, props); + list_servers.add(server); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + } + } - ConfigResponse metricConfig = new ConfigResponse(); - if (serviceSata.length > 2) { - metricConfig.setValue(LogFileTrackPlugin.PROP_FILES_SERVICE, serviceSata[2]); - } - service.setMeasurementConfig(metricConfig); - service.setCustomProperties(new ConfigResponse()); + return list_servers; + } + private final static Service[] SERVICES = { + new Service("MySQL", "/db/mysql.pid"), + new Service("Postfix", "/data/postfix/spool/pid/master.pid"), + new Service("Log Watch", "/log/logswatch.pid"), + new Service("Logger MySQL", "/logger/db/mysql.pid"), + new Service("OpenLDAP", "/openldap/var/run/slapd.pid"), + new Service("Swatch", "/log/swatch.pid"), + new Service("MTA Config", "/log/zmmtaconfig.pid"), + new Service("memcached", "/log/memcached.pid"), + new Service("ClamAV", "/log/clamd.pid", "log/clamd.log"), + new Service("Convertd Monitor", "/log/zmconvertdmon.pid", "log/zmconvertd.log"), + new Service("Jetty Process", "/log/zmmailboxd_java.pid") + }; + private final static Service[] MULTI_SERVICES = { + new Service("AMaViS", "/log/amavisd.pid", null, "amavisd"), + new Service("HTTPD", "/log/httpd.pid"), + new Service("NGINX", "/log/nginx.pid", "log/nginx.log"), + new Service("Cyrus SASL", "/cyrus-sasl/state/saslauthd.pid") + }; + private final static Service[] OTHER_SERVICES = { + new Service("MTAQueue Stats", "/zmstat/mtaqueue.csv"), + new Service("VM Stats", "/zmstat/vm.csv") + }; - services.add(service); - } else { - log.debug("OTHER_SERVICES '" + serviceSata[0] + "(" + serviceSata[1] + ")' not found"); - } - } + private ServiceResource createService(Service serviceData, String path) { + ServiceResource service = new ServiceResource(); + service.setServiceName(serviceData.getName()); + service.setType(this, serviceData.getName()); + service.setDescription(path); - for (int n = 0; n < SERVICES.length; n++) { - String[] serviceSata = SERVICES[n]; - File pidFile = new File(config.getValue("installpath"), serviceSata[1]); - if (pidFile.exists()) { - ServiceResource service = new ServiceResource(); - service.setServiceName(serviceSata[0]); - service.setType(this, serviceSata[0]); - service.setDescription(pidFile.getAbsolutePath()); + ConfigResponse metricConfig = new ConfigResponse(); + if (serviceData.getLog() != null) { + metricConfig.setValue(LogFileTrackPlugin.PROP_FILES_SERVICE, serviceData.getLog()); + } else { + metricConfig.setValue("service.log_track.enable", "false"); + } + service.setMeasurementConfig(metricConfig); - ConfigResponse props = new ConfigResponse(); - String args[] = { pidFile.getAbsolutePath() }; - props.setValue("process.query", MessageFormat.format(PROCESS_PID_QUERY, args)); - setProductConfig(service, props); + return service; + } - ConfigResponse metricConfig = new ConfigResponse(); - if (serviceSata.length > 2) { - metricConfig.setValue(LogFileTrackPlugin.PROP_FILES_SERVICE, serviceSata[2]); - } - service.setMeasurementConfig(metricConfig); - service.setCustomProperties(new ConfigResponse()); + protected List discoverServices(ConfigResponse config) throws PluginException { + log.debug("discoverServices(" + config + ")"); + List services = new ArrayList(); - services.add(service); - } else { - log.debug("SERVICES '" + serviceSata[0] + "(" + serviceSata[1] + ")' not found"); - } - } + for (int n = 0; n < OTHER_SERVICES.length; n++) { + Service serviceData = OTHER_SERVICES[n]; + File csvFile = new File(config.getValue("installpath"), serviceData.getPidFile()); + if (csvFile.exists()) { + ServiceResource service = createService(serviceData, csvFile.getAbsolutePath()); - for (int n = 0; n < MULTI_SERVICES.length; n++) { - String[] serviceSata = MULTI_SERVICES[n]; - File pidFile = new File(config.getValue("installpath"), serviceSata[1]); - log.debug("pidFile='" + pidFile + "'"); - String args[] = { pidFile.getAbsolutePath() }; - String pQuery=MessageFormat.format(PROCESS_PID_QUERY, args); - log.debug("pQuery --> '"+pQuery+"'"); - long[] pids = getPids(pQuery); - if (pids.length > 0) { - long pid = pids[0]; - String exec = getProcExe(pid); - log.debug("'" + serviceSata[0] + "' exec='" + exec + "'"); + ConfigResponse props = new ConfigResponse(); + setProductConfig(service, props); - ServiceResource service = new ServiceResource(); - service.setServiceName(serviceSata[0]); - service.setType(this, serviceSata[0]); - service.setDescription(pidFile.getAbsolutePath()); + service.setCustomProperties(new ConfigResponse()); - ConfigResponse props = new ConfigResponse(); - String[] args2 = { new File(exec).getName() }; - props.setValue("process.query", MessageFormat.format(PROCESS_EXEC, args2)); - setProductConfig(service, props); + services.add(service); + } else { + log.debug("OTHER_SERVICES '" + serviceData.getName() + "(" + serviceData.getPidFile() + ")' not found"); + } + } - service.setMeasurementConfig(new ConfigResponse()); - service.setCustomProperties(new ConfigResponse()); + for (int n = 0; n < SERVICES.length; n++) { + Service serviceData = SERVICES[n]; + File pidFile = new File(config.getValue("installpath"), serviceData.getPidFile()); + if (pidFile.exists()) { + ServiceResource service = createService(serviceData, pidFile.getAbsolutePath()); - services.add(service); - } else { - log.debug("MULTI_SERVICES '" + serviceSata[0] + "(" + serviceSata[1] + ")' not found"); - } - } + ConfigResponse props = new ConfigResponse(); + Object args[] = {pidFile.getAbsolutePath()}; + props.setValue("process.query", MessageFormat.format(PROCESS_PID_QUERY, args)); + setProductConfig(service, props); - long[] pids = getPids("State.Name.eq=java,Args.*.eq=com.zimbra.cs.convertd.TransformationServer"); - if (pids.length > 0) { - ServiceResource service = new ServiceResource(); - service.setServiceName("Convertd"); - service.setType(this, "Convertd"); + service.setCustomProperties(new ConfigResponse()); - ConfigResponse props = new ConfigResponse(); - setProductConfig(service, props); + services.add(service); + } else { + log.debug("SERVICES '" + serviceData.getName() + "(" + serviceData.getPidFile() + ")' not found"); + } + } - ConfigResponse metricConfig = new ConfigResponse(); - metricConfig.setValue(LogFileTrackPlugin.PROP_FILES_SERVICE, - "log/convertd.log"); //relative to installpath + for (int n = 0; n < MULTI_SERVICES.length; n++) { + Service serviceData = MULTI_SERVICES[n]; + log.debug("[discoverServices] -> " + serviceData.getName()); + File pidFile = new File(config.getValue("installpath"), serviceData.getPidFile()); + log.debug("pidFile='" + pidFile + "'"); + Object args[] = {pidFile.getAbsolutePath()}; + String pQuery = MessageFormat.format(PROCESS_PID_QUERY, args); + log.debug("pQuery --> '" + pQuery + "'"); + long[] pids = getPids(pQuery); + if (pids.length > 0) { + long pid = pids[0]; + String exec = getProcExe(pid); + log.debug("'" + serviceData.getName() + "' exec='" + exec + "'"); - service.setMeasurementConfig(metricConfig); - service.setCustomProperties(new ConfigResponse()); + ServiceResource service = createService(serviceData, pidFile.getAbsolutePath()); - services.add(service); - } + ConfigResponse props = new ConfigResponse(); + if (serviceData.getProcess() != null) { + Object[] args2 = {serviceData.getProcess()}; + props.setValue("process.query", MessageFormat.format(PROCESS_EXEC_2, args2)); + } else { + Object[] args2 = {new File(exec).getName()}; + props.setValue("process.query", MessageFormat.format(PROCESS_EXEC, args2)); + } + props.setValue("process.status", pidFile.getAbsolutePath()); + setProductConfig(service, props); + log.debug("process.query = '" + props.getValue("process.query") + "'"); + log.debug("process.status ='" + pidFile.getAbsolutePath() + "'"); - // Stats Process - File dir_pids = new File(config.getValue("installpath"), "/zmstat/pid"); - String[] pids_files = dir_pids.list(new PIDFilter()); - for (int n = 0; n < pids_files.length; n++) { - String pid_file = pids_files[n]; - services.add(cerateStatService(pid_file)); - } + service.setCustomProperties(new ConfigResponse()); - return services; - } + services.add(service); + } else { + log.debug("MULTI_SERVICES '" + serviceData.getName() + "(" + serviceData.getPidFile() + ")' not found"); + } + log.debug("[discoverServices] <- " + serviceData.getName()); + } - private static Pattern p = Pattern.compile("zmstat-(.*).pid"); + long[] pids = getPids("State.Name.eq=java,Args.*.eq=com.zimbra.cs.convertd.TransformationServer"); + if (pids.length > 0) { + ServiceResource service = new ServiceResource(); + service.setServiceName("Convertd"); + service.setType(this, "Convertd"); - private ServiceResource cerateStatService(String file) { - log.debug("cerateStatService('" + file + "')"); - Matcher m = p.matcher(file); - String name = file; - if (m.matches()) - name = m.group(); - ServiceResource servicio = new ServiceResource(); - servicio.setServiceName(name); - servicio.setType(this, "Stats process"); - servicio.setDescription(file); + ConfigResponse props = new ConfigResponse(); + setProductConfig(service, props); - ConfigResponse props = new ConfigResponse(); - props.setValue("pid-file", file); - setProductConfig(servicio, props); + ConfigResponse metricConfig = new ConfigResponse(); + metricConfig.setValue(LogFileTrackPlugin.PROP_FILES_SERVICE, "log/convertd.log"); //relative to installpath + service.setMeasurementConfig(metricConfig); + service.setCustomProperties(new ConfigResponse()); - servicio.setMeasurementConfig(new ConfigResponse()); - servicio.setCustomProperties(new ConfigResponse()); - return servicio; + services.add(service); + } - } + // Stats Process + File dir_pids = new File(config.getValue("installpath"), "/zmstat/pid"); + String[] pids_files = dir_pids.list(new PIDFilter()); + for (int n = 0; n < pids_files.length; n++) { + String pid_file = pids_files[n]; + services.add(cerateStatService(pid_file)); + } - private static class PIDFilter implements FilenameFilter { - public boolean accept(File dir, String name) { - return name.endsWith(".pid"); - } - } + return services; + } + private static Pattern p = Pattern.compile("zmstat-(.*).pid"); + private ServiceResource cerateStatService(String file) { + log.debug("cerateStatService('" + file + "')"); + Matcher m = p.matcher(file); + String name = file; + if (m.matches()) { + name = m.group(); + } + ServiceResource servicio = new ServiceResource(); + servicio.setServiceName(name); + servicio.setType(this, "Stats process"); + servicio.setDescription(file); + + ConfigResponse props = new ConfigResponse(); + props.setValue("pid-file", file); + setProductConfig(servicio, props); + + ConfigResponse metricConfig = new ConfigResponse(); + metricConfig.setValue("service.log_track.enable", "false"); + servicio.setMeasurementConfig(metricConfig); + + servicio.setCustomProperties(new ConfigResponse()); + return servicio; + + } + + private static class PIDFilter implements FilenameFilter { + + public boolean accept(File dir, String name) { + return name.endsWith(".pid"); + } + } + + private boolean checkVersion(String path, String version) { + boolean res = false; + try { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + Execute exec = new Execute(new PumpStreamHandler(output)); + exec.setCommandline( + new String[]{"sudo", "-u", "zimbra", path + "/bin/zmcontrol", "-v"}); + int rc = exec.execute(); + String out = output.toString().trim(); + if (getLog().isDebugEnabled()) { + getLog().debug("output of '" + path + "/bin/zmcontrol -v' : " + out); + } + if (rc == 0) { + Pattern p = Pattern.compile(version.toLowerCase().replaceAll("x", "\\\\d*")); + Matcher m = p.matcher(out); + res = m.find(); + if (!res) { + getLog().debug("m -->" + m); + } + } + } catch (Exception e) { + getLog().warn("Could not get the version of mysql: " + e.getMessage(), e); + } + return res; + } } |