Dedunu

  • Technology
  • Travel
  • Basic Prometheus Exporter with Python Standard Library

    I wanted to use a Raspberry Pi and some sensors to create a Grafana dashboard for monitoring air quality. I didn’t like the idea of using any library to keep everything simple, and I wanted to learn how Prometheus works.

    Prometheus will look for <hostname>/metrics to collect metrics, and it has to be in the format below.

    one_sensor 0.5
    second_sensor 100

    It should respond with a 200 status code too. I wrote a second exporter without a 200 status code and it failed. You can use the code below to make it work.

    from http.server import BaseHTTPRequestHandler, HTTPServer
    
    
    class BaseHandler(BaseHTTPRequestHandler):
        def _set_response(self):
            self.send_response(200)
            self.send_header("Content-type", "text/plain")
            self.end_headers()
    
        def do_GET(self):
            self._set_response()
            result = "first_metric 1\n"
            result = result + "second_metric 2\n"
            output = process(result.stdout.strip())
            self.wfile.write(output.encode("utf-8"))
    
    
    def run(server_class=HTTPServer, handler_class=BaseHandler, port=9123):
    
        server_address = ("0.0.0.0", port)
        httpd = server_class(server_address, handler_class)
    
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            pass
    
        httpd.server_close()
    
    
    if __name__ == "__main__":
        from sys import argv
    
        if len(argv) == 2:
            run(port=int(argv[1]))
        else:
            run()
    

    If you want to install it as a service, you can use this file.

    [Unit]
    Description=Prometheus
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=user1
    Group=user1
    Type=simple
    Restart=on-failure
    RestartSec=5s
    ExecStart=/usr/bin/python3 /home/user1/app.py
    
    [Install]
    WantedBy=multi-user.target
    
  • Lego for Adults

    A desktop computer case with a geometric design, positioned on a wooden desk next to a monitor.

    I was using the HP EliteDesk 800 G2 65W for testing. The only issue was the memory, which has just two expansion slots. I upgraded from 8GB to 16GB, but the SSD had limited space for upgrades and no NVMe slots.

    I need a modern computer with WiFi, Bluetooth, USB-C, two HDMI or Display ports, two NVMe drives, enough memory for Virtual Machines, and low power consumption.

    Which brings me to the next question, what to buy. After a couple of weeks of research I decided to pick the

    • AMD Ryzen 7 8700G
    • Gigabyte B650M D3HP AX
    • Corsair VENGEANCE DDR5 (4 x 32GB) DDR5 5200MHz 
    • MSI SPATIUM M470 PRO 2TB M.2 SSD
    • WD Black SN770 1TB M.2 SSD
    • Cooler Master Elite V4 400W PSU
    • Cooler Master Hyper 411 Nano
    • Cooler Master MasterBox Q300L
    • Arctic Case Fan Hub
    • Arctic P12 Silent x 4
    • Thermal Grizzly Kryonaut 1g 
    Interior view of a computer case showcasing the motherboard, CPU cooler, RAM modules, and power supply with visible wiring.

    After assembling everything, it wouldn’t start. I had to upgrade the BIOS to version F36b, which took a while during the first boot. I tried several operating systems, including CachyOS, Omachy, Redhat, and Ubuntu, but decided to stick with Ubuntu because all the drivers worked immediately, including Wi-Fi and Bluetooth. I don’t like dealing with drivers for Linux, so I’m happy that Ubuntu handled everything automatically.

    CachyOS was nice, but there were issues with GNOME and VirtualBox. I didn’t want to troubleshoot the host operating system, so I chose Ubuntu instead.

  • Disable KVM for VirtualBox on Ubuntu

    I recently installed Ubuntu and got an error that the kvm and kvm-amd modules are blocking VirtualBox from running VMs.

    Failed to open a session for the virtual machine xp efendi.
    AMD-V is being used by another hypervisor. (VERR_SVM_IN_USE).
    VirtualBox can't enable the AMD-V extension. Please disable the KVM kernel extension, recompile your kernel and reboot (VERR_SVM_IN_USE).

    Just remove these modules to quickly fix the problem.

    sudo rmmod kvm_amd
    sudo rmmod kvm
    

    A restart will load the modules again. To make it permanent, create the file /etc/modprobe.d/blacklist-kvm.conf and change its content as shown below.

    blacklist kvm-amd
    blacklist kvm
    

    Links:

    https://help.ubuntu.com/community/Loadable_Modules

  • Rethinking Index Investing

    “I do think that index investing, if everyone did it won’t work. But for another considerable period, index investing is going to work better than active stock picking when you try and know a lot. ” – Charlie Munger

    Exchange-traded funds (ETFs) have become a go-to investment for many retail investors, with financial advisors frequently recommending them as a reliable, long-term strategy. The prevailing wisdom is to buy a low-cost ETF and hold it for years—a view even Warren Buffett endorses. This advice is everywhere, from YouTube to financial blogs. I once owned VOO, Vanguard’s S&P 500 ETF, but currently, I don’t hold any ETFs in my brokerage accounts, though I may include an index fund in my retirement plan.

    Recently, the Financial Times reported that, according to Morningstar and Bloomberg, there are now more ETFs than individual stocks. This explosion includes leveraged ETFs, which are widely regarded as risky and unsuitable for most investors. Terry Smith has highlighted the dangers of these products, especially the complexities of shorting them. There are also ETFs that invest in illiquid assets, introducing hidden risks that can catch investors off guard.

    Another concern is the growing concentration within major indices. The “Magnificent Seven” tech stocks now account for over 30% of the S&P 500. This means that, despite holding hundreds of stocks, index investors are heavily exposed to just a handful of companies. Such concentration undermines the idea of true diversification and can lead to what’s been dubbed “diworsification.”

    If retail investors were to sell off ETFs en masse, it could spark a market event reminiscent of Black Monday in 1987. The top five S&P 500 ETFs now manage over $2 trillion, while the S&P 500’s total market cap exceeds $50 trillion-a ratio that keeps climbing. A sudden wave of ETF selling could strain market liquidity, raising questions about whether the system could handle such pressure.

    Index ETFs are also forced to buy and sell based on index changes, not investment merit. When Tesla joined the S&P 500, for example, all related ETFs had to buy Tesla shares—sometimes at inflated prices—while selling other holdings to rebalance. This mechanical buying and selling can amplify market swings, as ETFs must purchase more of the stocks that are already rising in prominence, fueling momentum rather than providing true diversification.

    I recently watched a Howard Markets video on index investing. One of his main points was that index ETFs are built on the belief that active investing is ineffective. Passive investing aims to deliver the market’s average return, minus fees. But it’s crucial to remember that ETF prices are ultimately set by active market participants—hedge funds, institutions, and sometimes large groups of retail traders.

    So, is it still wise to “index”?

    References:

    • https://www.ft.com/content/0907462a-363b-46bf-94d9-59249f16106a
    • https://en.macromicro.me/charts/123469/us-magnificent-seven-total-market-cap-and-share-of-sp-500
    • https://www.investopedia.com/terms/d/diworsification.asp
    • https://www.investopedia.com/ask/answers/042115/what-caused-black-monday-stock-market-crash-1987.asp
  • Proton Mail

    Email is an old technology that was invented long ago. Many of my colleagues don’t like emails, and I understand why. They aren’t great for people with short attention spans, but they serve well as a modern replacement for letters and are useful for keeping records.

    I check emails daily. I am keeping a clean inbox. I delete emails that are not useful and move emails to their own folder if no work/response is needed. I keep the emails that needs attention in my inbox and make sure it is addressed.

    I have tried several email providers like iCloud, SendGrid, Postmark, SquareSpace, and Gmail. I chose to move to Proton Mail because many providers lack security features. Sometimes, I had to run a Python script to send an email, but everything else was great. However, none of these solutions fully met my needs.

    I had problems with iCloud because I couldn’t manage all the email addresses linked to iCloud accounts. Having a few iCloud accounts with my domain caused issues. Gmail was a costly option, but it meets all my needs except for the price.

    Proton Mail meets my needs with folders and labels, though I only use folders. I need a catch-all email address, and buying for two years is cheaper.

  • AWS Free Tier Revamp: Get $200 Credits Now

    I was surprised to learn that AWS revamped its free tier. Now you can create a free account, and it won’t charge anything from you other than a verification payment.

    It comes with 100 USD credits. If you do five tasks, you will get 100 USD more, 20 USD each.

    Five activities are:

    • Create an AWS EC2 instance
    • Create an AWS RDS instance
    • Create a Lambda function
    • Set a budget
    • Create a bedrock playground

  • Easily Convert Jekyll Posts to WordPress using wp-cli

    I have a business WordPress.com subscription. My previous travel blog was on Jekyll, and the posts only contained pictures. It would take a lot of time for me to import them manually. I didn’t want to import them via the RSS method either. I wrote this Python script to convert my posts.

    Script: https://gist.github.com/dedunumax/6facdd0258c3d939b3f64a2bd698fd3e

    Jekyll Repository: https://github.com/dedunu/travel

    You can run the script this way.

    python3 generate_wp_cli.py travel/_posts/ > cmd.bash
    

    Sample command would look like this.

    wp post create --post_author=Jackson --post_date='2025-07-05 00:00:00' --post_content='<!-- wp:image {"className":"wp-block-image size-large"} --><figure class="wp-block-image size-large"><img src="https://cdn.dedunu.info/travel/images/2025-07-05-05-july-2025-2.jpeg" alt=""/></figure><!-- /wp:image -->' --comment_status='closed' --post_title='05 July 2025' --post_category='travel' --tags_input='amsterdam,palace' --post_status='publish'
    

    I tried to create readable commands with multiple lines. But it didn’t work. I am really happy with wp-cli; it is really versatile. To run this you will have to enable SFTP/SSH on your website.

    scp cmd.bash website_name.wordpress.com@ssh.wp.com:
    

    You will find your cmd.bash on htdocs folder. Run below commands to run all the wp-cli commands against your site.

    cd htdocs
    bash cmd.bash
    
  • Why Frequent Travelers Choose Amex Platinum

    American Express Platinum card is a great proposition. It offers a lot of benefits to frequent travelers such as travel insurance, lounge access, dinner for two, reward points, and much more. It only makes sense if you travel a lot. Lounge access allows you to take a plus one, which is pretty rare. I am seeing more and more people using Amex Platinum cards. The Platinum card can change consumer behavior significantly, especially with their hotel offers and upgrades.

    Perks vary from country to country. But they are more or less similar. Amex is getting attention, and every other credit card issuer is trying to match or offer something similar. JPM and Citi both are revamping or introducing new cards. This sounds a bit more like streaming wars to me. We are going to see a credit card war soon.

  • Sri Lanka’s Tourism Growth: Balancing Numbers and Earnings

    We are getting more and more tourists every quarter, which is a positive indication for the economy. There is no question about that. After the financial crisis, Sri Lanka is turning around and it looks attractive for tourists to pick Sri Lanka as a destination. I simply calculate earnings per tourist, it was 1,854 USD in 2017; it grew to 1,877 USD in 2018. This steady growth indicates that tourists were not just arriving in larger numbers but were also willing to spend more during their visits. You can see that tourist earning growth was slightly higher than the tourist arrival growth.

    Line graph comparing arrivals and earnings growth for the years 2017 and 2018, displaying monthly trends from January to December.

    Fast forward to 2024, the situation has changed significantly. Every month, tourist arrival growth surpasses earnings growth. We are getting more tourists who spend less, indicating a shift in the demographics of our visitors. Earnings per tourist were 1,567 USD in 2024 for the first five-month period, reflecting a potentially thriving tourism sector; yet, it dropped to 1,498 USD in 2025 for the same period, signaling a worrying decline. We are receiving more people who burden the infrastructure, create more waste, and cause congestion in popular areas, leading to a diminished experience for both tourists and locals. The potential for earnings is decreasing, creating a paradox where increased tourist numbers do not equate to greater economic benefits. Are we going to be a Costco country or an LVMH country? Our policymakers should decide which model is the most suitable for us.

    Line graph comparing arrivals and earnings growth for the years 2024 and 2025, with blue representing arrivals and red representing earnings, plotted over the months from January to May.

    Personally, I favor the LVMH model. It will be easy to handle the amount of tourists and hit our revenue targets. It will strengthen the country’s image as well as sustainability. On the other hand, the Costco model might get us more revenue with a lot of stress on the current system. The locals are already pushing back in some areas. I think the former model is suitable and will keep everyone happy.

    I welcome the government’s move to grant visa-free entry to 40 countries. We have to make it easier for our visitors. It is always better to reduce the red tape. Sri Lanka is well known for doing the opposite.

    Sri Lankan authorities are not doing enough to market the country’s allure. Turkey, Azerbaijan, Georgia, and many Middle Eastern countries usually have very good campaigns. We should look at them and learn. If possible, we should mimic and stand out at the same time.

    Most of the hotels listed on the Colombo Stock Exchange have high levels of debt. Introducing more taxes and burdens will certainly drive away tourists and investments. Our banking system already owns a lot of debt related to tourism. It will pose a risk to the health of the economy, and it is crucial to keep the tourism sector healthy and help it recover. We are not out of the woods yet.

    Data: https://cdn.dedunu.info/tech/29.pdf

  • Mozart and Rembrandt: The Cost of Artistic Genius

    A historical painting depicting a group of armed men, many wearing hats and formal attire, standing in a dimly lit space, with a central figure gesturing while holding a sword, surrounded by soldiers and townspeople.

    It is hard to figure out Mozart’s financial health. Most sources show that he often borrowed money. Some sources show that he was gambling too. According to Mozart in Context, even though he earned enough money, he had expenses to match them.

    “There once was a man who became the most famous composer in the world but was utterly miserable most of the time, and one of the reasons was because he always overspent his income. That was Mozart. If Mozart can’t get by with this kind of asinine conduct, I don’t think you should try” – Charles Thomas Munger

    The problem with Mozart was he had no social safety net or health insurance. His income was unpredictable. He had to borrow years’ worth of expenses at a time. It appears that his financial management was poor, and he struggled to make ends meet.

    I visited Rembrandt’s house recently, and Rembrandt had the same problem: he overspent his income. All the artists had foreign objects like seashells and armor as reference. Most artists opened it up for other people and earned money, but Rembrandt never commercialized it. Rembrandt himself was buying and selling art and had a gallery. He sold other people’s paintings.

    Even though he had financial difficulties, he kept buying exotic objects for his collection. He had many legal battles. He finally declared bankruptcy. It is crucial to be prudent, and Mozart and Rembrandt clearly teach us that.

    Sources:

    • The financial affairs of Wolfgang Amadeus Mozart
    • Mozart in Context: Chapter 20 – Mozart and Finances
    • Wolfgang Amadeus Mozart`s financial struggles and strategies
    • Rembrandt made a mess of his legal and financial life

1 2 3 … 17
Next Page→
 

Loading Comments...