Skip to content

Instantly share code, notes, and snippets.

@rokoucha
Created March 30, 2026 07:20
Show Gist options
  • Select an option

  • Save rokoucha/f5c84030d66d4a23841cf96199d41b56 to your computer and use it in GitHub Desktop.

Select an option

Save rokoucha/f5c84030d66d4a23841cf96199d41b56 to your computer and use it in GitHub Desktop.
// MongoDB拡張監視スクリプト for Mackerel
const now = Math.floor(new Date().getTime() / 1000)
const c = db.serverStatus().wiredTiger.cache
const lock = db.serverStatus().globalLock
// キャッシュヒット率 (%)
{
const ratio = (1 - c["pages read into cache"] / c["pages requested from the cache"]) * 100
print(`mongodb.cache.hit_ratio\t${ratio}\t${now}`)
}
// キャッシュ使用率 (%)
{
const ratio = c["bytes currently in the cache"] / c["maximum bytes configured"] * 100
print(`mongodb.cache.usage_ratio\t${ratio}\t${now}`)
}
// dirty page率 (%)
{
const ratio = c["tracked dirty bytes in the cache"] / c["bytes currently in the cache"] * 100
print(`mongodb.cache.dirty_ratio\t${ratio}\t${now}`)
}
// ロック待機数
{
const ratio = lock.currentQueue.readers + lock.currentQueue.writers
print(`mongodb.lock.queue_total\t${ratio}\t${now}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment