Monday, April 24, 2017

North Korea: China or The USA's Opportunity?

Overview

North Korea's sabre-rattling tactics by launching missiles and conducting nuclear tests may be seen as an internal affair to boost confidence in Kim Jong-Un's regime, but with its neighbours being alarmed, and attracting the attention of the USA, the hermit kingdom is no longer insulated from world affairs. China, the emerging superpower, will be hard-pressed to act, while the USA, the current superpower, is also pondering on military action should things continue to escalate. Many see this geopolitical event as a problem. But this represent an opportunity for both sides.

Historical Background

The Korean peninsula has always been a buffer zone between its bigger neighbours; China to the west, Japan to the east, and Russia to the north. Chinese, Korean and Japanese cultures all share similarities, yet all have distinctives that separate them. In the early 20th century, China was so weakened by foreign intervention that Japan saw an opportunity to expand its territories westward. First, by annexing the Korean peninsula in 1910. Then, in 1931, Japan invaded and occupied Manchuria. China proper was then invaded in 1937.

The Chinese mainland territories captured by Japan were still controlled by them until 1945. After Europe was liberated by the Allies in May 1945, focus was shifted to Japan. USSR then agreed to enter the war against Japan. The Soviet Union invaded Japanese-occupied Manchuria in August 1945. At about the same time, the Americans dropped the atomic bombs on Hiroshima and Nagasaki. Japan then surrendered unconditionally.

The United Nations then developed plans for a trusteeship administration. The Soviet Union administered the peninsula north of the 38th parallel, while the United States administered the south. This resulted in the 1948 establishment of two separate governments, North Korea and South Korea. Both governments were molded in the image of their administrators.

In 1949, the Communist Party took control of China. The Soviet Union then welcomed China into its sphere of influence. Along with North Korea, the Soviets then have a buffer zone against the USA.

From this, after the Second World War, China needed to re-establish the Korean peninsula as a buffer zone against future invasions from the east. Even as the Japanese threat was eliminated by their defeat and surrender at the hands of the Allies, a new adversary suddenly emerged: The United States of America. Remember that the whole Korean peninsula was controlled by China. A southern Western-like state so close to the mainland gave the Chinese leaders restless nights.

When the Korean War broke out, China took a back seat at first, thinking that the North Korean Army, armed with Soviet weapons and trained by the Soviet army could do the job in unifying Korea. When the United Nations army was very close to capturing the entire peninsula, the Chinese Army suddenly mobilised and in a twist of events too long to discuss here, managed to get away with a ceasefire and retained the division of North & South Korea along the 38th parallel.

At that time, China's intervention was justified in the Communist world, having saved their smaller comrade from the jaws of defeat. A Korean peninsula half-controlled by another Communist regime is surely better than the entire peninsula controlled by the opposite camp. Chinese casualties were high but the fallen were celebrated as heroes for the great communist cause.

The Present Situation

North Korea's unbridled nuclear tests, along with missile launches from land and sea, is unnerving even for China, its greatest supporter. It is one thing to have this 'puppet' state occupy Western minds and shake the Japanese, but another if the provocations cause a military reaction to 'bring peace' to the region. It will be another Korean War, this time not of the communists' choosing. China now is not as dogmatic as China in the 1950s. This however does not eliminate the fact that she still needs a buffer zone.

Economics is a strong factor when going to war. The Japanese went all-out in the Second World War to capture resource-rich territories that they see as essential for their nation's benefit. Then, it was painful to have a lack of resources. Now, it is painful to expend resources in war. Both China and the US are seen as capable to intervene militarily, since both have similar interest to control the East Pacific regions.

Scenario A: The US Attacks, China Idles

As the incumbent superpower in the region, the US is still the protector for South Korea and Japan. A strike from North Korea to the 2 countries will surely pressure the US to respond. As the North Koreans have boasted on national TV that they are capable of challenging the US, the Trump administration can use this opportunity to eliminate this threat by military intervention.

A defeated North Korean regime can be a positive outcome, with which South Korea have the responsibility to rebuild its northern sibling. The US, through South Korea, can also offer assistance and this will spark demand for infrastructure and construction. The US can send a signal to the rest of the world of its status as a superpower & not to be messed with. It may also result in China being viewed as to have forsaken its neighbour for economic expediency, since ideology no longer is a strong factor in national decisions.

It will be a sign of weakness to the rest of the East Pacific nations, as China did not act to the threat so near its mainland, the likelihood of them really challenging Vietnam, the Philippines, Taiwan etc. over control of the nine-dash line (South China Sea region). This will boost the smaller nations' will to continue challenging China's claims of sovereignty.

Scenario B: The US Attacks, China Defends

This will surely spark internal outrage in China. Why send troops to defend North Korea in this time of economic uncertainty and at the cost of Chinese lifes just to maintain the Kim regime? It may boost the confidence of regional allies and 'neutral' nations, but internal backlash is something China could not afford.

If the outcome of the war is another stalemate, it will provoke further outrage as it will be compared to the first Korean War. This time, there's no strong ideological reason to justify shedding Chinese blood on foreign soil. Mao Zedong was the king in the party then, but Xi Jinping is no supreme commander now, though he is the leader.

Scenario C: The US Idles, China Attacks

This sounds preposterous, but in actual fact, is a possibility as history has shown. A region of instability will invite trouble from other nations that sees this as a 'low-hanging fruit'. That was how Japan annexed Korea in 1910. A weak China precipitated this. As the Kim regime is universally despised by the world, and internally-pressured to remain adored by its own people, a sudden invasion will give Kim Jong Un a heart attack and time to respond will be longer.

Militarily, this gives China the opportunity to gain experience by participating in combat within the same region. It can be a rehearsal for the invasion of Taiwan, though this requires dominance at sea. The Chinese army seen as liberating North Korea from the hegemony of the Kim regime will be a better morale-booster than defending the Kim regime.

China, emerging as the victor, will be able to strike a deal with South Korea in rebuilding the North. This will increase demand in the construction and infrastructure sector. This is surely a better way to use resources and manpower rather than building ghost cities in 'no man's land'. As happened in Germany, where the Western side had to pay for the Eastern side's debts and rebuilding costs, so will South Korea do the same for their Northern sibling.

This will be an eye-opener for South Korea as the US is no longer integral in its security and may look to China taking over the role. Perhaps there isn't a need for any nation to offer 'protection' if the Koreans view China as benevolent. But this may shake up Japan as China still has not forgotten World War II.

Scenario D: The US & China Attacks

This requires military coordination between both nations, which is a weak area since both nations regard each other with great suspicion, each trying to subvert rather than cooperate. A land invasion from China and an aerial assault by the US can be possible, as along as both militaries do not interfere with each other. Limited cooperation and coordination is still possible, as in the 2-side front in Europe against Nazi Germany by the Allies.

Conclusion

No doubt the US and China are challenging each other for influence in East Asia. In the Cold War era, choosing sides was easier, what more choosing a victor in World War II. China's emergence as a regional superpower is changing the status quo. Then, nations going to war with each other are not tightly coupled together economically/financially. When this coupling is severed, as happened between Japan and the US in the 1940s, war followed. Both the US and China are too interdependent with each other, but both also do not want to be seen as weak and losing ground. This complicates matters and given the circumstances, both nations will want to avoid going to war with each other.

If war is unavoidable, then Scenario C will favour China in the aftermath. China is one of the "Kings of the East". No power can take it lightly, even North Korea. I quipped to my South Korean friends of my next visit to "Korea" will be in Pyongyang. Perhaps this year will be the right year.

Tuesday, April 18, 2017

GoAccess: Visualize Your Web Traffic

If you want a visual representation of your web traffic, try GoAccess (https://goaccess.io/). You will never let it go.

I am just generating a report using static log files. GoAccess has many other features (real-time updates, console access, JSON/CSV-exporting etc.) that I haven't got the need to use (for now).

Tools Used:

- Mac OS 10.12
- GoAccess v1.2


Installation

brew install goaccess

Configuration

Retrieving logs from the web servers (Apache 2.4-based), sample output:
10.230.33.71 - - [26/Mar/2017:02:41:09 +0800] "GET /retail/mce/img/icons/icon-close.png HTTP/1.1" 200 196 314
10.230.33.71 - - [26/Mar/2017:02:36:26 +0800] "GET /retail/mce/img/icons/icon-close.png HTTP/1.1" 304 - 314
10.230.33.71 - - [25/Mar/2017:22:47:19 +0800] "GET /retail/mce/css/icons.data.svg.css HTTP/1.1" 304 - 314
10.230.33.71 - - [25/Mar/2017:17:46:35 +0800] "GET /retail/mce/css/icons.fallback.css HTTP/1.1" 304 - 314

Tip #1: To remove 'noise' if your web server is shared by multiple apps, use 'grep' to filter patterns that you are interested:
grep -i 'mypattern' access_log-20170328 > filtered_access_log-20170328

Tip #2: Although GoAccess has the ability to get input from multiple files, you can also combine all your log files via 'cat':
cat a.log b.log c.log > d.log

Log format settings from httpd.conf:
LogFormat "%h %l %u %t \"%r\" %>s %b %D" common

Note: The assumption was to take the Apache log format verbatim, since GoAccess supports the Apache log file format. After much trial and error, the log format for GoAccess is as below. The most frustrating issue was the response times getting rendered as 0.00us due to the inclusion of ">" in %>s. GoAccess only recognises %s.

Open file: /usr/local/Cellar/goaccess/1.2/etc/goaccess.conf, and set the following (adjust based on your own log patterns):
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %l %u [%d:%t %^] "%m %U %H" %s %b %D

Save the file after editing, and run the following (assuming log filename is access_log):
goaccess access_log -o report.html -q

where
-o: Report file. For HTML report, specify a filename with *.html extension
-q: Ignore query string i.e., www.google.com/page.htm?query => www.google.com/page.htm

My output/report:



The man page (https://goaccess.io/man) has the full options available.

Side note: Why not AWStats (http://www.awstats.org/)? It was my 1st choice, but I was working on a Macbook, and the easiest route was GoAccess (just use brew to install). AWStats needed Perl and only had ready RPMs at its website's download page. Plus, GoAccess has a more impressive UI dashboard, and I needed to show some fancy stats to biz...