Difference between revisions of "Google charts"

From SME Server
Jump to navigationJump to search
Line 29: Line 29:
 
* Columns : number, mem_used, process_size, processors_used, period
 
* Columns : number, mem_used, process_size, processors_used, period
  
 +
the sql is below :
 +
-- MySQL dump 10.13  Distrib 5.1.73, for redhat-linux-gnu (x86_64)
 +
--
 +
-- Host: localhost    Database: apache_stats
 +
-- ------------------------------------------------------
 +
-- Server version      5.1.73
 +
 +
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
 +
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
 +
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
 +
/*!40101 SET NAMES utf8 */;
 +
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
 +
/*!40103 SET TIME_ZONE='+00:00' */;
 +
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
 +
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
 +
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
 +
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
 +
 +
--
 +
-- Table structure for table `performance`
 +
--
 +
 +
DROP TABLE IF EXISTS `performance`;
 +
/*!40101 SET @saved_cs_client    = @@character_set_client */;
 +
/*!40101 SET character_set_client = utf8 */;
 +
CREATE TABLE `performance` (
 +
  `number` int(11) NOT NULL AUTO_INCREMENT,
 +
  `mem_used` int(10) unsigned NOT NULL,
 +
  `process_size` int(10) unsigned NOT NULL DEFAULT '0',
 +
  `processors_used` int(10) unsigned NOT NULL,
 +
  `period` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 +
  PRIMARY KEY (`number`),
 +
  KEY `index` (`number`)
 +
) ENGINE=MyISAM AUTO_INCREMENT=47577 DEFAULT CHARSET=latin1;
 +
/*!40101 SET character_set_client = @saved_cs_client */;
 +
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
 +
 +
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
 +
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
 +
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
 +
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
 +
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
 +
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 +
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 +
 +
-- Dump completed on 2015-11-26 23:35:11
  
  

Revision as of 22:36, 26 November 2015

PythonIcon.png Skill level: Medium
The instructions on this page require a basic knowledge of linux.


Is this article helpful to you?
Please consider donating or volunteering
Thank you!

About

"Charts Google chart tools are powerful, simple to use, and free. Try out our rich gallery of interactive charts and data tools.


Forum discussion

This how-to can be discussed on the forums here

The rational for behind this is : You have a database / source of information that you would like to graph. In this instance, I needed to see in fairly real-time, the number of http processes as well as the size of these processes.

It could be applied to a multitude of scenarios.

Getting Started

1. Find the relevant info re; http

ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}' && echo -n 'current Apache Processes : ' && ps -C httpd --no-headers | wc -l

This outputs the following information;

Apache Memory Usage (MB): 1737.91
Average Proccess Size (MB): 75.5611
current Apache Processes : 23

2. Now we must create a database to hold the information -( how you name the database, table and the columns is up to you ), I'll use the following :

  • Database name : apache_stats
  • Table name : performance
  • Columns : number, mem_used, process_size, processors_used, period

the sql is below : -- MySQL dump 10.13 Distrib 5.1.73, for redhat-linux-gnu (x86_64) -- -- Host: localhost Database: apache_stats -- ------------------------------------------------------ -- Server version 5.1.73

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

-- -- Table structure for table `performance` --

DROP TABLE IF EXISTS `performance`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `performance` (

 `number` int(11) NOT NULL AUTO_INCREMENT,
 `mem_used` int(10) unsigned NOT NULL,
 `process_size` int(10) unsigned NOT NULL DEFAULT '0',
 `processors_used` int(10) unsigned NOT NULL,
 `period` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 PRIMARY KEY (`number`),
 KEY `index` (`number`)

) ENGINE=MyISAM AUTO_INCREMENT=47577 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2015-11-26 23:35:11


3.Prepare the collection of the relevant parameters that you want to monitor ( in this case, http stats ) create a shell script: ( apache_memory_usage_show_to_database.sh )

#/usr/bin
while true
do
LOG=outlog.txt
OUTPUT=$(ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print ":Average Proccess Size (MB): "x/((y-1)*1024)}' && echo -n ':Apache Processes: ' && ps -C httpd --no-headers | wc -l  )
DAY=$(date +"%F"+"%T")
now=$(date +'%Y-%m-%d %H:%M:%S')

echo $OUTPUT \'$DAY\' | awk  '{print "INSERT INTO performance (mem_used, process_size, processors_used,period) VALUES  ( "$5", "$10", "$13", "$14" );"}' | mysql --user=username --password=password database_name
sleep 120
done