A simple way of logging server stats

Time series data plays a crucial role in monitoring and optimizing the performance of web applications and servers. By logging and analyzing key metrics like response time and CPU usage, developers can identify bottlenecks and ensure their applications run smoothly. In this blog post, we'll explore how Umlogger can help you easily log these metrics and visualize them in a combined graph.

Step 1: Set up your account
Before you start logging your data, make sure you have an account set up with Umlogger. Sign up for an account and follow the onboarding process to get your API key, which you'll need for logging the time series data.

Step 2: Log webpage response time
To log the response time of a webpage, you can use a simple script to make an HTTP request and measure the time it takes for the server to respond. Here's an example using Python and the popular 'requests' library:

import requests import time umlogger_url = 'https://umlogger.com/p' umlogger_apikey = 'your_umlogger_api_key' url_to_monitor = 'https://example.com' start_time = time.time() response = requests.get(url_to_monitor) elapsed_time = time.time() - start_time payload = { 'record_type': 'value', 'metric_name': 'example.com response time', 'apikey': umlogger_apikey, 'value': elapsed_time } response = requests.post(umlogger_url, json=payload)

This script measures the response time of the specified URL and logs it to your Umlogger account using a simple POST request.

Step 3: Log server CPU usage
To log server CPU usage, you can use a tool like 'psutil' in Python to collect the CPU usage percentage. Here's an example:

import psutil import requests umlogger_url = 'https://umlogger.com/p' umlogger_apikey = 'your_umlogger_api_key' cpu_usage = psutil.cpu_percent() payload = { 'record_type': 'value', 'metric_name': 'CPU usage', 'apikey': umlogger_apikey, 'value': cpu_usage } response = requests.post(umlogger_url, json=payload)

This script retrieves the server's CPU usage and logs it to your Umlogger account.

Step 4: Visualize the data
Once you've logged your time series data, you can easily visualize it in your Umlogger account:

  • Log in to your Umlogger account and navigate to the 'Metrics' section.
  • Select one of the metrics, e.g. 'example.com response time'.
  • Under 'Additional metrics in graph', add your second metric 'CPU usage'
  • (optional) Adjust the multiplication factor for 'CPU usage' in order to have both graphs visible, in case they have to big difference in normal value

Conclusion:
With Umlogger, you can easily log, monitor, and visualize crucial performance metrics like webpage response time and server CPU usage. By tracking these metrics, you can identify issues, optimize your application, and ensure a seamless experience for your users. Start leveraging the power of Umlogger today and streamline your monitoring process.

This website uses cookies and similar techniques to provide you with personalized content, relevant advertising and an improved experience on our website. By using our website, you consent to our privacy policy and to the use of cookies on your device for the purposes of evaluating your usage.
Necessary cookies Analytical cookies Marketing cookies