Web Performance is a Journey, Not a Destination

Mehdi Daoudi

Subscribe to Mehdi Daoudi: eMailAlertsEmail Alerts
Get Mehdi Daoudi via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Blog Feed Post

Raising the bar with BitBar (Mac)

Mat Ryer (@matryer) has developed a neat tool for Mac OS X that allows you to put the output from any script or program right into your menu bar. Your script can be written using BASH, Ruby, Python, PHP etc.

After stumbling across this tool, it soon became apparent this would be an excellent next victim candidate to integrate with the Catchpoint Pull API. Below is a screenshot of the tool in action.

Mac OS X integration screenshot 2http://assetsblogfly1.catchpoint.com/wp-content/uploads/2016/07/Mac-OS-X... 300w" sizes="(max-width: 380px) 100vw, 380px" />

To begin, you need to visit https://getbitbar.com and download and install BitBar (it is completely free, but donations are appreciated).

Once you have copied to your Applications folder and created your plugins folder, we can start on the integration. For this, I will mainly be using PHP.

Create your plugin filename by following the convention of {name}.{refresh}.{ext} e.g. catchpoint.5m.php. This will have the plugin run your script every five minutes in BitBar.

Below is an example script that fetches your alerts and formats them nicely for you.



/* Display Catchpoint logo on menu bar */


echo “—\n”;

/* Configure Catchpoint API Key/Secret */

$key   = ‘<Your_Catchpoint_API_Key’;

$secret = ‘<Your_Catchpoint_API_Secret>’;

/* Get Auth Token */

$data = array(‘grant_type’ => ‘client_credentials’, ‘client_id’ => $key, ‘client_secret’ => $secret);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ‘https://io.catchpoint.com/ui/api/token’);

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);


$result = json_decode($result);

/* Base64 encode the token */

$_SESSION[‘token’] = base64_encode($result->access_token);

$ch = curl_init();

/* Fetch last 5 alerts */

curl_setopt($ch, CURLOPT_URL, ‘https://io.catchpoint.com/ui/api/v1/alerts?pageSize=5’);

curl_setopt($ch, CURLOPT_HTTPHEADER,

array(‘Authorization: Bearer ‘ . $_SESSION[‘token’]));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);


$alerts = json_decode($data);

/* Apply styling to each alert */

foreach ($alerts->alerts as $a) {

switch ($a->level->id) {

case 0:

$color = ‘#ff8000’;

$state = ‘Warning’;

$emoji = ‘:neutral_face:’;


case 1:

$color = ‘#ff0000’;

$state = ‘Critical’;

$emoji = ‘:worried:’;


case 3:

$color = ‘#80ff00’;

$state = ‘OK’;

$emoji = ‘:smile:’;



echo “:clock1030: ” . $a->report_time . ” | size=10 color=” . $color. “\n”;

echo $emoji . ” Test: ” . $a->test->name . ” – ” . $state . “| size= 10 color=” . $color . ” href=http://portal.catchpoint.com/ui/Content/Charts/Performance.aspx?tList=” . $a->test->id . “&z=&chartView=1\n”;

echo “Reason: ” . $a->alert_type->name . ” | size=10 color=#000000\n”;

echo “—\n”;


Save this and make sure it is executable (chmod +x catchpoint.5m.php); you will then get your alerts (if you have any) listed in the new plugin e.g.

For additional integration you can add an extra line that will display the last alert received in your Notifications. Add the following line to the bottom of the above script:

echo exec(“osascript -e ‘display notification \”” . $a->report_time . ” – ” . $a->alert_type->name . “\” with title \”” . $a->test->name . ” – ” . $state . “\”‘”);

There you have it … Catchpoint alerts integrated right into your Mac OS X desktop! Enjoy!


The post Raising the bar with BitBar (Mac) appeared first on Catchpoint's Blog.

Read the original blog entry...

More Stories By Mehdi Daoudi

Catchpoint radically transforms the way businesses manage, monitor, and test the performance of online applications. Truly understand and improve user experience with clear visibility into complex, distributed online systems.

Founded in 2008 by four DoubleClick / Google executives with a passion for speed, reliability and overall better online experiences, Catchpoint has now become the most innovative provider of web performance testing and monitoring solutions. We are a team with expertise in designing, building, operating, scaling and monitoring highly transactional Internet services used by thousands of companies and impacting the experience of millions of users. Catchpoint is funded by top-tier venture capital firm, Battery Ventures, which has invested in category leaders such as Akamai, Omniture (Adobe Systems), Optimizely, Tealium, BazaarVoice, Marketo and many more.