Google Cloud Pub/Sub is the backbone of many modern distributed systems, handling millions of messages daily. But here’s the problem: how do you monitor something you can’t see?
Most organizations struggle with:
What if I told you there’s a way to get comprehensive Pub/Sub monitoring integrated directly into your existing AppDynamics dashboard with minimal setup?
In this guide, we’ll build a complete monitoring solution that:
✅ Automatically creates GCP Pub/Sub topics and subscriptions
✅ Generates realistic test data for immediate monitoring
✅ Collects 50+ metrics covering every aspect of your Pub/Sub infrastructure
✅ Integrates seamlessly with AppDynamics Machine Agent
✅ Supports multiple platforms (AWS, GCP, Azure, on-premises)
✅ Includes cleanup scripts for easy environment management
Here’s what we’re building:
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ GCP Pub/Sub │ │ Metrics Script │ │ AppDynamics │
│ │ │ │ │ │
│ ┌─────────────┐ │ │ ┌──────────────┐ │ │ ┌─────────────┐ │
│ │ Topics │◄┼────┼─│ gcloud │ │ │ │ Machine │ │
│ └─────────────┘ │ │ │ CLI │ │ │ │ Agent │ │
│ │ │ └──────────────┘ │ │ └─────────────┘ │
│ ┌─────────────┐ │ │ ┌──────────────┐ │ │ │ │
│ │Subscriptions│◄┼────┼─│ Metrics │─┼────┼────────┘ │
│ └─────────────┘ │ │ │ Collector │ │ │ │
│ │ │ └──────────────┘ │ │ ┌─────────────┐ │
│ ┌─────────────┐ │ │ ┌──────────────┐ │ │ │ Controller │ │
│ │ Metrics │◄┼────┼─│ JSON │ │ │ │ Dashboard │ │
│ └─────────────┘ │ │ │ Auth │ │ │ └─────────────┘ │
└─────────────────┘ │ └──────────────┘ │ └─────────────────┘
└──────────────────┘
Before we start, ensure you have:
Don’t worry if you’re missing some pieces — we’ll guide you through everything!
First, let’s get our toolkit:
git clone https://github.com/Abhimanyu9988/gcp-pubsub-appdynamics.git
cd gcp-pubsub-appdynamics
chmod +x *.sh
Our smart installer detects your operating system and installs everything needed:
bash
sudo ./ec2-pre-req.sh
What this does:
Sample output:
==============================================
Multi-Distribution GCP Pub/Sub Prerequisites
==============================================
[INFO] Detected OS: Amazon Linux 2
[SUCCESS] System packages updated
[SUCCESS] Python 3.9 installed
[SUCCESS] ✅ Google Cloud SDK installed successfully
[SUCCESS] 🎉 All prerequisites installed successfully!
On your local machine where you have gcloud configured:
bash
./create_service_account.sh
What this creates:
Sample output:
bash
============================================
GCP Service Account Creation for Pub/Sub Monitoring
============================================
[SUCCESS] Using project: my-gcp-project
[SUCCESS] Created service account: pubsub-monitor@my-project.iam.gserviceaccount.com
[SUCCESS] ✅ Assigned: roles/pubsub.viewer
[SUCCESS] ✅ Service account key created: pubsub-monitor-service-account.json
📦 Transfer to AWS Linux 2:
scp -i your-key.pem pubsub-monitor-service-account.json ec2-user@your-instance-ip:~/
Copy the service account key to your monitoring server:
bash
# On your local machine
scp -i your-aws-key.pem pubsub-monitor-service-account.json ec2-user@your-server:~/
# On your monitoring server
sudo mkdir -p /opt/appdynamics
sudo mv ~/pubsub-monitor-service-account.json /opt/appdynamics/
sudo chmod 600 /opt/appdynamics/pubsub-monitor-service-account.json
bash
export GCP_PROJECT_ID="your-actual-project-id"
bash
./pubsub_create.sh
What this does:
Sample output:
bash
==================================
GCP Pub/Sub Creation Script
==================================
[SUCCESS] Created topic: appdynamics-monitoring-topic
[SUCCESS] Created subscription: appdynamics-monitoring-subscription
[INFO] Publishing 100 messages to appdynamics-monitoring-topic
[SUCCESS] Publishing completed:
Total messages: 100
Published successfully: 100
Failed to publish: 0
Messages per second: 23
bash
./pubsub_info.sh status
This shows you exactly what was created and provides troubleshooting information.
Update the configuration in script.sh:
bash
vi script.sh
# Update these values:
PROJECT_ID="your-actual-project-id"
SERVICE_ACCOUNT_KEY_FILE="/opt/appdynamics/pubsub-monitor-service-account.json"
# Optional: Add more topics/subscriptions
TOPIC_NAMES="topic1,topic2,topic3"
SUBSCRIPTION_NAMES="sub1,sub2,sub3"
bash
./script.sh
Expected output (50+ metrics):
bash
name=Custom Metrics|PubSub|Health|Collection Success, value=1
name=Custom Metrics|PubSub|Topic|appdynamics-monitoring-topic|Status, value=1
name=Custom Metrics|PubSub|Subscription|appdynamics-monitoring-subscription|Ack Deadline, value=60
name=Custom Metrics|PubSub|API|PubSub Enabled, value=1
name=Custom Metrics|PubSub|Project|Total Topics, value=5
bash
# Create extension directory
sudo mkdir -p /opt/appdynamics/machine-agent/monitors/PubSubMonitor
# Copy files
sudo cp script.sh /opt/appdynamics/machine-agent/monitors/PubSubMonitor/
sudo cp monitor.xml /opt/appdynamics/machine-agent/monitors/PubSubMonitor/
# Set permissions
sudo chown -R appdynamics:appdynamics /opt/appdynamics/machine-agent/monitors/PubSubMonitor
sudo chmod +x /opt/appdynamics/machine-agent/monitors/PubSubMonitor/script.sh
bash
sudo systemctl restart appdynamics-machine-agent
# Verify it's running
sudo systemctl status appdynamics-machine-agent
bash
# Check Machine Agent logs
tail -f /opt/appdynamics/machine-agent/logs/machine-agent.log
# Check for our extension
grep -i pubsub /opt/appdynamics/machine-agent/logs/machine-agent.log
Our solution collects 50+ comprehensive metrics across these categories:
Create custom dashboards with widgets for:
Health Overview:
Topic Performance:
Subscription Analytics:
Project Insights:
bash
# Secure service account keys
sudo chmod 600 /opt/appdynamics/*.json
sudo chown appdynamics:appdynamics /opt/appdynamics/*.json
# Enable audit logging
gcloud logging sinks create pubsub-monitoring-sink \
bigquery.googleapis.com/projects/YOUR_PROJECT/datasets/audit_logs \
--log-filter='protoPayload.serviceName="pubsub.googleapis.com"'
bash
# Development environment
export GCP_PROJECT_ID="dev-project"
export TOPIC_NAMES="dev-orders,dev-inventory"
# Production environment
export GCP_PROJECT_ID="prod-project"
export TOPIC_NAMES="orders,inventory,notifications,analytics"
Create AppDynamics policies for:
bash
# Check current resources
./pubsub_info.sh status
# View available metrics
./pubsub_info.sh metrics
# Generate more test data
RUN_SIMULATION=true ./pubsub_create.sh
# Clean up everything
./pubsub_destroy.sh
bash
# Create new service account
./create_service_account.sh
# Test with new credentials
./script.sh
# Delete old service account
./delete_service_account.sh
Common Issues & Solutions:
Authentication Errors:
bash
# Verify service account file
jq empty /opt/appdynamics/pubsub-monitor-service-account.json
# Test authentication
gcloud auth activate-service-account --key-file=/opt/appdynamics/pubsub-monitor-service-account.json
Permission Denied:
bash
# Check IAM roles
gcloud projects get-iam-policy YOUR_PROJECT_ID \
--flatten="bindings[].members" \
--filter="bindings.members:your-service-account@project.iam.gserviceaccount.com"
No Metrics in AppDynamics:
bash
# Test script manually
cd /opt/appdynamics/machine-agent/monitors/PubSubMonitor
./script.sh
# Check Machine Agent logs
tail -f /opt/appdynamics/machine-agent/logs/machine-agent.log
Monitor Pub/Sub across multiple GCP projects by deploying separate instances with different service accounts:
bash
# Project 1 - Development
PROJECT_ID="dev-project" SERVICE_ACCOUNT_KEY_FILE="/opt/appdynamics/dev-sa.json" ./script.sh
# Project 2 - Production
PROJECT_ID="prod-project" SERVICE_ACCOUNT_KEY_FILE="/opt/appdynamics/prod-sa.json" ./script.sh
Extend the solution to include your application-specific metrics:
bash
# Add custom metrics to /tmp/pubsub_custom_metrics.log
echo "[$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")] CUSTOM_METRIC order_processing_rate 150" >> /tmp/pubsub_custom_metrics.log
Include in your deployment pipelines:
yaml
# GitHub Actions example
- name: Setup Pub/Sub Monitoring
run: |
./pubsub_create.sh
./script.sh
# Verify metrics collection
if grep -q "Collection Success, value=1" <(./script.sh); then
echo "✅ Monitoring setup successful"
else
echo "❌ Monitoring setup failed"
exit 1
fi
Our solution is designed for production scale:
Performance Metrics:
You now have a production-ready Pub/Sub monitoring solution that provides:
✅ Complete Visibility - 50+ metrics covering every aspect
✅ Automated Setup - One-click deployment and configuration
✅ Integration Ready - Native AppDynamics dashboard integration
✅ Production Tested - Handles real-world scale and complexity
✅ Maintenance Friendly - Easy updates, rotation, and cleanup
Monitoring GCP Pub/Sub doesn't have to be complicated. With the right automation and tooling, you can have comprehensive visibility into your messaging infrastructure in under 30 minutes.
The solution we've built together provides enterprise-grade monitoring with minimal operational overhead. Your teams can now:
Have questions or want to share your success story? Drop a comment below or reach out on GitHub!
⭐ If this guide helped you, please give the GitHub repository a star and share it with your team!