如何在Prometheus目标页面批量点击所有展开/收起按钮并将解决方案保存为浏览器书签
Absolutely, you can automate this with a bookmarklet—a tiny piece of JavaScript stored as a browser bookmark that runs when you click it. Here's how to set it up:
Step 1: Create the Bookmarklet Code
Use this JavaScript snippet, which targets all the "show more" / "show less" buttons on the Prometheus targets page and simulates a click on each one:
javascript:(function(){ // Find all target toggle buttons matching the class you provided const toggleButtons = document.querySelectorAll('button.targets.btn.btn-primary.expanded-table'); // Click each button to toggle its expanded/collapsed state toggleButtons.forEach(button => button.click()); })();
If you prefer a compact single-line version (functionally identical):
javascript:(function(){document.querySelectorAll('button.targets.btn.btn-primary.expanded-table').forEach(b=>b.click());})();
Step 2: Add It to Your Browser Bookmarks
- Open your browser's bookmark manager (e.g., Chrome:
Ctrl+Shift+O, Firefox:Ctrl+Shift+B). - Create a new bookmark (look for "New Bookmark" or "Add Page" option).
- Name it something clear like "Toggle All Prometheus Targets".
- Paste the full bookmarklet code into the URL field of the bookmark.
- Save the bookmark.
Step 3: Use It
- Navigate to your Prometheus targets page (typically
http://<your-prometheus-instance>/targets). - Click the bookmark you just created. All "show more" buttons will expand their target lists, and all "show less" buttons will collapse them—all in one go!
Quick Notes
- This script toggles every button regardless of its current state: if some targets are expanded and others collapsed, clicking the bookmark will flip all of them to the opposite state.
- If Prometheus ever updates its UI class names, you’ll just need to adjust the selector in the script to match the new button classes—but based on the element code you shared, this will work perfectly for your current setup.
内容的提问来源于stack exchange,提问作者waldauf
相关产品推荐
相关产品推荐

