Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
mackerel-client-php
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Takuya Arita
January 26, 2017
Technology
5.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
mackerel-client-php
Mackerel Meetup #9のLT資料です
Takuya Arita
January 26, 2017
More Decks by Takuya Arita
See All by Takuya Arita
Hosted Redash の EOL と移行ツール redash-migrate / You should know about Hosted Redash EOL and redash-migrate
ariarijp
0
3.4k
Redash で踏み出す BI 導入はじめの一歩 / DataEngineeringStudy Redash
ariarijp
1
2.8k
Redash のいま / Redash in 2021
ariarijp
2
1.2k
Redash 導入・運用を4年ぐらいやって変わったこと・変わらなかったこと / Changed and unchanged things with Redash and me
ariarijp
0
1.5k
5年前の自分に伝えたい広告 API 周辺の歩き方 / SOT Tech Night vol.1
ariarijp
1
560
使われていない、を知る / How do we know unused things in the real world?
ariarijp
0
490
MULTI_ORG について / What is MULTI_ORG in Redash
ariarijp
1
3.9k
あらためて振り返る Redash の使いどころ / Why I strongly recommend Redash
ariarijp
2
1.3k
PHP Data Structures
ariarijp
1
590
Other Decks in Technology
See All in Technology
Vue.jsのGitHubから学ぶ意思決定
yut0naga1_fa
1
120
Claude Code をローカルとサーバー上で利用した際の Bedrock 利用料をユーザー単位で一本化してみる
ohorig
0
130
Gemini Intelligence 入門 ― AppFunctions と Gemini Nano
takuroabe
0
360
アカウント統制の健康診断
kenichinakamura
1
160
S3 Filesで挑む! 八戸せんべい汁の食べ頃問題
usanchuu
0
160
Agent × Maestro で始める モバイル E2E 端末準備からテスト実行・結果確認まで
sansantech
PRO
0
140
導入から定着へ ~コーディングエージェントを日常業務に組み込む実践知~
yukisakai1225
0
220
Turning Repos into the Product Second Brain with an LLM Wiki
linedevth
0
150
freeeにおけるSoftware Factory
freee
PRO
0
380
Tofu-Controller lightning talk @ Containerday 2026
gionn
0
200
Claude Code on Bedrock で統制をかける小ネタ集/claude-code-bedrock-governance-tips
emiki
1
2k
20年間 SNS サービス「GREE」 を支えた技術の刷新と、長期運用サービスの Kubernetes へのリアーキテクト
gree_tech
PRO
0
120
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
580
Amusing Abliteration
ianozsvald
1
350
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
270
How to make the Groovebox
asonas
2
2.5k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
580
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
Side Projects
sachag
456
43k
So, you think you're a good person
axbom
PRO
2
2.2k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Transcript
mackerel-client-php @ariarijp
自己紹介 • @ariarijp(Takuya Arita) • 株式会社ココラブル ソフトウェアエンジニア • 普段はPHPを書いたりしていますが、インフラも扱 います
• mackerel-agent-pluginsにプルリクエストを送った ことがあります
Mackerelといえば
None
可視化がうれしい
Mackerelに メトリクスを送ろう
Mackerelにメトリクスを 送る方法 • mackerel-agentやプラグインを使う • mkrを使う • 各言語向けのクライアントライブラリを使う • Mackerel
APIを使う
Mackerelにメトリクスを 送る方法 • mackerel-agentやプラグインを使う • mkrを使う • 各言語向けのクライアントライブラリを使う • Mackerel
APIを使う
Mackerelの クライアントライブラリ • mackerelio/mackerel-client-go • mackerelio/mackerel-client-ruby • itchyny/mackerel-client-hs • heavenshell/py-mackerel-client
• pepabo/mackerel-rb • muddydixon/node-mackerel • ariarijp/mackerel-client-php
Mackerelの クライアントライブラリ • mackerelio/mackerel-client-go • mackerelio/mackerel-client-ruby • itchyny/mackerel-client-hs • heavenshell/py-mackerel-client
• pepabo/mackerel-rb • muddydixon/node-mackerel • ariarijp/mackerel-client-php
PHP版のクライアントを 作ってみました
None
None
導入 composer require ariarijp/mackerel-client:dev-master (2017/01/26ݱࡏ)
使ってみる (READMEに記載) <?php require __DIR__ . '/vendor/autoload.php'; $client
= new \Mackerel\Client([ 'mackerel_api_key' => 'YOUR_MACKEREL_API_KEY_HERE', ]); $host = $client->getHost('HOST_ID');
使ってみる (メトリクスを送ってみる) <?php require __DIR__ . '/vendor/autoload.php'; $client
= new \Mackerel\Client([ 'mackerel_api_key' => 'YOUR_MACKEREL_API_KEY_HERE', ]); $host = $client->getHost('HOST_ID'); $metric = [ 'hostId' => $host->id, 'time' => time(), 'name' => 'metrics.meetup.random', 'value' => mt_rand(1, 6), ]; var_dump($metric); $client->postMetrics([$metric]); ※公式ドキュメント:ホストのカスタムメトリックを投稿するを参考にしました
PHPerも気軽に メトリクスを送れる! • アプリケーション固有のメトリクスを送る • バッチ処理などの実行時間を送る • 外部APIのレスポンスタイムやエラー率を送る
メトリクスさえ送れば あとはMackerelが 可視化も監視もしてくれる
(小ネタ) Mackerelでがんばり具合を可視化する • SlackのUser Presence APIを使用 • レスポンスにはメンバー一覧とその状態が含まれる • アクティブなユーザーの数を拾い、mackerel-
client-phpを使ったPHPスクリプトでMackerelに送 る
Mackerelでがんばり具合を 可視化するコード例 <?php require __DIR__ . '/vendor/autoload.php'; function
getActiveUsersCount() { $client = new GuzzleHttp\Client(); $resp = $client->get('https://slack.com/api/users.list', [ 'query' => [ 'token' => ‘YOUR_SLACK_TOKEN’, 'presence' => '1', ], ]); $presence = json_decode($resp->getBody()->getContents()); return count(array_filter($presence->members, function ($m) { return $m->presence == 'active'; })); } $client = new \Mackerel\Client([ 'mackerel_api_key' => 'YOUR_MACKEREL_API_KEY_HERE', ]); $host = $client->getHost('HOST_ID'); $metric = [ 'hostId' => $host->id, 'time' => time(), 'name' => 'metrics.slack.active', 'value' => getActiveUsersCount(), ]; var_dump($metric); $client->postMetrics([$metric]);
Mackerelでがんばり具合を 可視化した例
Mackerelでがんばり具合を 可視化した例 やる気が急激に減っているのではなく 今日は18時から全社定例がありました activeだけに絞るの忘れてた またやる気が減っているように見えますが 月例の全社飲み会が始まったのだと思います Meetup会場に移動中
PHP x Mackerel便利 (だと思う)
PHPerのみなさまにおかれましては mackerel-client-phpの導入もご検討ください