Author: Stephen Ndegwa

  • How to install and configure Prometheus SNMP Exporter


    1. Download & Install SNMP Exporter

    1. Grab the latest release from the official GitHub repo ([Grafana Labs][1])
    2. Unpack and install:
      “`bash
      wget https://github.com/prometheus/snmp_exporter/releases/download//snmp_exporter-.linux-amd64.tar.gz
      tar xzf snmp_exporter-*.tar.gz
      sudo mv snmp_exporter-.linux-amd64 /opt/snmp_exporter-
      sudo ln -s /opt/snmp_exporter- /opt/snmp_exporter
    1. Make the binary executable and optionally add /opt/snmp_exporter to your PATH (nsrc.org, sbcode.net)

    2. Generate & Configure snmp.yml

    • Use the default snmp.yml (built around if_mib) for basic interface metrics.
    • For device-specific metrics, customize or generate a config using snmp_exporter’s generator tool to include CPU, memory, temperature, etc. (GitHub)
    • Place your MIB files (e.g. from vendors like Cisco) into a directory (e.g. /usr/share/snmp/mibs) and reference them if crafting custom modules (groups.google.com)

    3. Install Supporting Tools (Linux)

    Ensure SNMP tools and dependencies are installed:

    • On Ubuntu/Debian:
    sudo apt update
    sudo apt install gcc make net-snmp net-snmp-utils
    
    • On RHEL/CentOS:
    sudo yum install gcc make net-snmp net-snmp-utils net-snmp-libs
    

    This includes tools like snmpwalk, snmpget you can use to validate target devices before deploying the exporter (youtube.com, nsrc.org)


    4. Run the Exporter

    From the installation directory:

    cd /opt/snmp_exporter
    ./snmp_exporter --config.file=snmp.yml
    

    By default, it listens on port 9116 at /metrics, exposing its own internal metrics (prometheus.io)


    5. Configure Prometheus to Scrape SNMP

    Edit your prometheus.yml to add:

    scrape_configs:
      - job_name: 'snmp'
        static_configs:
          - targets:
              - "192.0.2.5" # your device IP
        metrics_path: /snmp
        params:
          module: [if_mib] # matches one module in snmp.yml
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: instance
          - target_label: __address__
            replacement: 127.0.0.1:9116 # exporter address
    

    This enables Prometheus to send SNMP requests via the exporter to the target device (artifacthub.io, dbi-services.com)


    6. Test SNMP Access

    Before relying on the exporter, verify SNMP connectivity with standard tools:

    snmpwalk -v2c -c public 192.0.2.5
    

    or for SNMPv3:

    snmpget -v3 -u <user> -l authPriv -a MD5 -A <authpass> -x DES -X <privpass> 192.0.2.5 .1.3.6.1.2.1.1.3.0
    

    7. Validate & Verify

    • After starting Prometheus, visit http://<prometheus-host>:9090/targets to check the snmp job status.
    • If DOWN, confirm exporter is running and reachable.
    • Use curl http://localhost:9116/metrics to check exporter health.
    • Use curl 'http://localhost:9116/snmp?module=if_mib&target=192.0.2.5' to test probe metrics manually.

    8. Advanced Tips & Best Practices

    • Before deploying custom MIB modules, test modules with the SNMP generator to ensure correct mapping of OIDs to metrics (docs-bigbang.dso.mil, GitHub)
    • Allocate unique ports when running multiple exporters on a host; the SNMP exporter defaults to 9116 (prometheus.io)
    • Protect any HTTP endpoint access (including /snmp or SNMP community/credentials) using network and monitoring security best practices (prometheus.io)
    • To avoid exposing sensitive SNMP strings in config, consider external secret files or tools that support secret hiding (discuss.prometheus.io)

    ✅ TL;DR

    StepTask
    1Download & unpack exporter binary
    2Generate & customize snmp.yml with needed MIBs/modules
    3Install SNMP tools (net-snmp, etc.)
    4Launch exporter: ./snmp_exporter --config.file=snmp.yml
    5Add snmp scrape config to prometheus.yml
    6Validate via snmpwalk & Prometheus UI

    Example Ubuntu Workflow

    sudo apt update
    sudo apt install wget net-snmp net-snmp-utils gcc make
    wget https://github.com/prometheus/snmp_exporter/releases/download/0.20.0/snmp_exporter-0.20.0.linux-amd64.tar.gz
    tar xzf snmp_exporter-*.tar.gz
    sudo mv snmp_exporter-0.20.0.linux-amd64 /opt/snmp_exporter-0.20.0
    sudo ln -s /opt/snmp_exporter-0.20.0 /opt/snmp_exporter
    cd /opt/snmp_exporter
    ./snmp_exporter --config.file=snmp.yml &
    

    Then configure Prometheus as shown above and restart it. After launch, check /targets and /metrics.


  • How to Install Git

    Installing Git is straightforward, and the process varies slightly depending on your operating system. Here’s how to install Git on **Windows**, **macOS**, and **Linux**:

    ### **1. Install Git on Windows**
    #### **Option 1: Install Git via Official Installer**
    1. **Download Git** from the official website:
    → [https://git-scm.com/download/win](https://git-scm.com/download/win)
    2. **Run the installer** (`Git-x.x.x-64-bit.exe`).
    3. Follow the setup wizard (default options are fine for most users).
    4. **Verify installation** by opening **Command Prompt** (`cmd`) and running:
    “`sh
    git –version
    “`

    #### **Option 2: Install Git via Winget (Windows Package Manager)**
    Run in **PowerShell** or **Command Prompt**:
    “`sh
    winget install –id Git.Git -e –source winget
    “`

    ### **2. Install Git on macOS**
    #### **Option 1: Install Git via Homebrew (Recommended)**
    1. Open **Terminal**.
    2. Install **Homebrew** (if not already installed):
    “`sh
    /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
    “`
    3. Install Git:
    “`sh
    brew install git
    “`
    4. Verify:
    “`sh
    git –version
    “`

    #### **Option 2: Install Git via Xcode Command Line Tools**
    Run in **Terminal**:
    “`sh
    xcode-select –install
    “`
    This will install Git along with other developer tools.

    ### **3. Install Git on Linux**
    #### **Debian/Ubuntu (apt)**
    “`sh
    sudo apt update && sudo apt install git -y
    “`

    #### **Fedora (dnf)**
    “`sh
    sudo dnf install git -y
    “`

    #### **Arch Linux (pacman)**
    “`sh
    sudo pacman -S git
    “`

    #### **Verify Installation**
    “`sh
    git –version
    “`

    ### **Post-Installation Setup (Recommended)**
    After installing Git, configure your username and email (required for commits):
    “`sh
    git config –global user.name “Your Name”
    git config –global user.email “[email protected]
    “`
    Check your settings:
    “`sh
    git config –list
    “`

    ### **Next Steps**
    – Learn basic Git commands (`git clone`, `git add`, `git commit`, `git push`).
    – Use a GUI tool like **GitHub Desktop**, **Sourcetree**, or **VS Code Git integration**.

    Let me know if you need help with any step! 🚀

  • How to Install Git

    Installing Git is straightforward, and the process varies slightly depending on your operating system. Here’s how to install Git on **Windows**, **macOS**, and **Linux**:\n\n—\n\n### **1. Install Git on Windows**\n#### **Option 1: Install Git via Official Installer**\n1. **Download Git** from the official website: \n → [https://git-scm.com/download/win](https://git-scm.com/download/win)\n2. **Run the installer** (`Git-x.x.x-64-bit.exe`).\n3. Follow the setup wizard (default options are fine for most users).\n4. **Verify installation** by opening **Command Prompt** (`cmd`) and running:\n “`sh\n git –version\n “`\n\n#### **Option 2: Install Git via Winget (Windows Package Manager)**\nRun in **PowerShell** or **Command Prompt**:\n“`sh\nwinget install –id Git.Git -e –source winget\n“`\n\n—\n\n### **2. Install Git on macOS**\n#### **Option 1: Install Git via Homebrew (Recommended)**\n1. Open **Terminal**.\n2. Install **Homebrew** (if not already installed):\n “`sh\n /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”\n “`\n3. Install Git:\n “`sh\n brew install git\n “`\n4. Verify:\n “`sh\n git –version\n “`\n\n#### **Option 2: Install Git via Xcode Command Line Tools**\nRun in **Terminal**:\n“`sh\nxcode-select –install\n“`\nThis will install Git along with other developer tools.\n\n—\n\n### **3. Install Git on Linux**\n#### **Debian/Ubuntu (apt)**\n“`sh\nsudo apt update && sudo apt install git -y\n“`\n\n#### **Fedora (dnf)**\n“`sh\nsudo dnf install git -y\n“`\n\n#### **Arch Linux (pacman)**\n“`sh\nsudo pacman -S git\n“`\n\n#### **Verify Installation**\n“`sh\ngit –version\n“`\n\n—\n\n### **Post-Installation Setup (Recommended)**\nAfter installing Git, configure your username and email (required for commits):\n“`sh\ngit config –global user.name “Your Name”\ngit config –global user.email “[email protected]”\n“`\nCheck your settings:\n“`sh\ngit config –list\n“`\n\n—\n\n### **Next Steps**\n- Learn basic Git commands (`git clone`, `git add`, `git commit`, `git push`).\n- Use a GUI tool like **GitHub Desktop**, **Sourcetree**, or **VS Code Git integration**.\n\nLet me know if you need help with any step! 🚀

  • How to Query WordPress Posts with WPGraphQL and cURL

    If you’ve ever wanted to pull WordPress content into an app, static site, or dashboard without dealing with the REST API, WPGraphQL is a powerful plugin that exposes your WordPress data as a GraphQL endpoint. In this guide, we’ll focus on how to query posts directly — including getting a single post or a list of the latest posts — using curl from the command line.


    1. Install WPGraphQL

    In your WordPress dashboard:

    1. Go to Plugins → Add New
    2. Search for “WPGraphQL”
    3. Install and activate the plugin

    This will create a new endpoint:

    https://yourdomain.com/graphql
    

    2. Get the Latest Posts with cURL

    Run the following command, replacing the domain with your own:

    curl -X POST https://yourdomain.com/graphql \
      -H "Content-Type: application/json" \
      -d '{
        "query": "{ posts(first: 5) { nodes { id title excerpt date uri } } }"
      }'
    

    What this does:

    • Sends a POST request to the /graphql endpoint
    • Requests the first 5 posts, returning id, title, excerpt, date, and uri

    3. Get a Single Post by Slug with cURL

    If you know the slug of your post (for example, hello-world), you can fetch it directly:

    curl -X POST https://yourdomain.com/graphql \
      -H "Content-Type: application/json" \
      -d '{
        "query": "query GetPostBySlug($slug: ID!) { post(id: $slug, idType: SLUG) { id title content date uri } }",
        "variables": { "slug": "hello-world" }
      }'
    

    Key points:

    • post query fetches a single post instead of an array
    • idType: SLUG tells GraphQL to interpret the ID as a post slug
    • The variables object passes the slug value dynamically

    4. Common Field Options

    WPGraphQL lets you fetch more than just titles and content. Some useful fields include:

    • author { node { name } } → Get the author’s name
    • featuredImage { node { sourceUrl } } → Get the post’s featured image URL
    • categories { nodes { name slug } } → Get category data

    Example:

    {
      post(id: "hello-world", idType: SLUG) {
        title
        author { node { name } }
        featuredImage { node { sourceUrl } }
        categories { nodes { name slug } }
      }
    }
    

    5. Why Use WPGraphQL Over REST API?

    • Flexible: You choose exactly which fields you want — no over-fetching
    • Single request: Get all related data in one query
    • Structured: Responses are predictable and match your query shape

    Conclusion

    With WPGraphQL, you can turn your WordPress site into a modern, headless CMS that’s easy to integrate into apps and frontends. Using curl is a quick way to test queries before integrating them into your codebase. Once you’ve mastered the basics, you can use advanced GraphQL features like fragments, filtering, and pagination to tailor your data fetching even further.

  • How to Install WordPress on Ubuntu + Apache


    How to Install WordPress on Ubuntu + Apache Without Breaking Existing Sites

    If you’re running multiple sites on a single Ubuntu server with Apache, you’ve probably run into the issue where a new site loads the wrong content — like your WHMCS showing up when you try to access your WordPress subdomain.

    In this tutorial, we’ll go step-by-step through a proper WordPress installation on Ubuntu + Apache, ensuring each site is isolated, secure, and working on both HTTP and HTTPS from the start.


    1. Prerequisites

    Before we begin, make sure you have:

    • Ubuntu server with Apache installed
    • MySQL or MariaDB installed
    • PHP 7.4+ with required extensions: sudo apt install php php-mysql php-xml php-curl php-mbstring php-zip unzip
    • SSH access as a sudo user
    • DNS record pointing your domain/subdomain (e.g. tutorials.example.com) to your server IP

    2. Create the Apache VirtualHost

    We’ll create a dedicated vhost file so Apache knows exactly where to send requests.

    sudo nano /etc/apache2/sites-available/tutorials.example.com.conf
    

    Add:

    <VirtualHost *:80>
        ServerName tutorials.example.com
        DocumentRoot /var/www/tutorials
    
        <Directory /var/www/tutorials>
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/tutorials_error.log
        CustomLog ${APACHE_LOG_DIR}/tutorials_access.log combined
    </VirtualHost>
    

    Enable the site & reload Apache:

    sudo mkdir -p /var/www/tutorials
    sudo chown -R www-data:www-data /var/www/tutorials
    sudo chmod -R 755 /var/www/tutorials
    
    sudo a2ensite tutorials.example.com.conf
    sudo a2enmod rewrite
    sudo systemctl reload apache2
    

    Lesson learned:
    If you skip this and reuse your default vhost, Apache may serve the wrong DocumentRoot (like WHMCS).


    3. Create a Separate MySQL Database & User

    Using unique credentials prevents cross-access between applications.

    sudo mysql -u root -p
    

    Inside MySQL:

    CREATE DATABASE tutorials_wp;
    CREATE USER 'wp_user_tutorials'@'localhost' IDENTIFIED BY 'StrongP@ssw0rd!';
    GRANT ALL PRIVILEGES ON tutorials_wp.* TO 'wp_user_tutorials'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    

    Lesson learned:
    Never reuse WHMCS’s database or user for WordPress.


    4. Download & Configure WordPress

    cd /tmp
    wget https://wordpress.org/latest.tar.gz
    tar -xvzf latest.tar.gz
    sudo mv wordpress/* /var/www/tutorials/
    sudo chown -R www-data:www-data /var/www/tutorials
    sudo chmod -R 755 /var/www/tutorials
    

    5. Configure wp-config.php

    cd /var/www/tutorials
    cp wp-config-sample.php wp-config.php
    nano wp-config.php
    

    Update with your credentials:

    define( 'DB_NAME', 'tutorials_wp' );
    define( 'DB_USER', 'wp_user_tutorials' );
    define( 'DB_PASSWORD', 'StrongP@ssw0rd!' );
    define( 'DB_HOST', 'localhost' );
    $table_prefix = 'wpx9_'; // Random, secure prefix
    

    Lesson learned:
    Change the table prefix during installation to avoid predictable defaults.


    6. Set Up HTTPS (Avoid the Wrong SSL Problem)

    If you skip creating an SSL vhost, HTTPS requests may default to another site’s SSL config (like WHMCS).
    We’ll use Certbot to handle it automatically:

    sudo apt install certbot python3-certbot-apache
    sudo certbot --apache -d tutorials.example.com
    

    Lesson learned:
    Always create an SSL vhost for the new site immediately after enabling HTTP.


    7. Complete the WordPress Installation

    Visit:

    https://tutorials.example.com
    
    • Choose language
    • Set site title, admin username, password (unique from WHMCS)
    • Log in and start building

    8. Secure and Maintain

    • Install a firewall: sudo ufw allow 'Apache Full'
    • Keep packages updated: sudo apt update && sudo apt upgrade -y
    • Install a security plugin like Wordfence.

    Final Thoughts

    By giving WordPress its own VirtualHost, DocumentRoot, database, user, table prefix, and SSL config, you completely avoid the common pitfalls we faced when tutorials.lineserve.net kept loading WHMCS.

    This setup ensures both sites run independently, securely, and without conflicts — no matter how many other apps you host on the same server.