Skip to content

Instantly share code, notes, and snippets.

@MaxGabriel
MaxGabriel / ekg-yesod.md
Last active August 6, 2020 09:46
Monitoring a Yesod app with EKG

Monitoring a Yesod app with EKG

Monitoring is critical to a well-functioning production system. OS-level metrics like CPU load and RAM usage are a good start, but you'll eventually want to record application-level metrics like how long it's taking you to service each HTTP request, or how much time is spent in garbage collection. Once tracked, this data can be used by humans and machines (like monitoring systems) to gain insight into how your app is running.

In this post I'll show how you can use EKG, a popular Haskell metrics library, to add application-level metrics to your Yesod app.

A Brief Overview of EKG Metric Types

EKG allows reporting four different types of metrics from your app:

@MaxGabriel
MaxGabriel / ekgjson.json
Created April 4, 2016 02:50
Example JSON output from EKG, a Haskell monitoring tool
{
"myapp":{
"home_requests":{
"type":"c",
"val":0
}
},
"ekg":{
"server_timestamp_ms":{
"type":"c",
@MaxGabriel
MaxGabriel / redis-yesod.md
Last active March 3, 2016 20:25
Connecting to Redis from Yesod

Connecting to Redis from Yesod

This is a quick run-through of how I connected to Redis from a Yesod site (which used the default scaffolding). There isn't much specific to Redis here, so this information should apply to connecting to any database or service from Yesod.

Background: Basics of Hedis

First, a brief intro of the basics of Hedis:

{-# LANGUAGE OverloadedStrings #-}
@MaxGabriel
MaxGabriel / gist:2a8b75cfbbdc0d59245f
Created November 13, 2015 01:51
With :flatten => true
Max@maximilians-mbp ~/D/i/C/S/H/5.0.2> pod spec lint --verbose --no-clean
HZInMobi (5.0.2) - Analyzing on iOS 6.0 platform.
Preparing
Analyzing dependencies
Fetching external sources
-> Fetching podspec for `HZInMobi` from `/Users/Max/Documents/iOS/CocoapodsSource/Specs/HZInMobi/5.0.2/HZInMobi.podspec`
@MaxGabriel
MaxGabriel / gist:51c99fff419ccd759e58
Created November 13, 2015 01:18
tree in the project directory
tree
.
├── HZInMobi
├── Headers
├── Local Podspecs
│   └── HZInMobi.podspec.json
├── Manifest.lock
├── Pods.xcodeproj
│   ├── project.pbxproj
│   └── xcuserdata
@MaxGabriel
MaxGabriel / gist:83e08c0b1ae20a1e62ea
Created November 13, 2015 01:10
pod spec lint output
Max@maximilians-mbp /t/C/S/H/5.0.2> pod spec lint --verbose --no-clean
WARN: Unresolved specs during Gem::Specification.reset:
json (>= 1.7.7, ~> 1.7)
minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
HZInMobi (5.0.2) - Analyzing on iOS 6.0 platform.
Preparing
@MaxGabriel
MaxGabriel / gist:c6c1efa0287de715edbe
Created October 6, 2015 17:13
Chartboost warnings
while processing /Users/Max/Documents/iOS/ios-example-app/Chartboost.framework/Chartboost(CBTouchCallbackView.o):
warning: /Users/bob/Library/Developer/Xcode/DerivedData/Chartboost-dbglhohaluoolubfpjbzctgxcsdw/Build/Intermediates/PrecompiledHeaders/Chartboost-Prefix-gjlczopydjkegkafbxxfsnlbgwmm/Chartboost-Prefix.pch.pch: No such file or directory
while processing /Users/Max/Documents/iOS/ios-example-app/Chartboost.framework/Chartboost(CBTouchCallbackView.o):
warning: /Users/bob/Library/Developer/Xcode/DerivedData/Chartboost-dbglhohaluoolubfpjbzctgxcsdw/Build/Intermediates/PrecompiledHeaders/Chartboost-Prefix-gjlczopydjkegkafbxxfsnlbgwmm/Chartboost-Prefix.pch.pch: No object file for requested architecture
while processing /Users/Max/Documents/iOS/ios-example-app/Chartboost.framework/Chartboost(CBTouchCallbackView.o):
warning: Could not resolve external type c:objc(cs)UIView
while processing /Users/Max/Documents/iOS/ios-example-app/Chartboost.framework/Chartboost(CBTouchCallbackView.o):
warning: Could not resol
##########################################
#
# c.f. http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4
#
# Version 2.7
#
# Latest Change:
# - Supports iPhone 5 / iPod Touch 5 (uses Apple's workaround to lipo bug)
#
# Purpose:
@MaxGabriel
MaxGabriel / FlexMobileTest-app.xml
Created September 30, 2015 21:21
Application descriptor for our ANE test app
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/19.0">
<!-- Adobe AIR Application Descriptor File Template. Specifies parameters
for identifying, installing, and launching AIR applications. xmlns - The
Adobe AIR namespace: http://ns.adobe.com/air/application/3.1 The last segment
of the namespace specifies the version of the AIR runtime required for this
application to run. minimumPatchLevel - The minimum patch level of the AIR
runtime required to run the application. Optional. -->
BOOL hz_chartboost_enabled(void) {
return [HeyzapAds isNetworkInitialized:HZNetworkChartboost];
}
// Calling hz_fetch_chartboost_for_location recursively won't keep the `const char *` in memory
// Since I want to call it recursively, I immediately convert to an `NSString *` in `hz_fetch_chartboost_for_location`
void hz_fetch_chartboost_for_location_objc(NSString *location) {
if (!hz_chartboost_enabled()) {
NSLog(@"Chartboost not enabled; in 0.25 seconds");
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{