PageRenderTime 72ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/clavain/munin/MuninNode.java

https://gitlab.com/goolic/MuninMX
Java | 916 lines | 638 code | 101 blank | 177 comment | 74 complexity | 7bec2b7d8bbba5c47e2340db75a5d5d8 MD5 | raw file
  1. /*
  2. * MuninMX
  3. * Written by Enrico Kern, kern@clavain.com
  4. * www.clavain.com
  5. *
  6. * Licensed to the Apache Software Foundation (ASF) under one
  7. * or more contributor license agreements. See the NOTICE file
  8. * distributed with this work for additional information
  9. * regarding copyright ownership. The ASF licenses this file
  10. * to you under the Apache License, Version 2.0 (the
  11. * "License"); you may not use this file except in compliance
  12. * with the License. You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing,
  17. * software distributed under the License is distributed on an
  18. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. * KIND, either express or implied. See the License for the
  20. * specific language governing permissions and limitations
  21. * under the License.
  22. */
  23. package com.clavain.munin;
  24. import com.mongodb.BasicDBObject;
  25. import java.io.BufferedReader;
  26. import java.io.InputStreamReader;
  27. import java.io.PrintStream;
  28. import java.net.InetSocketAddress;
  29. import java.net.Socket;
  30. import java.util.ArrayList;
  31. import java.util.Iterator;
  32. import java.util.StringTokenizer;
  33. import java.util.logging.Level;
  34. import java.util.logging.Logger;
  35. import static com.clavain.muninmxcd.p;
  36. import static com.clavain.muninmxcd.logger;
  37. import static com.clavain.utils.Generic.getUnixtime;
  38. import static com.clavain.muninmxcd.logMore;
  39. import static com.clavain.utils.Database.dbDeleteMissingPlugins;
  40. import static com.clavain.utils.Database.dbUpdateAllPluginsForNode;
  41. import static com.clavain.utils.Database.dbUpdatePluginForNode;
  42. import static com.clavain.utils.Database.dbUpdateLastContact;
  43. import static com.clavain.utils.Generic.isPluginIgnored;
  44. import static com.clavain.utils.Database.dbTrackLogChangedForNode;
  45. import static com.clavain.utils.Database.dbUpdateNodeDistVerKernel;
  46. import static com.clavain.utils.Database.removeOldPackageTrack;
  47. import com.clavain.utils.SocketCheck;
  48. import java.io.ByteArrayInputStream;
  49. import java.util.concurrent.CopyOnWriteArrayList;
  50. import java.util.zip.GZIPInputStream;
  51. import org.apache.commons.codec.binary.Base64;
  52. /**
  53. *
  54. * @author enricokern
  55. *
  56. */
  57. public class MuninNode
  58. {
  59. private String str_nodename;
  60. private String str_hostname = "unset";
  61. private int i_port = 4949;
  62. private String str_group;
  63. private boolean b_isRunning = false;
  64. private transient long l_lastFrontendQuery;
  65. private String str_muninVersion = "";
  66. private transient CopyOnWriteArrayList<MuninPlugin> v_loaded_plugins;
  67. private transient int i_GraphCount = 0;
  68. private int i_lastRun = 0;
  69. private Integer node_id = 0;
  70. private Integer user_id = 0;
  71. private int queryInterval = 0;
  72. private int last_plugin_load = 0;
  73. private String authpw = "";
  74. private boolean is_init = false;
  75. private boolean track_pkg = false;
  76. private boolean essentials = false;
  77. private int last_pkg_update = 0;
  78. private int last_essentials_update = 0;
  79. private transient Socket lastSocket;
  80. private String str_via = "unset";
  81. public void setQueryInterval(Integer p_int)
  82. {
  83. queryInterval = p_int;
  84. }
  85. public int getQueryInterval()
  86. {
  87. return queryInterval;
  88. }
  89. public int getGraphCount()
  90. {
  91. return i_GraphCount;
  92. }
  93. /**
  94. * @return the str_hostname
  95. */
  96. public String getHostname()
  97. {
  98. return str_hostname;
  99. }
  100. /**
  101. * @param str_hostname the str_hostname to set
  102. */
  103. public void setHostname(String str_hostname)
  104. {
  105. this.str_hostname = str_hostname;
  106. }
  107. /**
  108. * @return the i_port
  109. */
  110. public int getPort()
  111. {
  112. return i_port;
  113. }
  114. /**
  115. * @param i_port the i_port to set
  116. */
  117. public void setPort(int i_port)
  118. {
  119. this.i_port = i_port;
  120. }
  121. /**
  122. * @return the str_nodename
  123. */
  124. public String getNodename()
  125. {
  126. return str_nodename;
  127. }
  128. /**
  129. * @param str_nodename the str_nodename to set
  130. */
  131. public void setNodename(String str_nodename)
  132. {
  133. this.str_nodename = str_nodename;
  134. }
  135. /**
  136. * @return the str_group
  137. */
  138. public String getGroup()
  139. {
  140. return str_group;
  141. }
  142. /**
  143. * @param str_group the str_group to set
  144. */
  145. public void setGroup(String str_group)
  146. {
  147. this.str_group = str_group;
  148. }
  149. /**
  150. *
  151. * @return if the Thread is active or not
  152. */
  153. public boolean isRunning()
  154. {
  155. return b_isRunning;
  156. }
  157. public void setIsRunning(boolean p_isRunning)
  158. {
  159. b_isRunning = p_isRunning;
  160. }
  161. /**
  162. * will retrieve a list of loaded munin plugins for this host. If the node was never
  163. * contacted before the list is downloaded from munin-node
  164. *
  165. * @return list of plugins
  166. */
  167. public CopyOnWriteArrayList<MuninPlugin> getPluginList()
  168. {
  169. if(getLoadedPlugins() == null)
  170. {
  171. // using logger from main class because of gson throwing stackoverflow otherwise
  172. logger.info("Empty Pluginlist for " + this.getHostname() + ". Loading from munin-node...");
  173. loadPlugins();
  174. }
  175. return getLoadedPlugins();
  176. }
  177. /**
  178. * Will load the plugin list from munin-node
  179. */
  180. public boolean loadPlugins()
  181. {
  182. setLoadedPlugins(new CopyOnWriteArrayList<MuninPlugin>());
  183. String l_lastProceeded = "";
  184. try
  185. {
  186. Socket cs = new Socket();
  187. cs.setKeepAlive(false);
  188. cs.setSoLinger(true, 0);
  189. cs.setReuseAddress(true);
  190. cs.setSoTimeout(com.clavain.muninmxcd.socketTimeout);
  191. if(!str_via.equals("unset"))
  192. {
  193. cs.connect(new InetSocketAddress(this.getStr_via(), this.getPort()),com.clavain.muninmxcd.socketTimeout);
  194. }
  195. else
  196. {
  197. cs.connect(new InetSocketAddress(this.getHostname(), this.getPort()),com.clavain.muninmxcd.socketTimeout);
  198. }
  199. if(p.getProperty("kill.sockets").equals("true"))
  200. {
  201. SocketCheck sc = new SocketCheck(cs,getUnixtime());
  202. sc.setHostname(this.getHostname());
  203. com.clavain.muninmxcd.v_sockets.add(sc);
  204. }
  205. PrintStream os = new PrintStream( cs.getOutputStream() );
  206. BufferedReader in = new BufferedReader(new InputStreamReader( cs.getInputStream()) );
  207. String s = in.readLine();
  208. if(s != null)
  209. {
  210. // Set version
  211. os.println("version");
  212. Thread.sleep(150);
  213. s = in.readLine();
  214. String version = s.substring(s.indexOf(":")+1,s.length()).trim();
  215. this.str_muninVersion = version;
  216. if(authpw != null)
  217. {
  218. // if authpw is set, verify
  219. if(!authpw.trim().equals(""))
  220. {
  221. os.println("config muninmxauth");
  222. Thread.sleep(150);
  223. String apw = in.readLine();
  224. s = in.readLine();
  225. if(!apw.trim().equals(this.getAuthpw()))
  226. {
  227. logger.error("Invalid muninmxauth password for host: " + this.getHostname());
  228. cs.close();
  229. return false;
  230. }
  231. }
  232. }
  233. // check anyway if muninmxauth plugin is present
  234. else
  235. {
  236. os.println("config muninmxauth");
  237. Thread.sleep(100);
  238. String apw = in.readLine();
  239. if(!apw.trim().equals("# Unknown service"))
  240. {
  241. logger.error("no auth password given, but muninmxauth plugin present on " + this.getHostname());
  242. cs.close();
  243. return false;
  244. }
  245. s = in.readLine();
  246. }
  247. // get list of available plugins
  248. if(str_via.equals("unset"))
  249. {
  250. os.println("list");
  251. }
  252. else
  253. {
  254. os.println("list " + str_hostname);
  255. }
  256. Thread.sleep(250);
  257. s = in.readLine();
  258. // if response is empty and host is not via, do a list $hostname
  259. if(s.trim().equals("") && str_via.equals("unset"))
  260. {
  261. logger.info("Plugin Response Empty on " + this.getHostname() + " trying to load with list $hostname");
  262. os.println("list " + this.getHostname());
  263. Thread.sleep(250);
  264. s = in.readLine();
  265. }
  266. String l_tmp;
  267. StringTokenizer l_st = new StringTokenizer(s, " ");
  268. // create plugin
  269. MuninPlugin l_mp = new MuninPlugin();
  270. // negative support
  271. ArrayList<String> tmp_negatives = new ArrayList<String>();
  272. while(l_st.hasMoreTokens())
  273. {
  274. String l_strPlugin = l_st.nextToken();
  275. // check for track_pkg and muninmx essentials
  276. if(l_strPlugin.equals("muninmx_trackpkg"))
  277. {
  278. this.setTrack_pkg(true);
  279. continue;
  280. }
  281. // got essentials?
  282. if(l_strPlugin.equals("muninmx_essentials"))
  283. {
  284. this.setEssentials(true);
  285. continue;
  286. }
  287. if(isPluginIgnored(l_strPlugin.toUpperCase()))
  288. {
  289. continue;
  290. }
  291. l_mp.setPluginName(l_strPlugin);
  292. os.println("config " + l_strPlugin);
  293. // create graphs for plugin
  294. int l_iGraphsFound = 0;
  295. int l_iTmp = 0;
  296. MuninGraph l_mg = new MuninGraph();
  297. l_mg.setQueryInterval(this.getQueryInterval());
  298. while ((l_tmp = in.readLine()) != null)
  299. {
  300. if(l_tmp.startsWith("."))
  301. {
  302. break;
  303. }
  304. // collect graphs only for plugin
  305. String l_strName;
  306. String l_strType;
  307. String l_strValue;
  308. if(!l_tmp.contains("graph_") && !l_tmp.trim().equals("") && !l_tmp.contains("host_name") && !l_tmp.contains("multigraph") && !l_tmp.trim().equals("graph no") && !l_tmp.trim().equals("# Bad exit") && !l_tmp.trim().contains("info Currently our peer") && !l_tmp.trim().startsWith("#") && !l_tmp.trim().contains("Bonding interface errors"))
  309. {
  310. l_lastProceeded = l_tmp;
  311. l_strName = l_tmp.substring(0,l_tmp.indexOf("."));
  312. l_strType = l_tmp.substring(l_tmp.indexOf(".")+1,l_tmp.indexOf(" "));
  313. l_strValue = l_tmp.substring(l_tmp.indexOf(" ")+1,l_tmp.length());
  314. //System.err.println("Name: " + l_strName + " Type: " + l_strType + " Value: " + l_strValue);
  315. if(l_strType.equals("label"))
  316. {
  317. l_iTmp++;
  318. if(l_iTmp > 1)
  319. {
  320. l_mp.addGraph(l_mg);
  321. l_mg = new MuninGraph();
  322. l_mg.setQueryInterval(this.getQueryInterval());
  323. }
  324. l_mg.setGraphName(l_strName);
  325. l_mg.setGraphLabel(l_strValue);
  326. }
  327. else if(l_strType.equals("draw"))
  328. {
  329. l_mg.setGraphDraw(l_strValue);
  330. }
  331. else if(l_strType.equals("type"))
  332. {
  333. l_mg.setGraphType(l_strValue);
  334. }
  335. else if(l_strType.equals("info"))
  336. {
  337. l_mg.setGraphInfo(l_strValue);
  338. }
  339. else if(l_strType.equals("negative"))
  340. {
  341. // add to temporary negative list to set negatives later
  342. tmp_negatives.add(l_strValue);
  343. }
  344. //System.out.println(l_strName);
  345. //System.out.println(l_strType);
  346. //System.out.println(l_strValue);
  347. }
  348. else
  349. {
  350. // set plugin title
  351. if(l_tmp.contains("graph_title"))
  352. {
  353. l_mp.setPluginTitle(l_tmp.substring(12,l_tmp.length()));
  354. }
  355. // set plugin info, if any
  356. if(l_tmp.contains("graph_info"))
  357. {
  358. l_mp.setPluginInfo(l_tmp.substring(11,l_tmp.length()));
  359. }
  360. // set graph category
  361. if(l_tmp.contains("graph_category"))
  362. {
  363. l_mp.setPluginCategory(l_tmp.substring(15,l_tmp.length()));
  364. }
  365. // set graph vlabel
  366. if(l_tmp.contains("graph_vlabel"))
  367. {
  368. l_mp.setPluginLabel(l_tmp.substring(13,l_tmp.length()));
  369. }
  370. // set plugin title
  371. if(l_tmp.contains("graph_mxdraw"))
  372. {
  373. l_mp.setStr_LineMode(l_tmp.substring(13,l_tmp.length()));
  374. }
  375. }
  376. }
  377. // add to pluginlist
  378. l_mp.addGraph(l_mg);
  379. Iterator it = l_mp.getGraphs().iterator();
  380. while(it.hasNext())
  381. {
  382. MuninGraph l_mpNg = (MuninGraph) it.next();
  383. if(tmp_negatives.contains(l_mpNg.getGraphName()))
  384. {
  385. l_mpNg.setNegative(true);
  386. }
  387. }
  388. // add plugin if it got valid graphs and add nodeid (req. for alerts)
  389. if(l_mp.getGraphs().size() > 0)
  390. {
  391. l_mp.set_NodeId(this.getNode_id());
  392. getLoadedPlugins().add(l_mp);
  393. }
  394. // flush temporary negatives
  395. tmp_negatives.clear();
  396. l_mp = null;
  397. l_mp = new MuninPlugin();
  398. //String l_strGraphTitle = s.substring(s.indexOf("graph_title") + 11,s.length());
  399. //System.out.println(" - " + l_strGraphTitle);
  400. }
  401. cs.close();
  402. in.close();
  403. os.close();
  404. last_plugin_load = getUnixtime();
  405. //System.out.println(s);
  406. }
  407. else
  408. {
  409. cs.close();
  410. in.close();
  411. os.close();
  412. logger.warn("Error loading plugins on " + str_hostname + " ("+this.getNode_id()+"). Check connectivity or munin-node");
  413. }
  414. /*
  415. for (MuninPlugin l_mn : getLoadedPlugins()) {
  416. i_GraphCount = i_GraphCount + l_mn.getGraphs().size();
  417. logger.debug(l_mn.getGraphs().size() + " graphs found for plugin: " + l_mn.getPluginName().toUpperCase() + " on node: " + this.getNodename());
  418. }*/
  419. } catch (Exception ex) {
  420. logger.error("Error loading plugins on " + str_hostname + " ("+this.getNode_id()+") : " + ex.getMessage());
  421. ex.printStackTrace();
  422. return false;
  423. }
  424. return true;
  425. }
  426. public void run() {
  427. b_isRunning = true;
  428. if(this.str_via.equals("unset"))
  429. {
  430. logger.info(getHostname() + " Monitoring job started");
  431. }
  432. else
  433. {
  434. logger.info(getHostname() + " (VIA: "+this.str_via+") Monitoring job started");
  435. }
  436. int iCurTime = getUnixtime();
  437. int iPluginRefreshTime = last_plugin_load + Integer.parseInt(p.getProperty("plugin.refreshtime"));
  438. try {
  439. // update plugins, maybe we have some new :)
  440. // double try to load plugins if fail
  441. if(getPluginList().size() > 0)
  442. {
  443. if(!is_init)
  444. {
  445. logger.info("[Job: " + getHostname() + "] Updating Database");
  446. // update graphs in database too
  447. for(MuninPlugin it_pl : getPluginList()) {
  448. if(it_pl.getGraphs().size() > 0)
  449. {
  450. //logger.info(it_pl.getPluginName());
  451. dbUpdatePluginForNode(getNode_id(),it_pl);
  452. }
  453. }
  454. // delete now missing plugins
  455. dbDeleteMissingPlugins(getNode_id(),getPluginList());
  456. logger.info("[Job: " + getHostname() + "] Databaseupdate Done");
  457. is_init = true;
  458. }
  459. else
  460. {
  461. if(iCurTime > iPluginRefreshTime )
  462. {
  463. logger.info("Refreshing Plugins on " + this.getHostname());
  464. this.loadPlugins();
  465. dbUpdateAllPluginsForNode(this);
  466. }
  467. }
  468. }
  469. else
  470. {
  471. this.loadPlugins();
  472. }
  473. Socket clientSocket = new Socket();
  474. clientSocket.setSoTimeout(com.clavain.muninmxcd.socketTimeout);
  475. clientSocket.setKeepAlive(false);
  476. clientSocket.setReuseAddress(true);
  477. if(this.str_via.equals("unset"))
  478. {
  479. clientSocket.connect(new InetSocketAddress(this.getHostname(), this.getPort()),com.clavain.muninmxcd.socketTimeout);
  480. }
  481. else
  482. {
  483. clientSocket.connect(new InetSocketAddress(this.getStr_via(), this.getPort()),com.clavain.muninmxcd.socketTimeout);
  484. }
  485. lastSocket = clientSocket;
  486. SocketCheck sc = new SocketCheck(clientSocket,getUnixtime());
  487. if(p.getProperty("kill.sockets").equals("true"))
  488. {
  489. sc.setHostname(this.getHostname());
  490. com.clavain.muninmxcd.v_sockets.add(sc);
  491. }
  492. this.i_lastRun = getUnixtime();
  493. // track packages?
  494. if(this.track_pkg)
  495. {
  496. updateTrackPackages(clientSocket);
  497. }
  498. // gather essentials?
  499. if(this.essentials)
  500. {
  501. updateEssentials(clientSocket);
  502. }
  503. // update graphs for all plugins
  504. Iterator it = this.getLoadedPlugins().iterator();
  505. while(it.hasNext())
  506. {
  507. MuninPlugin l_mp = (MuninPlugin) it.next();
  508. if(logMore)
  509. {
  510. logger.info(getHostname() + " fetching graphs for " + l_mp.getPluginName().toUpperCase());
  511. }
  512. // snmp support
  513. if(!str_via.equals("unset"))
  514. {
  515. l_mp.updateAllGraps(this.getStr_via(), this.getPort(), clientSocket, getQueryInterval());
  516. }
  517. else
  518. {
  519. l_mp.updateAllGraps(this.getHostname(), this.getPort(), clientSocket, getQueryInterval());
  520. }
  521. // add all graphs to insertion queue for mongodb
  522. queuePluginFetch(l_mp.returnAllGraphs(), l_mp.getPluginName());
  523. }
  524. clientSocket.close();
  525. if(p.getProperty("kill.sockets").equals("true"))
  526. {
  527. com.clavain.muninmxcd.v_sockets.remove(sc);
  528. }
  529. sc = null;
  530. } catch (Exception ex) {
  531. logger.fatal("Error in thread for host: " + getHostname() + " : " + ex.getLocalizedMessage());
  532. ex.printStackTrace();
  533. }
  534. int iRunTime = getUnixtime() - iCurTime;
  535. dbUpdateLastContact(this.getNode_id());
  536. logger.info(getHostname() + " Monitoring job stopped - runtime: " + iRunTime);
  537. }
  538. /*
  539. * update essentials
  540. */
  541. private void updateEssentials(Socket p_socket)
  542. {
  543. String decodestr = "";
  544. try {
  545. PrintStream os = new PrintStream( p_socket.getOutputStream() );
  546. BufferedReader in = new BufferedReader(new InputStreamReader( p_socket.getInputStream()) );
  547. os.println("config muninmx_essentials");
  548. // skip first line if starts with #
  549. decodestr = in.readLine();
  550. if(decodestr.startsWith("#"))
  551. {
  552. decodestr = in.readLine();
  553. }
  554. if(decodestr.equals("."))
  555. {
  556. decodestr = in.readLine();
  557. }
  558. BasicDBObject doc = new BasicDBObject();
  559. doc.put("data", decodestr);
  560. doc.put("time",getUnixtime());
  561. doc.put("node", this.node_id);
  562. doc.put("type","essential");
  563. com.clavain.muninmxcd.mongo_essential_queue.add(doc);
  564. logger.info("Essentials Updated for Node: " + this.getHostname() + ": received base64 (length): " + decodestr.length());
  565. last_essentials_update = getUnixtime();
  566. // read following .
  567. in.readLine();
  568. } catch (Exception ex)
  569. {
  570. logger.error("Error in updateEssentials for Node " + this.getHostname() + " : " + ex.getLocalizedMessage());
  571. logger.error("updateEssentials for Node " + this.getHostname() + " received: " + decodestr);
  572. ex.printStackTrace();
  573. }
  574. }
  575. /*
  576. * update track package log
  577. */
  578. private void updateTrackPackages(Socket p_socket)
  579. {
  580. // only try to update this once per hour
  581. int curTime = getUnixtime();
  582. int lalert = this.last_pkg_update + 3600;
  583. if(lalert > curTime )
  584. {
  585. return;
  586. }
  587. String decodestr = "";
  588. try
  589. {
  590. logger.info("TrackPackages - fetching " + this.str_hostname);
  591. PrintStream os = new PrintStream( p_socket.getOutputStream() );
  592. BufferedReader in = new BufferedReader(new InputStreamReader( p_socket.getInputStream()) );
  593. os.println("config muninmx_trackpkg");
  594. // skip first line if starts with #
  595. decodestr = in.readLine();
  596. if(decodestr.startsWith("#"))
  597. {
  598. decodestr = in.readLine();
  599. }
  600. if(decodestr.equals("."))
  601. {
  602. decodestr = in.readLine();
  603. }
  604. byte[] decode = Base64.decodeBase64(decodestr);
  605. ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(decode);
  606. GZIPInputStream gzipInputStream;
  607. gzipInputStream = new GZIPInputStream(byteArrayInputStream);
  608. InputStreamReader inputStreamReader = new InputStreamReader(gzipInputStream);
  609. BufferedReader bufferedReader = new BufferedReader(inputStreamReader, 4);
  610. String read;
  611. String sum = bufferedReader.readLine();
  612. if(sum == null)
  613. {
  614. logger.error("TrackPackages - sum is null for: " + this.str_hostname);
  615. return;
  616. }
  617. String dist = bufferedReader.readLine();
  618. String ver = bufferedReader.readLine();
  619. String kernel = bufferedReader.readLine();
  620. if(dbTrackLogChangedForNode(sum, this.node_id))
  621. {
  622. logger.info("TrackPackages - packages changed, updating " + this.str_hostname);
  623. // purge old logs
  624. removeOldPackageTrack(this.node_id);
  625. dbUpdateNodeDistVerKernel(sum,dist, ver, kernel, this.node_id);
  626. int i = 0;
  627. while ((read = bufferedReader.readLine()) != null)
  628. {
  629. BasicDBObject doc = new BasicDBObject();
  630. doc.put("package", read);
  631. doc.put("time",getUnixtime());
  632. doc.put("node", this.node_id);
  633. doc.put("type","trackpkg");
  634. com.clavain.muninmxcd.mongo_essential_queue.add(doc);
  635. i++;
  636. }
  637. logger.info("TrackPackages Updated for Node: " + this.getHostname() + " ("+dist+" " + ver + " " + kernel + "). tracking " + i + " packages");
  638. }
  639. else
  640. {
  641. logger.info("TrackPackages - sum not changed since last run for Node: " + this.getHostname());
  642. }
  643. this.last_pkg_update = getUnixtime();
  644. } catch (Exception ex)
  645. {
  646. logger.error("Error in updateTrackPackages for Node " + this.getHostname() + " : " + ex.getLocalizedMessage());
  647. logger.error("updateTrackPackages for Node " + this.getHostname() + " received: " + decodestr);
  648. ex.printStackTrace();
  649. }
  650. }
  651. public void queuePluginFetch(ArrayList<MuninGraph> p_almg, String p_strPluginName)
  652. {
  653. queuePluginFetch(p_almg, p_strPluginName, 0);
  654. }
  655. /**
  656. * fill insertion queue with current graph values for each plugin
  657. */
  658. public void queuePluginFetch(ArrayList<MuninGraph> p_almg, String p_strPluginName, int p_iCustomId)
  659. {
  660. Iterator<MuninGraph> it = p_almg.iterator();
  661. while(it.hasNext())
  662. {
  663. MuninGraph mg = it.next();
  664. // prepare document object
  665. BasicDBObject doc = new BasicDBObject();
  666. doc.put("hostname", this.getHostname());
  667. doc.put("plugin", p_strPluginName);
  668. doc.put("graph", mg.getGraphName());
  669. doc.put("value", mg.getGraphValue().toString());
  670. doc.put("recv", mg.getLastGraphTime());
  671. doc.put("user_id", this.getUser_id());
  672. doc.put("nodeid", this.getNode_id());
  673. if(p_iCustomId > 0)
  674. {
  675. doc.put("customId",p_iCustomId);
  676. }
  677. // only queue if plugin is initialized or it is a if_err plugin
  678. if(mg.isInit() || p_strPluginName.startsWith("if_err") || p_strPluginName.equals("swap"))
  679. {
  680. com.clavain.muninmxcd.mongo_queue.add(doc);
  681. mg.setLastQueued(getUnixtime());
  682. logger.debug("Queued: " + this.getHostname() + " (" + p_strPluginName + " / " + mg.getGraphName() + ") Value: " + mg.getGraphValue());
  683. if(logMore)
  684. {
  685. logger.info("Queued: " + this.getHostname() + " (" + p_strPluginName + " / " + mg.getGraphName() + ") Value: " + mg.getGraphValue());
  686. }
  687. }
  688. }
  689. }
  690. /**
  691. * @return the v_loaded_plugins
  692. */
  693. public CopyOnWriteArrayList<MuninPlugin> getLoadedPlugins() {
  694. return v_loaded_plugins;
  695. }
  696. /**
  697. * @param v_loaded_plugins the v_loaded_plugins to set
  698. */
  699. public void setLoadedPlugins(CopyOnWriteArrayList<MuninPlugin> v_loaded_plugins) {
  700. this.v_loaded_plugins = v_loaded_plugins;
  701. }
  702. /**
  703. * @return the l_lastFrontendQuery
  704. */
  705. public long getLastFrontendQuery() {
  706. return l_lastFrontendQuery;
  707. }
  708. /**
  709. * @param l_lastFrontendQuery the l_lastFrontendQuery to set
  710. */
  711. public void setLastFrontendQuery(long l_lastFrontendQuery) {
  712. this.l_lastFrontendQuery = l_lastFrontendQuery;
  713. }
  714. /**
  715. * Sets lastFrontendQuery to current unixtime
  716. */
  717. public void setLastFrontendQuery()
  718. {
  719. l_lastFrontendQuery = System.currentTimeMillis() / 1000L;
  720. }
  721. private void cleanUpGraphs()
  722. {
  723. Iterator it = this.getLoadedPlugins().iterator();
  724. while(it.hasNext())
  725. {
  726. MuninPlugin l_mp = (MuninPlugin) it.next();
  727. Iterator itg = l_mp.getGraphs().iterator();
  728. while(itg.hasNext())
  729. {
  730. MuninGraph l_mg = (MuninGraph) itg.next();
  731. l_mg.setGraphValue("0");
  732. l_mg.setLastGraphValue("0");
  733. l_mg.setLastGraphValueCounter("0");
  734. }
  735. }
  736. }
  737. /**
  738. * @return the node_id
  739. */
  740. public Integer getNode_id() {
  741. return node_id;
  742. }
  743. /**
  744. * @param node_id the node_id to set
  745. */
  746. public void setNode_id(Integer node_id) {
  747. this.node_id = node_id;
  748. }
  749. /**
  750. * @return the user_id
  751. */
  752. public Integer getUser_id() {
  753. return user_id;
  754. }
  755. /**
  756. * @param user_id the user_id to set
  757. */
  758. public void setUser_id(Integer user_id) {
  759. this.user_id = user_id;
  760. }
  761. /**
  762. * @return the lastSocket
  763. */
  764. public Socket getLastSocket() {
  765. return lastSocket;
  766. }
  767. /**
  768. * @return the str_via
  769. */
  770. public String getStr_via() {
  771. return str_via;
  772. }
  773. /**
  774. * @param str_via the str_via to set
  775. */
  776. public void setStr_via(String str_via) {
  777. this.str_via = str_via;
  778. }
  779. /**
  780. * @return the authpw
  781. */
  782. public String getAuthpw() {
  783. return authpw;
  784. }
  785. /**
  786. * @param authpw the authpw to set
  787. */
  788. public void setAuthpw(String authpw) {
  789. this.authpw = authpw;
  790. }
  791. /**
  792. * @return the track_pkg
  793. */
  794. public boolean isTrack_pkg() {
  795. return track_pkg;
  796. }
  797. /**
  798. * @param track_pkg the track_pkg to set
  799. */
  800. public void setTrack_pkg(boolean track_pkg) {
  801. this.track_pkg = track_pkg;
  802. }
  803. /**
  804. * @return the essentials
  805. */
  806. public boolean isEssentials() {
  807. return essentials;
  808. }
  809. /**
  810. * @param essentials the essentials to set
  811. */
  812. public void setEssentials(boolean essentials) {
  813. this.essentials = essentials;
  814. }
  815. }