♊️ GemiNews 🗞️ (dev)

Demo 1: Embeddings + Recommendation Demo 2: Bella RAGa Demo 3: NewRetriever Demo 4: Assistant function calling

🗞️My Mac’s battery on Google Cloud Monitoring — with SMS if its low

🗿Semantically Similar Articles (by :title_embedding)

My Mac’s battery on Google Cloud Monitoring — with SMS if its low

2022-11-09 - Riccardo Carlesso (from Riccardo Carlesso - Medium)

My Mac’s battery🔋 on Google Cloud Monitoring — send SMS if low 🪫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!This morning I was in London, and I forgot my charger at home. With plenty of time but 🪫 little battery, I thought: 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!Catching an early train from St Pancras to Stratford Intl then London City Airport.My battery was at 42%, which seemed a subtle indication my idea was worth blogging. Googling around, I found an article which gave me the tip on how to script my Mac’s battery (note this only works for a Macbook).Ugly code here (hey! I’m in an airport with no charger, do you want Unit tests too?!?)<a href="https://medium.com/media/085df68699c21b7f54f45721065c2813/href">https://medium.com/media/085df68699c21b7f54f45721065c2813/href</a>I know, I call the same command 10 times and I could cache it. This is for the next iteration!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!There you go, let’s try it out, let me just remove the cable so you dont get a boring 100%.Battery level is 98%. Unfortunately 14% of my battery potential seems gone 😢Battery is 98%, yay! Unfortunately seems like ~14% of my battery is gone. Luckily I don’t pay for its repair :)Step 2: push this metric to the ☁ ️(GCP)Now, I want a script which emits my metric from CLI. So I can say something like push-to-gcp <METRIC_NAME> <METRIC_VALUE>.I’ve coded my disk space a month ago, let me abstract it into some more reusable code (always Ruby): palladius/sakura/gcp-write-metric .<a href="https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href">https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href</a>Ok! Now let’s try it out.Created the timeseries ‘prova’ (test in italian) with meaningful number 123! Wow!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).Let’s now glue the two scripts and upload the two Macbook info and see on the DevConsole:<a href="https://medium.com/media/49258a59c0117f1018504c211725d963/href">https://medium.com/media/49258a59c0117f1018504c211725d963/href</a>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: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.Once everything works, you need to “productionize it”, which means setting up a Cron job (actually, launchd). 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).$ crontab -e […]PATH=/sbin:/bin:/usr/sbin:/usr/bin:~/git/sakura/bin/3/5 * * * * bash -lc '/Users/ricc/path-to/sakura/bin/gcp-write-mac-battery-values-on-project your-project-id'[…]Step3: View metric and Create dashboardLet’s now head to the Metrics Explorer here and check a fake GCE metric:Go to https://console.cloud.google.com/monitoring/metrics-explorerIn “Select a metric” > Type “Battery” and see the options fall from many to two:Here are my two metrics, CamelCased too!Select BatteryLife. 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.Since this signal comes from (possibly) multiple Macs, select “group by” -> hostname. You could see something like this: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!Now click “Save Chart” and enjoy.Bingo! You can have a dashboard where you see side by side both BatteryLife and BatteryHealth.Step4. Set alerting when battery is lowNow let’s get an alert when the battery is below 14% (42 divided by π).Open https://console.cloud.google.com/monitoring/alertingClick “+ Create Policy” (see sample JSON output)“Select Metric” as above (type BatteryLife)[optional] You may add a filter on the computer you care about: hostname = “my-favorite-mac”Adjust TransformData parameters if you wish.Click “Create Policy” -> Configure Alert triggerConditionType: ThresholdPosition: Below thresholdThreshold value: 14 (or value of your choice, like 20).click Create PolicyFinally, configure your Notification Channels (documentation), where I’ve set up previously my email and swiss phone:What life would be without emojis?[optional] You can add some Policy User Labels. I enjoy using labels at all time (eg env=prod, scope=personal, ..).[optional] You can fill in the Documentation like a Playbook. I always try to write something meaningful as part of SRE methodology (“no alert is good if it’s not actionable”). The action here is to attach your Mac to a power source.Finally review the values and click Review Alert:ConclusionsIn 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.It’s very easy to slice and dice these values (in this case aggregate by hostname), then dashboard and alert on them.plug it to have battery or unplug it to see a nice graph?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 “A message from the Galaxy: restart Chrome!”brew install chrome-cli # only-once installPROJECT_ID=my-project-123 gcp-write-metric mac-chrome-cli-ntabs $(chrome-cli list tabs | wc -l)Note: in the code I use “gce_instance” when I should be really using “global” metric (docs). 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:🌸 gcp-write-metric-done-wellMy Mac’s battery on Google Cloud Monitoring — with SMS if its low was originally published in Google Cloud - Community on Medium, where people are continuing the conversation by highlighting and responding to this story.

[Blogs] 🌎 https://medium.com/google-cloud/my-macs-battery-on-google-cloud-monitoring-with-sms-if-its-low-a1ccd70485fe?source=rss-b5293b96912f------2 [🧠] [v2] article_embedding_description: {:llm_project_id=>"Unavailable", :llm_dimensions=>nil, :article_size=>10489, :llm_embeddings_model_name=>"textembedding-gecko"}
[🧠] [v1/3] title_embedding_description: {:ricc_notes=>"[embed-v3] Fixed on 9oct24. Only seems incompatible at first glance with embed v1.", :llm_project_id=>"unavailable possibly not using Vertex", :llm_dimensions=>nil, :article_size=>10489, :poly_field=>"title", :llm_embeddings_model_name=>"textembedding-gecko"}
[🧠] [v1/3] summary_embedding_description:
[🧠] As per bug https://github.com/palladius/gemini-news-crawler/issues/4 we can state this article belongs to titile/summary version: v3 (very few articles updated on 9oct24)

🗿article.to_s

------------------------------
Title: My Mac’s battery on Google Cloud Monitoring — with SMS if its low
[content]
My Mac’s battery🔋 on Google Cloud Monitoring — send SMS if low 🪫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!This morning I was in London, and I forgot my charger at home. With plenty of time but 🪫 little battery, I thought: 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!Catching an early train from St Pancras to Stratford Intl then London City Airport.My battery was at 42%, which seemed a subtle indication my idea was worth blogging. Googling around, I found an article which gave me the tip on how to script my Mac’s battery (note this only works for a Macbook).Ugly code here (hey! I’m in an airport with no charger, do you want Unit tests too?!?)<a href="https://medium.com/media/085df68699c21b7f54f45721065c2813/href">https://medium.com/media/085df68699c21b7f54f45721065c2813/href</a>I know, I call the same command 10 times and I could cache it. This is for the next iteration!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!There you go, let’s try it out, let me just remove the cable so you dont get a boring 100%.Battery level is 98%. Unfortunately 14% of my battery potential seems gone 😢Battery is 98%, yay! Unfortunately seems like ~14% of my battery is gone. Luckily I don’t pay for its repair :)Step 2: push this metric to the ☁ ️(GCP)Now, I want a script which emits my metric from CLI. So I can say something like push-to-gcp <METRIC_NAME> <METRIC_VALUE>.I’ve coded my disk space a month ago, let me abstract it into some more reusable code (always Ruby): palladius/sakura/gcp-write-metric .<a href="https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href">https://medium.com/media/a73541e14f99aefb609f8ca056ccf574/href</a>Ok! Now let’s try it out.Created the timeseries ‘prova’ (test in italian) with meaningful number 123! Wow!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).Let’s now glue the two scripts and upload the two Macbook info and see on the DevConsole:<a href="https://medium.com/media/49258a59c0117f1018504c211725d963/href">https://medium.com/media/49258a59c0117f1018504c211725d963/href</a>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: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.Once everything works, you need to “productionize it”, which means setting up a Cron job (actually, launchd). 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).$ crontab -e […]PATH=/sbin:/bin:/usr/sbin:/usr/bin:~/git/sakura/bin/3/5 * * * * bash -lc '/Users/ricc/path-to/sakura/bin/gcp-write-mac-battery-values-on-project your-project-id'[…]Step3: View metric and Create dashboardLet’s now head to the Metrics Explorer here and check a fake GCE metric:Go to https://console.cloud.google.com/monitoring/metrics-explorerIn “Select a metric” > Type “Battery” and see the options fall from many to two:Here are my two metrics, CamelCased too!Select BatteryLife. 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.Since this signal comes from (possibly) multiple Macs, select “group by” -> hostname. You could see something like this: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!Now click “Save Chart” and enjoy.Bingo! You can have a dashboard where you see side by side both BatteryLife and BatteryHealth.Step4. Set alerting when battery is lowNow let’s get an alert when the battery is below 14% (42 divided by π).Open https://console.cloud.google.com/monitoring/alertingClick “+ Create Policy” (see sample JSON output)“Select Metric” as above (type BatteryLife)[optional] You may add a filter on the computer you care about: hostname = “my-favorite-mac”Adjust TransformData parameters if you wish.Click “Create Policy” -> Configure Alert triggerConditionType: ThresholdPosition: Below thresholdThreshold value: 14 (or value of your choice, like 20).click Create PolicyFinally, configure your Notification Channels (documentation), where I’ve set up previously my email and swiss phone:What life would be without emojis?[optional] You can add some Policy User Labels. I enjoy using labels at all time (eg env=prod, scope=personal, ..).[optional] You can fill in the Documentation like a Playbook. I always try to write something meaningful as part of SRE methodology (“no alert is good if it’s not actionable”). The action here is to attach your Mac to a power source.Finally review the values and click Review Alert:ConclusionsIn 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.It’s very easy to slice and dice these values (in this case aggregate by hostname), then dashboard and alert on them.plug it to have battery or unplug it to see a nice graph?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 “A message from the Galaxy: restart Chrome!”brew install chrome-cli # only-once installPROJECT_ID=my-project-123 gcp-write-metric mac-chrome-cli-ntabs $(chrome-cli list tabs | wc -l)Note: in the code I use “gce_instance” when I should be really using “global” metric (docs). 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:🌸 gcp-write-metric-done-wellMy Mac’s battery on Google Cloud Monitoring — with SMS if its low was originally published in Google Cloud - Community on Medium, where people are continuing the conversation by highlighting and responding to this story.
[/content]

Author: Riccardo Carlesso
PublishedDate: 2022-11-09
Category: Blogs
NewsPaper: Riccardo Carlesso - Medium
Tags: google-cloud-platform, gcp-app-dev, alerts, monitoring, cloud-monitoring
{"id"=>214,
"title"=>"My Mac’s battery on Google Cloud Monitoring — with SMS if its low",
"summary"=>nil,
"content"=>"

My Mac’s battery🔋 on Google Cloud Monitoring — send SMS if low 🪫

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!

This morning I was in London, and I forgot my charger at home. With plenty of time but 🪫 little battery, I thought: 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!

\"\"
Catching an early train from St Pancras to Stratford Intl then London City Airport.

My battery was at 42%, which seemed a subtle indication my idea was worth blogging. Googling around, I found an article which gave me the tip on how to script my Mac’s battery (note this only works for a Macbook).

Ugly code here (hey! I’m in an airport with no charger, do you want Unit tests too?!?)

I know, I call the same command 10 times and I could cache it. This is for the next iteration!

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!

There you go, let’s try it out, let me just remove the cable so you dont get a boring 100%.

\"\"
Battery level is 98%. Unfortunately 14% of my battery potential seems gone 😢

Battery is 98%, yay! Unfortunately seems like ~14% of my battery is gone. Luckily I don’t pay for its repair :)

Step 2: push this metric to the ☁ ️(GCP)

Now, I want a script which emits my metric from CLI. So I can say something like push-to-gcp <METRIC_NAME> <METRIC_VALUE>.

I’ve coded my disk space a month ago, let me abstract it into some more reusable code (always Ruby): palladius/sakura/gcp-write-metric .

Ok! Now let’s try it out.

\"\"
Created the timeseries ‘prova’ (test in italian) with meaningful number 123! Wow!

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).

Let’s now glue the two scripts and upload the two Macbook info and see on the DevConsole:

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:

\"\"
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.

Once everything works, you need to “productionize it”, which means setting up a Cron job (actually, launchd). 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).

$ crontab -e 
[…]
PATH=/sbin:/bin:/usr/sbin:/usr/bin:~/git/sakura/bin/
3/5 * * * * bash -lc '/Users/ricc/path-to/sakura/bin/gcp-write-mac-battery-values-on-project your-project-id'
[…]

Step3: View metric and Create dashboard

Let’s now head to the Metrics Explorer here and check a fake GCE metric:

\"\"
Here are my two metrics, CamelCased too!
  • Select BatteryLife. 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.
  • Since this signal comes from (possibly) multiple Macs, select “group by” -> hostname. You could see something like this:
\"\"
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!
  • Now click “Save Chart” and enjoy.

Bingo! You can have a dashboard where you see side by side both BatteryLife and BatteryHealth.

Step4. Set alerting when battery is low

Now let’s get an alert when the battery is below 14% (42 divided by π).

  • Open https://console.cloud.google.com/monitoring/alerting
  • Click “+ Create Policy” (see sample JSON output)
  • Select Metric” as above (type BatteryLife)
  • [optional] You may add a filter on the computer you care about: hostname = “my-favorite-mac”
  • Adjust TransformData parameters if you wish.
  • Click “Create Policy” -> Configure Alert trigger
  • ConditionType: Threshold
  • Position: Below threshold
  • Threshold value: 14 (or value of your choice, like 20).
  • click Create Policy
  • Finally, configure your Notification Channels (documentation), where I’ve set up previously my email and swiss phone:
\"\"
What life would be without emojis?
  • [optional] You can add some Policy User Labels. I enjoy using labels at all time (eg env=prod, scope=personal, ..).
  • [optional] You can fill in the Documentation like a Playbook. I always try to write something meaningful as part of SRE methodology (“no alert is good if it’s not actionable”). The action here is to attach your Mac to a power source.
  • Finally review the values and click Review Alert:
\"\"

Conclusions

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.

It’s very easy to slice and dice these values (in this case aggregate by hostname), then dashboard and alert on them.

\"\"
plug it to have battery or unplug it to see a nice graph?

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 “A message from the Galaxy: restart Chrome!

brew install chrome-cli # only-once install
PROJECT_ID=my-project-123 gcp-write-metric mac-chrome-cli-ntabs $(chrome-cli list tabs | wc -l)

Note: in the code I use “gce_instance” when I should be really using “global” metric (docs). 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:🌸 gcp-write-metric-done-well

\"\"

My Mac’s battery on Google Cloud Monitoring — with SMS if its low was originally published in Google Cloud - Community on Medium, where people are continuing the conversation by highlighting and responding to this story.

",
"author"=>"Riccardo Carlesso",
"link"=>"https://medium.com/google-cloud/my-macs-battery-on-google-cloud-monitoring-with-sms-if-its-low-a1ccd70485fe?source=rss-b5293b96912f------2",
"published_date"=>Wed, 09 Nov 2022 16:53:21.000000000 UTC +00:00,
"image_url"=>nil,
"feed_url"=>"https://medium.com/google-cloud/my-macs-battery-on-google-cloud-monitoring-with-sms-if-its-low-a1ccd70485fe?source=rss-b5293b96912f------2",
"language"=>nil,
"active"=>true,
"ricc_source"=>"feedjira::v1",
"created_at"=>Sun, 31 Mar 2024 20:27:07.402094000 UTC +00:00,
"updated_at"=>Mon, 21 Oct 2024 15:34:21.426502000 UTC +00:00,
"newspaper"=>"Riccardo Carlesso - Medium",
"macro_region"=>"Blogs"}
Edit this article
Back to articles