Monitoring your Mac with Prometheus

Monitoring your Mac with Prometheus

A few weeks ago I was exploring SquaredUp Cloud which is an dashboarding and visibility platform that lets you connect to data from many different tools and sources. In order to have some familiar data to work with I set up the Prometheus node exporter and Prometheus on my Macbook.

What is Prometheus?

Prometheus is an open source metrics collection and storage platform. It's used extensively around the world, especially (in my experience) for monitoring Kubernetes platforms.

The Prometheus node exporter is a program which collects operating system level metrics such as CPU usage and exposes them via a standard /metrics endpoint. Prometheus can then "scrape" the data from this endpoint and store it.

Installing and running the Node Exporter

I wanted to install and run Prometheus and the node exporter via the terminal (because I'm still learning my way around my Macbook and wanted to learn how). You could just as easily do most, if not all of what I have explained below via the UI.

You can find the download link for the Mac version of the node exporter on the Prometheus downloads page. The Mac version of the exporter is labelled "darwin" as the OS. Once you have the download URL you can download it from a terminal using the command (replace the URL with the current version/version you want to install):

curl -O 'https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.darwin-amd64.tar.gz' -L        

Then to unzip the archive:


gunzip -c node_exporter-1.4.0.darwin-amd64.tar.gz| tar xopf -        

And to run it:


cd node_exporter-1.4.0.darwin-amd6
./node_exporter        

You can check that it's running by opening a browser at https://127.0.0.1:9100/metrics

No alt text provided for this image

Installing and configuring Prometheus

You can find the download link for Prometheus at the same page linked above. You can also use the same approach via the terminal to download and unzip it:


curl -O 'https://github.com/prometheus/prometheus/releases/download/v2.40.1/prometheus-2.40.1.darwin-amd64.tar.gz' -L
gunzip -c prometheus-2.40.1.darwin-amd64.tar.gz| tar xopf -        

Before you run Prometheus you need to add your node exporter endpoint as a "scrape config". What this means is that you tell Prometheus about a /metrics endpoint you want it to collect from, and it will "scrape" all the metrics there on a regular basis.

Open up prometheus.yml in your IDE or code editor of choice and add the following entry under scrape_configs:


  - job_name: "node_your_mac"
    static_configs:
      - targets: ["localhost:9100"]"        

Once you've made the change and saved the file you can run Prometheus:


./prometheus        

Checking the scrape is working

Once Prometheus is running you can view the Prometheus UI from https://127.0.0.1:9090. If you go to Status > Targets you should see your node exporter endpoint there:

No alt text provided for this image

You can double check the data is there by running a query, for example, the following shows you the average % CPU usage on your Mac each minute:


100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[1m])) * 100)        

You should see data coming back:

No alt text provided for this image

Summary

In the real world I don't think many/any people use Prometheus to monitor their laptops, but the same principles apply at bigger scale. There are node exporters for Linux and Windows hosts and Kubernetes nodes. What's great about the node exporter is that it gives you a consistent way to query node/host level metrics regardless of the specific operating system being monitored.

Prometheus can do a lot more than this, and I'm looking forward to sharing more about how to leverage it next year.

Sudermoni L

Cloud & Devops | Python | Golang | K8S | K3S | CKA | CI/CD | Automation | Prometheus/Grafana | Linux | Bash | Infra

1 年

Very good article. Made my testing very simple.

Mark C.

Principal, Director of Design Technology @ HOK | Applied AI, Innovative Application Development & Strategies, High-performance Team Builder, Large Project Management

1 年

One major issue with this .. node_exporter won't report stats on sys memory when running on Mac. Surprised I have not seen more on this - has been reported on GitHub under Issues by a user but the response was "it makes more sense to ask on the prometheus-users mailing list" which isn't very helpful. Don't get me wrong, you can obtain tons of other useful information, but mem committed, etc. is a critical piece of info (arguably more than CPU for some workloads) to have at your disposal.

  • 该图片无替代文字
Richard Bown

DevOps and Platform Engineer | Writing stories about the humans that make software

2 年

Great intro. Definitely going to be trying this out soon!

Scott Moore ?

Software Engineering, Tech Media Content. DevPerfOps, Performance engineering, Observability, Testing, AI. Consulting, Education, and Entertainment.

2 年

Very timely my friend. ??. I was literally just starting on a project for the SMC Journal about monitoring performance of MacOS multiple ways and this just saved me a lot of work. Keep publishing articles so I can take a vacation ??

Bogdan Iachimciuc

Expert in Performance Testing & QA | Infrastructure Builder | Teacher & Mentor

2 年

Monitoring your Mac with Prometheus is a great way to keep track of the performance and health of your device. By using Prometheus, you can set up alerts and notifications to alert you of any issues that may arise, such as high CPU usage or low disk space. Additionally, Prometheus provides a rich set of metrics that can be used to gain insights into the overall performance of your Mac, such as CPU and memory usage, network traffic, and more. Overall, monitoring your Mac with Prometheus can help you proactively identify and troubleshoot issues, ensuring that your device is running smoothly and efficiently.

要查看或添加评论,请登录

Stephen Townshend的更多文章

  • Running your first Kubernetes workload in AWS with EKS

    Running your first Kubernetes workload in AWS with EKS

    I have been using Kubernetes for about a year and a half, but through all of that time I've only ever deployed…

  • Containerising a Node.js app

    Containerising a Node.js app

    As a Developer Advocate, I need to keep my technical skills up to date and to practice what I preach. One way I'm doing…

  • A Year as an SRE

    A Year as an SRE

    A bit over a year ago I transitioned from performance engineering into the world of Site Reliability Engineering (SRE).…

    7 条评论
  • The HTTP Protocol (explained)

    The HTTP Protocol (explained)

    What's this all about? A few years ago, I started writing a book about performance engineering. I only finished a rough…

    6 条评论
  • Running Grafana & Prometheus on Docker

    Running Grafana & Prometheus on Docker

    We're in the process of standing up a monitoring platform on Kubernetes. Before we started this process I had very…

    11 条评论
  • Is cloud computing killing performance testing?

    Is cloud computing killing performance testing?

    I 've received a few messages recently from individuals concerned that performance testing is "on the decline". The…

    17 条评论
  • Wrapping up 13 years of performance engineering

    Wrapping up 13 years of performance engineering

    Thirteen years ago, I fired off my CV to a few dozen organisations looking for my first job in IT. Months later, after…

    9 条评论
  • Performance Engineer to SRE?

    Performance Engineer to SRE?

    Two months ago I transitioned from a performance engineer to a site reliability engineer (SRE). It's been terrifying at…

    21 条评论
  • Before you automate your performance testing…

    Before you automate your performance testing…

    This year I’ve been working in a large program of work. My role is to oversee the performance testing and engineering…

    14 条评论
  • What I will miss about Visual Studio Load Test

    What I will miss about Visual Studio Load Test

    With Microsoft's announcement that they will be discontinuing Visual Studio's load test features after Visual Studio…

    10 条评论

社区洞察

其他会员也浏览了