{"id":33,"date":"2006-04-29T20:16:39","date_gmt":"2006-04-30T03:16:39","guid":{"rendered":"http:\/\/www.dreness.com\/blog\/archives\/33"},"modified":"2019-12-07T17:15:15","modified_gmt":"2019-12-08T00:15:15","slug":"cacti-in-tiger-server","status":"publish","type":"post","link":"https:\/\/dreness.com\/blog\/archives\/33","title":{"rendered":"Cacti in Tiger Server"},"content":{"rendered":"<h4> Install XCode <\/h4>\n<h4> Install and configure darwinports <\/h4>\n<p>Download the newest version from <a href=\"https:\/\/svn.macports.org\/repository\/macports\/downloads\/\">macosforge<\/a>.<\/p>\n<h4> Add the darwinports paths to your shell config file. e.g.<\/h4>\n<pre>PATH=\"\/opt\/local\/bin:\/opt\/local\/sbin:\/usr\/local\/bin:\/usr\/local\/sbin:$PATH\"<\/pre>\n<h4> Update the ports collection <\/h4>\n<pre>sudo port -d selfupdate<\/pre>\n<h4> Install rrdtool from darwinports <\/h4>\n<p>Execute the following to install rrdtool and all of its dependencies for you.<\/p>\n<pre>sudo port install rrdtool<\/pre>\n<h4> Local user setup <\/h4>\n<p>Create a local cacti user and a home directory for it. In your Terminal window, su to this new user and then move to the cacti home directory<\/p>\n<pre>andre@casa[~]su cacti \r\nPassword: \r\ncasa:\/Network\/Servers\/casa.dreness.com\/Volumes\/Server\/andre cacti$ cd ~ \r\ncasa:~ cacti$<\/pre>\n<h4> Download cacti from <a href=\"https:\/\/www.cacti.net\/download_cacti.php\">http:\/\/www.cacti.net\/download_cacti.php<\/a> and decompress the archive <\/h4>\n<pre>casa:~ cacti$ curl -O https:\/\/www.cacti.net\/downloads\/cacti-0.8.6g.tar.gz \r\n% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current \r\n                                Dload  Upload   Total   Spent    Left  Speed\r\n100 1051k  100 1051k    0     0   184k      0  0:00:05  0:00:05 --:--:--  216k \r\ncasa:~ cacti$ gunzip cacti-0.8.6g.tar.gz \r\ncasa:~ cacti$ tar -xf cacti-0.8.6g.tar \r\ncasa:~ cacti$ cd cacti-0.8.6g \r\ncasa:~\/cacti-0.8.6g cacti$<\/pre>\n<p>Create a symlink to the cacti directory from the web document root (do this as an admin user)<\/p>\n<pre>andre@casa[~]ln -s ~cacti\/cacti-0.8.6g \/Library\/WebServer\/Documents\/cacti<\/pre>\n<h4> Inititalize MySQL <\/h4>\n<p>Use the MySQL Manager application to install and enable mysql. You do not need to enable network connections. As an alternative to the MySQL Manager, do the following as an admin user:<\/p>\n<pre>sudo mysql_install_db \r\nsudo chown -R mysql \/var\/mysql \r\nsudo chmod +rx \/var\/mysql<\/pre>\n<p>Edit \/etc\/hostconfig, adding<\/p>\n<pre>MYSQL=-YES-<\/pre>\n<h4> Start MySQL<\/h4>\n<pre>sudo SystemStarter start MySQL<\/pre>\n<h4> Set the mysql root password<\/h4>\n<pre>sudo mysqladmin -u root password <new password><\/pre>\n<h4> Create the cacti database<\/h4>\n<pre>mysqladmin --user=root -p create cacti<\/pre>\n<h4> Import the cacti database (as the cacti user while inside the cacti source folder)<\/h4>\n<pre>casa:~\/cacti-0.8.6g cacti$ mysql -u root -p cacti < cacti.sql<\/pre>\n<h4> Create the cacti mysql user<\/h4>\n<pre>mysql -u root -p mysql \r\nGRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'password';<\/pre>\n<h4> Configure Apache and PHP <\/h4>\n<p>Enable the php module in Apache. This can be done either in the \"Modules\" portion of the Web settings in Server Admin, or by editing the \/etc\/httpd\/httpd.conf file and uncommenting these two lines:<\/p>\n<pre>LoadModule php4_module           libexec\/httpd\/libphp4.so\r\nAddModule mod_php4.c<\/pre>\n<h4>Start the Web service using Server Admin<\/h4>\n<p>This will start Apache and configure it to start at system boot time. As an alternative to Server Admin for enabling Apache, start or restart apache using apachectl:<\/p>\n<pre>sudo apachectl graceful<\/pre>\n<p>Verify that apache will start at system boot time by editing \/etc\/hostconfig to include:<\/p>\n<pre>WEBSERVER=-YES-<\/pre>\n<h4>Cacti configuration<\/h4>\n<p>As your cacti user, while inside the cacti source directory, edit include\/config.php to include the apporiate details for making mysql connections. e.g.<\/p>\n<pre>$database_type = \"mysql\"; \r\n$database_default = \"cacti\"; \r\n$database_hostname = \"localhost\"; \r\n$database_username = \"cacti\"; \r\n$database_password = \"pass\";<\/pre>\n<h4>Configure the cacti user's crontab<\/h4>\n<p>Use a crontab configuration such as:<\/p>\n<pre>echo \"*\/5 * * * * php \/Library\/WebServer\/Documents\/cacti\/poller.php > \/dev\/null 2>&1\" | crontab<\/pre>\n<h4>Cacti web-based setup<\/h4>\n<p>Hit the cacti page and proceed with the web-based setup, e.g. . Advance through the first screen, and at the next, choose \"new install\". Change the binary location for rrdtool if necessary. It should be at \/opt\/local\/bin\/rrdtool. Once the setup is complete, log in as admin \/ admin and change password. <b>Be sure to change the rrd tool version to 1.2.x in the Configuration --> Settings menu<\/b>.<\/p>\n<h4>Extending Cacti<\/h4>\n<p>Once installed, you may wish to create custom scripts in order to monitor \/ graph things that are not accounted for by default templates.<\/p>\n<p>Because netsnmp in darwin (edit: even still, as of tiger) doesn't report on cpu utilization in the .1.3.6.1.4.1.2021.11 tree (basically I'm looking for user | system | idle), I had to write my own scripts to produce this data. <\/p>\n<p>Here's one I'm calling 'cpumon.pl'; it's placed in ~\/bin. <\/p>\n<pre>\r\n#!\/usr\/bin\/perl -w \r\n# get iostat output \r\nchomp ($cpuinfo = `iostat -C -d -n 1 -c 2 | tail -n 1 | awk '{print \\$4 \" \" \\$5 \" \" \\$6}'`); \r\n@cpuinfo = split(\/\\s\/, $cpuinfo); \r\n#print \"1 is $cpuinfo[0], 2 is $cpuinfo[1], 3 is $cpuinfo[2]\\n\"; \r\n$user = $cpuinfo[0]; \r\n$system = $cpuinfo[1]; \r\n$idle = $cpuinfo[2]; \r\nif ($system == \"0100\") { \r\n  print \"0\\n0\\n100\\n\";\r\n  } else {\r\n  print \"$user\\n$system\\n$idle\\n\";\r\n}; <\/pre>\n<p>Note the -c = 2 in the iostat invocation. If you only get one sample, iostat reports values that are averaged from boot time, which is not what we want. We're looking for more of a gauge style value, so the second sample is averaged over the last 1 second, which is fine. I'm also using -n 1 to restrict the number of monitored disks to exactly 1; we need this to be sure of the relative locations of the fields we actually do need (which are normally printed after the disk stats); if there were more disks, the fields we need would no longer be 4, 5 and 6. To complicate matters, if the system is 100% idle (don't ask me how that occurs while this script is running, but it does), iostat will report 0 0100 instead of 0 0 100, thus causing $system to contain 0100 and $idle to be undefined; hence the conditional at the end. <\/p>\n<p>Also note that the scripts produce multi-line output, with one value per line. <\/p>\n<p>Now that we have a functional \"cpumon.pl\" sript, we can edit snmpd.conf to add:<br \/>\nCode:<\/p>\n<pre>exec 1.3.6.1.4.1.2021.8.1.101 cpumon \/Users\/andre\/bin\/cpumon.pl<\/pre>\n<p>Because we are specifying an OID in the exec line, snmpd will put the resulting output into a 'table', rooted at the given OID. This basically means that each line of script output will be placed into an OID beneath the given one. ... and the resulting OIDs are: <\/p>\n<pre>.1.3.6.1.4.1.2021.8.1.101.101.1 \r\n.1.3.6.1.4.1.2021.8.1.101.101.2 \r\n.1.3.6.1.4.1.2021.8.1.101.101.3<\/pre>\n<p>... and if we query those OIDs: <\/p>\n<pre>andre@IP41-89[~]snmpget -c blah -v 1 host.com \r\n.1.3.6.1.4.1.2021.8.1.101.101.1 .1.3.6.1.4.1.2021.8.1.101.101.2 .1.3.6.1.4.1.2021.8.1.101.101.3 \r\nUCD-SNMP-MIB::extOutput.101.1 = STRING: 2 \r\nUCD-SNMP-MIB::extOutput.101.2 = STRING: 8 \r\nUCD-SNMP-MIB::extOutput.101.3 = STRING: 90<\/pre>\n<p>... it does exactly what we want. .1 is user, .2 is system, and .3 is idle <\/p>\n<p>Okay, getting closer. Now we have three OIDs to query for each of the three values related to CPU usage. <\/p>\n<p>Now we have to create new data templates to point at our new OIDs. It's not all that easy to create new templates, it seems, so it's easier to duplicate an existing data template; makes sense to start with the ucd template for 'nice' cpu, for example. After duplicating that template with a new name (darwin-cpu-idle), we need to modify our new template to point at the OID for idle, which is .1.3.6.1.4.1.2021.8.1.101.101.3. Also, feel free to change the 'internal data source name' to something unique, such as darwin_cpu_idle. Verify that the type is set to GAUGE and the query type is Get SNMP Data. <\/p>\n<p>Duplicate your new template twice more for the 'system' and 'user' OIDs, changing the OID and names as appropriate. <\/p>\n<p>Now we're ready to head into \"Data Sources\" and set up three new sources for each of the three new values we're monitoring. Create three new sources, set the \"Selected Data Template\" to one of the three new templates you created (they should appear in the popout menu), and change the names as necessary. Associate the source with one of your existing polling hosts for maximum ease. <\/p>\n<p>Before we build the graph, we need to modify the existing CPU Usage graph template. The template expects system, user and nice, but we have system, user and idle. Duplicate the \"ucd\/net - CPU Usage \" template, and then edit it. Rename the \"nice\" column to \"idle\", and delete the last 4 \"Graph Template Items\" - they correspond to \"total cpu\", which we don't have. (Actually I prefer to delete idle and total, so that only system and user are graphed). Modify all of the items in the graph template to use the appropriate data sources that we created earlier. Do this by clicking on \"Item # 1\" under the \"Graph Item\" column heading, and then choosing the appropriate data source from the popout menu. <\/p>\n<p>Now, finally, we are ready to actually build the graph. The good news is that by this point, you should already have collected some data :) Head over to \"Graph Management\", click \"Add\", select your new graph template and choose a host from the list. Set the \"graph item inputs\" to each correspond to the appropriate data source. That should be it! <\/p>\n<p>Finally, thanks to axon for his innane knowledge of the ascii characterset :) <\/p>\n<p>I have uploaded the Mac OS X host template file which includes all the dependencies. This should give you all the cacti configuration you need to monitor mac os x hosts for cpu, # of TCP connections, and # of NetInfo connections (I'm sure that last one will be super useful for ya ;). This template represents the cacti side of the configuration; you still need to set up the snmpd.conf files and the scripts to gather the necessary date. Examine the new data templates to make sure that the output from the scripts you call from snmpd.conf goes to the right OIDs. <\/p>\n<p><a href=\"https:\/\/dreness.com\/bits\/lj\/cacti_host_template_mac_os_x.xml\">http:\/\/www.dreness.com\/bits\/lj\/cacti_host_template_mac_os_x.xml<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install XCode Install and configure darwinports Download the newest version from macosforge. Add the darwinports paths to your shell config file. e.g. PATH=&#8221;\/opt\/local\/bin:\/opt\/local\/sbin:\/usr\/local\/bin:\/usr\/local\/sbin:$PATH&#8221; Update the ports collection sudo port -d selfupdate Install rrdtool from darwinports Execute the following to install &hellip; <a href=\"https:\/\/dreness.com\/blog\/archives\/33\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,10],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-os-x","category-os-x-server","category-tutorials"],"_links":{"self":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":5,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":1307,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions\/1307"}],"wp:attachment":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}