@Override String toString(Object o) { return ((HostInfo) o).getName(); } },
public String getName() { return host.getName(); }
@Override public boolean acceptGraph(GraphNode graph, String path) { return graph.getProbe().getHost().getName().equals(hostname) && path.startsWith("/" + GraphTree.HOSTROOT + "/"); }
public String getPrefix(Probe<?, ?> probe) { String pname = probe.getName(); String hostname = probe.getHost().getName(); if(hostname.contains(".")) { String[] part = hostname.split("\\."); StringBuilder b = new StringBuilder(hostname.length()); for(int i = part.length - 1; i >= 0; i--) { b.append(part[i]); b.append("."); } hostname = b.toString(); } else { hostname = hostname + "."; } if(pname.contains(".")) { pname = pname.replace('.', '_'); } return commonPrefix + hostname + pname; }
@Override public CacheStore create(Probe<?, ?> p) { String hostname = p.getHost().getName(); String probeName = p.getName(); if(!cache.containsKey(hostname)) cache.put(hostname, new HashMap<String, Map<String, Number>>()); Map<String, Map<String, Number>> probes = cache.get(hostname); if(!probes.containsKey(probeName)) probes.put(probeName, new HashMap<String, Number>(p.getPd().getDsDefs().length)); return new CacheStore(p, probes.get(probeName)); }
/** * Return a unique name for the graph * * @return */ public String getQualifiedName() { return getHost().getName() + "/" + getName(); }
public String resolve(GraphNode graph) { return graph.getProbe().getHost().getName(); } },
/** * Return the string value of the probe as a path constituted of the host * name / the probe name * * @see java.lang.Object#toString() */ public String toString() { String hn = "<empty>"; if(getHost() != null) hn = getHost().getName(); return hn + "/" + getName(); }
public HostStarter(HostInfo host) { super(); this.host = host; this.runningname = host.getName() + ":notrunning"; registerStarter(new Resolver(host.getDnsName())); }
public HostStarter getHost(HostInfo info) { String hostName = info.getName(); HostStarter starter = hostList.get(hostName); if(starter == null) { starter = new HostStarter(info); hostList.put(hostName, starter); starter.setTimeout(getTimeout()); starter.setStep(getStep()); starter.setParent(this); } return starter; }
public Collection<int[]> getProcsOID() { boolean found = false; Collection<OID> soidSet = getIndexSet(); Collection<int[]> oids = new HashSet<int[]>(); TabularIterator ti = new TabularIterator(getConnection(), soidSet); for(SnmpVars s: ti) { List<OID> lk = new ArrayList<OID>(s.keySet()); Collections.sort(lk); StringBuilder cmdBuf = new StringBuilder(); for(OID oid: lk) { cmdBuf.append(s.get(oid)); cmdBuf.append(' '); } if(pattern.matcher(cmdBuf.toString().trim()).matches()) { int[] index = new int[1]; index[0] = lk.get(0).last(); oids.add(index); found = true; } } if(!found) { log(Level.ERROR, "index for %s not found for host %s", indexKey, getHost().getName()); oids = Collections.emptySet(); } else { log(Level.DEBUG, "found %d processes", oids.size()); log(Level.TRACE, "processes indexes found: %s", oids); } return oids; }
/** * Return a uniq name for the graph * * @return */ public String getQualifiedName() { if(probe.getHost() != null) { return probe.getHost().getName() + "/" + getName(); } else { return "/" + getName(); } }
public HostInfo makeHost(JrdsDocument n) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { JrdsElement hostNode = n.getRootElement(); String hostName = hostNode.getAttribute("name"); String dnsHostname = hostNode.getAttribute("dnsName"); if(hostName == null) { return null; } HostInfo host; if(dnsHostname != null) { host = new HostInfo(hostName, dnsHostname); } else { host = new HostInfo(hostName); } host.setHostDir(new File(pm.rrddir, host.getName())); String hidden = hostNode.getAttribute("hidden"); host.setHidden(hidden != null && Boolean.parseBoolean(hidden)); Map<String, Set<String>> collections = new HashMap<String, Set<String>>(); parseFragment(hostNode, host, collections, null); return host; }
public void collectAll() { log(Level.DEBUG, "Starting collect"); Timer timer = (Timer) getParent(); long start = System.currentTimeMillis(); startCollect(); String oldThreadName = Thread.currentThread().getName(); for(Probe<?, ?> probe: allProbes) { if(!isCollectRunning()) break; long duration = (System.currentTimeMillis() - start) / 1000; if(duration > (probe.getStep() / 2)) { log(Level.ERROR, "Collect too slow: %ds for timer %s", duration, timer); break; } log(Level.TRACE, "Starting collect for %s", probe); log(Level.DEBUG, "Collect all stats for host " + host.getName()); setRunningname(oldThreadName + "/" + probe.getName()); probe.collect(); setRunningname(oldThreadName + ":finished"); } stopCollect(); long end = System.currentTimeMillis(); float elapsed = (end - start) / 1000f; log(Level.DEBUG, "Collect time for %s: %fs", host.getName(), elapsed); }
ExtractInfo ei = ExtractInfo.get().make(ConsolFun.AVERAGE).make(start, now).make(step); for (HostInfo hi: hostsList.getHosts()) { System.out.println(hi.getName()); for (Probe<?, ?> p: hi.getProbes()) { System.out.println(" " + p.getName());
Optional.ofNullable(p.getName()).ifPresent( i-> w.key("probeinstancename").value(i)); Optional.ofNullable(p.getPd().getName()).ifPresent( i-> w.key("probename").value(i)); Optional.ofNullable(p.getHost().getName()).ifPresent( i-> w.key("hostname").value(i)); Optional.ofNullable(params.getPid()).ifPresent( i-> w.key("pid").value(i)); if(p instanceof IndexedProbe) {
public GraphNode getGraphNode(JrdsServlet caller) { GraphNode gn = null; if(id != null) gn = hostlist.getGraphById(id); if(gn != null) { logger.debug(jrds.Util.delayedFormatString("Graph found: %s", gn)); } else if(pid != null && pid != 0 && dsName != null) { if(!caller.allowed(this, hostlist.getDefaultRoles())) return null; Probe<?, ?> p = getProbe(); if(p == null) { logger.error("Looking for unknown probe"); return null; } logger.debug(jrds.Util.delayedFormatString("Probe found: %s", p)); Graphics2D g2d = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).createGraphics(); String graphDescName = p.getName() + "." + dsName; GraphDesc gd = new GraphDesc(); gd.setName(graphDescName); gd.setGraphName(p.getHost().getName() + "." + p.getName() + "." + dsName); gd.setGraphTitle(p.getName() + "." + dsName + " on ${host}"); gd.add(dsName, GraphDesc.LINE); gd.initializeLimits(g2d); gn = new GraphNode(p, gd); gn.addACL(Configuration.get().getPropertiesManager().defaultACL); } return gn; }
@Test public void testProbe2() throws Exception { JrdsDocument d = Tools.parseString(goodProbeXml2); PropertiesManager pm = Tools.makePm(testFolder); HostBuilder hb = new HostBuilder(); hb.setProbeFactory(new MokeProbeFactory()); hb.setPm(pm); hb.setTimers(Tools.getSimpleTimerMap()); HostInfo host = new HostInfo("testProbe2"); host.setHostDir(pm.rrddir); Probe<?, ?> p = hb.makeProbe(d.getRootElement(), host, null); Assert.assertNotNull(p); Assert.assertEquals(host.getName() + "/" + p.getName(), p.toString()); }