♊️ GemiNews 🗞️
(dev)
🏡
📰 Articles
🏷️ Tags
🧠 Queries
📈 Graphs
☁️ Stats
💁🏻 Assistant
💬
🎙️
Demo 1: Embeddings + Recommendation
Demo 2: Bella RAGa
Demo 3: NewRetriever
Demo 4: Assistant function calling
Editing article
Title
Summary
Content
<h3>My Mac’s battery🔋 on Google Cloud Monitoring — send SMS if low 🪫</h3><blockquote><em>This article shows how you can easily inject a generic key/value into Google Cloud Monitoring and set up alerts on it. I use it to alert on disk space, and now also low battery!</em></blockquote><p>This morning I was in London, and I forgot my charger at home. With plenty of time but 🪫 little battery, I thought: <em>hey! I need to have a way to predict when my battery is low! And I need to do it in a totally overkill way!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yk6qFPAm6Y3Hwo5t" /><figcaption>Catching an early train from St Pancras to Stratford Intl then London City Airport.</figcaption></figure><p>My battery was at <strong>42%</strong>, which seemed a subtle indication my idea was worth blogging. Googling around, I found <a href="https://www.iphonetricks.org/check-battery-health-on-mac-using-terminal/">an article</a> which gave me the tip on how to script my Mac’s battery (note this only works for a <strong>Macbook</strong>).</p><p>Ugly code <a href="https://github.com/palladius/sakura/blob/master/bin/macbook-battery#L107-L150">here</a> (hey! I’m in an airport with no charger, do you want Unit tests too?!?)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/085df68699c21b7f54f45721065c2813/href">https://medium.com/media/085df68699c21b7f54f45721065c2813/href</a></iframe><p>I know, I call the same command 10 times and I could cache it. This is for the next iteration!</p><p>The best part of this is, not only I get my battery life, it also gives me my battery durability — so when I need to change battery. Woohoo!</p><p>There you go, let’s try it out, let me just remove the cable so you dont get a boring 100%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VVFX7-q7pyNbZaFayRGLmg.png" /><figcaption>Battery level is 98%. Unfortunately 14% of my battery potential seems gone 😢</figcaption></figure><p>Battery is 98%, yay! Unfortunately seems like ~14% of my battery is gone. Luckily I don’t pay for its repair :)</p><h4>Step 2: push this metric to the ☁ ️(GCP)</h4><p>Now, I want a script which emits my metric from CLI. So I can say something like push-to-gcp <METRIC_NAME> <METRIC_VALUE>.</p><p>I’ve coded my disk space a month ago, let me abstract it into some more reusable code (always Ruby): <a href="https://github.com/palladius/sakura/blob/master/bin/gcp-write-metric">palladius/sakura/gcp-write-metric</a> .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href">https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href</a></iframe><p>Ok! Now let’s try it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*fFPP3gWU1mMpCUXLAyeBrQ.png" /><figcaption>Created the timeseries ‘<strong>prova</strong>’ (test in italian) with meaningful number <strong>123</strong>! Wow!</figcaption></figure><p>Note you need to specify the project_id via ENV var (coming soon, the — project option, or better the project_id auto inferral from gcloud config).</p><p>Let’s now glue the two scripts and upload the two Macbook info and see on the DevConsole:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49258a59c0117f1018504c211725d963/href">https://medium.com/media/49258a59c0117f1018504c211725d963/href</a></iframe><p>This script requires a project_id in ARGV, then it does the work for you, knowing the fields which are useful from macbook-battery are coming from values 3 and 5 (yes, a JSON encoding/parsing would be less error prone!). Let’s call it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*CTX7IrQJgpI8qoFRDyA6Ug.png" /><figcaption>Meanwhile I went home, and launched this on my other M1 Mac. Always, boringly, attached to the current. Destined to an infinite life between 99 and 100%. Wait — this Mac, although charged, is on hold until 80%. Maybe cells optimization? I’m impressed.</figcaption></figure><p>Once everything works, you need to “productionize it”, which means setting up a Cron job (actually, <a href="https://www.launchd.info/">launchd</a>). I use. bash -lcto leverage PATH and other goodies from my .bashrcbut I hope you’re a better scripter and can make it work without that cumbersome import. Also make sure to add PATH correctly (I usually fail a few times before I get it right).</p><pre>$ crontab -e </pre><pre>[…]<br>PATH=/sbin:/bin:/usr/sbin:/usr/bin:~/git/sakura/bin/</pre><pre>3/5 * * * * bash -lc '/Users/ricc/path-to/sakura/bin/gcp-write-mac-battery-values-on-project your-project-id'<br>[…]</pre><h3>Step3: View metric and Create dashboard</h3><p>Let’s now head to the Metrics Explorer here and check a fake GCE metric:</p><ul><li>Go to <a href="https://console.cloud.google.com/monitoring/metrics-explorer?project=ric-cccwiki">https://console.cloud.google.com/monitoring/metrics-explorer</a></li><li>In “Select a metric” > Type “Battery” and see the options fall from many to two:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*DlxGuBX4SYzrmN8EMIa38Q.png" /><figcaption>Here are my two metrics, CamelCased too!</figcaption></figure><ul><li>Select <strong>BatteryLife</strong>. This should take you to a nice dashboard (possibly empty if you just created this — be patient). Use the time control to go back in time or zoom until you get the desired view.</li><li>Since this signal comes from (possibly) multiple Macs, select “group by” -> <strong>hostname</strong>. You could see something like this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yeP5TnvyAr-9uXYhOUvr4w.png" /><figcaption>See battery for last day. My Mac (3) at home is always plugged in, the one at work (42) goes to meeting rooms from time to time. To be honest i unplugged it twice just to get a nice screenshot — cheater!</figcaption></figure><ul><li>Now click “<strong>Save Chart</strong>” and enjoy.</li></ul><p>Bingo! You can have a dashboard where you see side by side both <strong>BatteryLife</strong> and <strong>BatteryHealth</strong>.</p><h4>Step4. Set alerting when battery is low</h4><p>Now let’s get an alert when the battery is below 14% (42 divided by π).</p><ul><li>Open <a href="https://console.cloud.google.com/monitoring/alerting?project=ric-cccwiki">https://console.cloud.google.com/monitoring/alerting</a></li><li>Click “<strong>+ Create Policy</strong>” (see <a href="https://gist.github.com/palladius/5c109015324fc6bffbfce2f58525760f">sample JSON output</a>)</li><li>“<strong>Select Metric</strong>” as above (type <em>BatteryLife</em>)</li><li><em>[optional] You may add a filter on the computer you care about: hostname = “my-favorite-mac”</em></li><li><em>Adjust TransformData parameters if you wish.</em></li><li>Click “<strong>Create Policy</strong>” -> Configure Alert trigger</li><li><strong>ConditionType</strong>: Threshold</li><li><strong>Position</strong>: Below threshold</li><li><strong>Threshold value</strong>: 14 (or value of your choice, like 20).</li><li>click <strong>Create Policy</strong></li><li>Finally, configure your <strong>Notification Channels</strong> (<a href="https://cloud.google.com/monitoring/support/notification-options">documentation</a>), where I’ve set up previously my email and swiss phone:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*GaEH0EttI6W24HeWAVLisw.png" /><figcaption>What life would be without emojis?</figcaption></figure><ul><li>[optional] You can add some <strong>Policy User Labels</strong>. I enjoy using labels at all time (eg env=prod, scope=personal, ..).</li><li>[optional] You can fill in the <strong>Documentation</strong> like a Playbook. I always try to write something meaningful as part of <strong>SRE</strong> methodology (“<strong><em>no alert is good if it’s not actionable”</em></strong>). The action here is to attach your Mac to a power source.</li><li>Finally review the values and click <strong>Review Alert</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fge8BQf73ReYJoUb5mdOMw.png" /></figure><h4>Conclusions</h4><p>In this brief article, we’ve seen how you can script a meaningful metric from your machine, and inject it to Cloud Monitoring from command line.</p><p>It’s very easy to slice and dice these values (in this case aggregate by hostname), then dashboard and alert on them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*clxCCRXccCBpxfET" /><figcaption>plug it to have battery or unplug it to see a nice graph?</figcaption></figure><p>The sky is just the limit now. You can do something silly like counting your Chrome Tabs and alert when they’re more than 42 with some silly messages like “<em>A message from the Galaxy: restart Chrome!</em>”</p><pre>brew install chrome-cli # only-once install<br>PROJECT_ID=my-project-123 gcp-write-metric mac-chrome-cli-ntabs $(chrome-cli list tabs | wc -l)</pre><p><em>Note: in the code I use “gce_instance” when I should be really using “global” metric (</em><a href="https://cloud.google.com/monitoring/api/resources"><em>docs</em></a><em>). I loved GCE Instance as it already has hostname and GCP zone baked in, but it’s incorrect (I tell GCP that’s a VM in the cloud, which is not). New code to support this is being developed in this amazing script:</em>🌸<em> </em><a href="https://github.com/palladius/sakura/blob/master/bin/gcp-write-metric-done-well">gcp-write-metric-done-well</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1ccd70485fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/my-macs-battery-on-google-cloud-monitoring-with-sms-if-its-low-a1ccd70485fe">My Mac’s battery on Google Cloud Monitoring — with SMS if its low</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>
Author
Link
Published date
Image url
Feed url
Guid
Hidden blurb
--- !ruby/object:Feedjira::Parser::RSSEntry title: My Mac’s battery on Google Cloud Monitoring — with SMS if its low url: https://medium.com/google-cloud/my-macs-battery-on-google-cloud-monitoring-with-sms-if-its-low-a1ccd70485fe?source=rss-b5293b96912f------2 author: Riccardo Carlesso categories: - google-cloud-platform - gcp-app-dev - alerts - monitoring - cloud-monitoring published: 2022-11-09 16:53:21.000000000 Z entry_id: !ruby/object:Feedjira::Parser::GloballyUniqueIdentifier is_perma_link: 'false' guid: https://medium.com/p/a1ccd70485fe carlessian_info: news_filer_version: 2 newspaper: Riccardo Carlesso - Medium macro_region: Blogs rss_fields: - title - url - author - categories - published - entry_id - content content: "<h3>My Mac’s battery\U0001F50B on Google Cloud Monitoring — send SMS if low \U0001FAAB</h3><blockquote><em>This article shows how you can easily inject a generic key/value into Google Cloud Monitoring and set up alerts on it. I use it to alert on disk space, and now also low battery!</em></blockquote><p>This morning I was in London, and I forgot my charger at home. With plenty of time but \U0001FAAB little battery, I thought: <em>hey! I need to have a way to predict when my battery is low! And I need to do it in a totally overkill way!</em></p><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*Yk6qFPAm6Y3Hwo5t\" /><figcaption>Catching an early train from St Pancras to Stratford Intl then London City Airport.</figcaption></figure><p>My battery was at <strong>42%</strong>, which seemed a subtle indication my idea was worth blogging. Googling around, I found <a href=\"https://www.iphonetricks.org/check-battery-health-on-mac-using-terminal/\">an article</a> which gave me the tip on how to script my Mac’s battery (note this only works for a <strong>Macbook</strong>).</p><p>Ugly code <a href=\"https://github.com/palladius/sakura/blob/master/bin/macbook-battery#L107-L150\">here</a> (hey! I’m in an airport with no charger, do you want Unit tests too?!?)</p><iframe src=\"\" width=\"0\" height=\"0\" frameborder=\"0\" scrolling=\"no\"><a href=\"https://medium.com/media/085df68699c21b7f54f45721065c2813/href\">https://medium.com/media/085df68699c21b7f54f45721065c2813/href</a></iframe><p>I know, I call the same command 10 times and I could cache it. This is for the next iteration!</p><p>The best part of this is, not only I get my battery life, it also gives me my battery durability — so when I need to change battery. Woohoo!</p><p>There you go, let’s try it out, let me just remove the cable so you dont get a boring 100%.</p><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*VVFX7-q7pyNbZaFayRGLmg.png\" /><figcaption>Battery level is 98%. Unfortunately 14% of my battery potential seems gone \U0001F622</figcaption></figure><p>Battery is 98%, yay! Unfortunately seems like ~14% of my battery is gone. Luckily I don’t pay for its repair :)</p><h4>Step 2: push this metric to the ☁ ️(GCP)</h4><p>Now, I want a script which emits my metric from CLI. So I can say something like push-to-gcp <METRIC_NAME> <METRIC_VALUE>.</p><p>I’ve coded my disk space a month ago, let me abstract it into some more reusable code (always Ruby): <a href=\"https://github.com/palladius/sakura/blob/master/bin/gcp-write-metric\">palladius/sakura/gcp-write-metric</a> .</p><iframe src=\"\" width=\"0\" height=\"0\" frameborder=\"0\" scrolling=\"no\"><a href=\"https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href\">https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href</a></iframe><p>Ok! Now let’s try it out.</p><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/852/1*fFPP3gWU1mMpCUXLAyeBrQ.png\" /><figcaption>Created the timeseries ‘<strong>prova</strong>’ (test in italian) with meaningful number <strong>123</strong>! Wow!</figcaption></figure><p>Note you need to specify the project_id via ENV var (coming soon, the — project option, or better the project_id auto inferral from gcloud config).</p><p>Let’s now glue the two scripts and upload the two Macbook info and see on the DevConsole:</p><iframe src=\"\" width=\"0\" height=\"0\" frameborder=\"0\" scrolling=\"no\"><a href=\"https://medium.com/media/49258a59c0117f1018504c211725d963/href\">https://medium.com/media/49258a59c0117f1018504c211725d963/href</a></iframe><p>This script requires a project_id in ARGV, then it does the work for you, knowing the fields which are useful from macbook-battery are coming from values 3 and 5 (yes, a JSON encoding/parsing would be less error prone!). Let’s call it:</p><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/925/1*CTX7IrQJgpI8qoFRDyA6Ug.png\" /><figcaption>Meanwhile I went home, and launched this on my other M1 Mac. Always, boringly, attached to the current. Destined to an infinite life between 99 and 100%. Wait — this Mac, although charged, is on hold until 80%. Maybe cells optimization? I’m impressed.</figcaption></figure><p>Once everything works, you need to “productionize it”, which means setting up a Cron job (actually, <a href=\"https://www.launchd.info/\">launchd</a>). I use. bash -lcto leverage PATH and other goodies from my .bashrcbut I hope you’re a better scripter and can make it work without that cumbersome import. Also make sure to add PATH correctly (I usually fail a few times before I get it right).</p><pre>$ crontab -e </pre><pre>[…]<br>PATH=/sbin:/bin:/usr/sbin:/usr/bin:~/git/sakura/bin/</pre><pre>3/5 * * * * bash -lc '/Users/ricc/path-to/sakura/bin/gcp-write-mac-battery-values-on-project your-project-id'<br>[…]</pre><h3>Step3: View metric and Create dashboard</h3><p>Let’s now head to the Metrics Explorer here and check a fake GCE metric:</p><ul><li>Go to <a href=\"https://console.cloud.google.com/monitoring/metrics-explorer?project=ric-cccwiki\">https://console.cloud.google.com/monitoring/metrics-explorer</a></li><li>In “Select a metric” > Type “Battery” and see the options fall from many to two:</li></ul><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/868/1*DlxGuBX4SYzrmN8EMIa38Q.png\" /><figcaption>Here are my two metrics, CamelCased too!</figcaption></figure><ul><li>Select <strong>BatteryLife</strong>. This should take you to a nice dashboard (possibly empty if you just created this — be patient). Use the time control to go back in time or zoom until you get the desired view.</li><li>Since this signal comes from (possibly) multiple Macs, select “group by” -> <strong>hostname</strong>. You could see something like this:</li></ul><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*yeP5TnvyAr-9uXYhOUvr4w.png\" /><figcaption>See battery for last day. My Mac (3) at home is always plugged in, the one at work (42) goes to meeting rooms from time to time. To be honest i unplugged it twice just to get a nice screenshot — cheater!</figcaption></figure><ul><li>Now click “<strong>Save Chart</strong>” and enjoy.</li></ul><p>Bingo! You can have a dashboard where you see side by side both <strong>BatteryLife</strong> and <strong>BatteryHealth</strong>.</p><h4>Step4. Set alerting when battery is low</h4><p>Now let’s get an alert when the battery is below 14% (42 divided by π).</p><ul><li>Open <a href=\"https://console.cloud.google.com/monitoring/alerting?project=ric-cccwiki\">https://console.cloud.google.com/monitoring/alerting</a></li><li>Click “<strong>+ Create Policy</strong>” (see <a href=\"https://gist.github.com/palladius/5c109015324fc6bffbfce2f58525760f\">sample JSON output</a>)</li><li>“<strong>Select Metric</strong>” as above (type <em>BatteryLife</em>)</li><li><em>[optional] You may add a filter on the computer you care about: hostname = “my-favorite-mac”</em></li><li><em>Adjust TransformData parameters if you wish.</em></li><li>Click “<strong>Create Policy</strong>” -> Configure Alert trigger</li><li><strong>ConditionType</strong>: Threshold</li><li><strong>Position</strong>: Below threshold</li><li><strong>Threshold value</strong>: 14 (or value of your choice, like 20).</li><li>click <strong>Create Policy</strong></li><li>Finally, configure your <strong>Notification Channels</strong> (<a href=\"https://cloud.google.com/monitoring/support/notification-options\">documentation</a>), where I’ve set up previously my email and swiss phone:</li></ul><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/308/1*GaEH0EttI6W24HeWAVLisw.png\" /><figcaption>What life would be without emojis?</figcaption></figure><ul><li>[optional] You can add some <strong>Policy User Labels</strong>. I enjoy using labels at all time (eg env=prod, scope=personal, ..).</li><li>[optional] You can fill in the <strong>Documentation</strong> like a Playbook. I always try to write something meaningful as part of <strong>SRE</strong> methodology (“<strong><em>no alert is good if it’s not actionable”</em></strong>). The action here is to attach your Mac to a power source.</li><li>Finally review the values and click <strong>Review Alert</strong>:</li></ul><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*Fge8BQf73ReYJoUb5mdOMw.png\" /></figure><h4>Conclusions</h4><p>In this brief article, we’ve seen how you can script a meaningful metric from your machine, and inject it to Cloud Monitoring from command line.</p><p>It’s very easy to slice and dice these values (in this case aggregate by hostname), then dashboard and alert on them.</p><figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*clxCCRXccCBpxfET\" /><figcaption>plug it to have battery or unplug it to see a nice graph?</figcaption></figure><p>The sky is just the limit now. You can do something silly like counting your Chrome Tabs and alert when they’re more than 42 with some silly messages like “<em>A message from the Galaxy: restart Chrome!</em>”</p><pre>brew install chrome-cli # only-once install<br>PROJECT_ID=my-project-123 gcp-write-metric mac-chrome-cli-ntabs $(chrome-cli list tabs | wc -l)</pre><p><em>Note: in the code I use “gce_instance” when I should be really using “global” metric (</em><a href=\"https://cloud.google.com/monitoring/api/resources\"><em>docs</em></a><em>). I loved GCE Instance as it already has hostname and GCP zone baked in, but it’s incorrect (I tell GCP that’s a VM in the cloud, which is not). New code to support this is being developed in this amazing script:</em>\U0001F338<em> </em><a href=\"https://github.com/palladius/sakura/blob/master/bin/gcp-write-metric-done-well\">gcp-write-metric-done-well</a></p><img src=\"https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1ccd70485fe\" width=\"1\" height=\"1\" alt=\"\"><hr><p><a href=\"https://medium.com/google-cloud/my-macs-battery-on-google-cloud-monitoring-with-sms-if-its-low-a1ccd70485fe\">My Mac’s battery on Google Cloud Monitoring — with SMS if its low</a> was originally published in <a href=\"https://medium.com/google-cloud\">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>"
Language
Active
Ricc internal notes
Imported via /Users/ricc/git/gemini-news-crawler/webapp/db/seeds.d/import-feedjira.rb on 2024-03-31 22:27:06 +0200. Content is EMPTY here. Entried: title,url,author,categories,published,entry_id,content. TODO add Newspaper: filename = /Users/ricc/git/gemini-news-crawler/webapp/db/seeds.d/../../../crawler/out/feedjira/Blogs/Riccardo Carlesso - Medium/2022-11-09-My_Mac’s_battery_on_Google_Cloud_Monitoring — with_SMS_if_its_lo-v2.yaml
Ricc source
Show this article
Back to articles