DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. How to Use Cron and Curl to Regularly Download API Performance Data

How to Use Cron and Curl to Regularly Download API Performance Data

Learn how to use cron and curl to regularly download API performance data.

Kevin Farnham user avatar by
Kevin Farnham
·
Jan. 23, 19 · Tutorial
Like (4)
Save
Tweet
Share
14.37K Views

Join the DZone community and get the full member experience.

Join For Free

API performance is critical for modern applications. People use their phones and tablets to immediately access information that is relevant to what they’re doing or thinking about right now. If your company’s objective is to provide this information, then you need to know how your product appears to your customers. If your product relies on APIs (external or internal), then you will want your team to know when your product appears partially or fully down to your customers. If your product is down, but your competitor’s product is up, the result is simple: you’ll lose customers.

API monitoring provides your company with a means to observe how your product is being perceived by your customers right now (is it up, or not?) and lets you analyze the performance of your product over time.

The API Science API provides the capability for your team to monitor the performance of all APIs that are relevant to your product, at a time cadence as low as one second, if that is what your customers expect and need.

The API Science Performance Report API provides metrics on API performance over a selectable period of time. You can choose to bin monitor results on an hourly basis or on a daily basis. In the example that is presented in this blog series, we assume that you are interested in looking at performance data on an hourly basis over the past week.

Get the Data

The first step, if you’re going to create an API performance report that is customized for your own product, is to get the data for the APIs that are critical for your product. API Science aggregates all the data from your API monitors, and this data is available in multiple formats. In this series, we will download the data in JSON format using a Linux cron that executes a curl command to download API performance data to a local server.

Ultimately (in subsequent blogs), we’ll use this data to create an example custom web site that provides your team with the essential information that would allow them to monitor critical API performance and recognize when immediate action is required.

But first, we need to get the data (which is where curl comes in) on a regular schedule (this is where cron comes in, assuming you’re working on a Unix/Linux-like operating system; note that other operating systems have similar chronological job schedulers).

The curl Code

The following curl command gathers the API performance data for the past week:

curl ‘https://api.apiscience.com/v1/monitors/1572020/performance.json?preset=lastWeek&resolution=hour’ -H ‘Authorization: Bearer xyzq…’

Here, the numeric 1572020 is the identity of the particular monitor for which you’re seeking performance data. preset=lastWeek means we’re accessing the monitor data for the past week. resolution=hour states that we want the monitor data binned by hour — for example, if the monitor is executed every minute, the 60 monitor results for each minute in that hour will be averaged to produce the cumulative data statistic. The Bearer variable is your authorization code for accessing the API Science API.

The cron Code

The cron code simply specifies the schedule for when the curl code is to be run. Specifying this varies by operating system. In many varieties of Linux, one can edit the /etc/crontab file and add a new command along with its scheduled timing.

For most modern operating systems, defining execution of a timed job is accomplished by adding a line to a text file that defines when the job should be executed and the program that is to be run at those times. It is up to the developer to ensure that the executable can find all necessary inputs and write its results to an appropriate output location.

Conclusion

In this post, I’ve illustrated that with just a few lines of code, you can access the API Science API to download performance data for an API at a regular cadence. My next posts will show how you can use the downloaded JSON data to create continuously-updated custom reports that you can provide to your team on your company’s intranet or the World Wide Web.

API Data (computing) Crons Download Monitor (synchronization)

Published at DZone with permission of Kevin Farnham, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Key Considerations When Implementing Virtual Kubernetes Clusters
  • 7 Awesome Libraries for Java Unit and Integration Testing
  • Distributed SQL: An Alternative to Database Sharding
  • 5 Factors When Selecting a Database

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: