Monitoring Plugin Language Comparison

Which programming language should we use to write monitoring check_plugins? This question rose some discussion and this post is trying to give some hints.

This kind of a follow up post to this older Blogpost. The focus of this post was more on the monitoring core, this post will focus more on the plugin itself.

Currently there are plugins written in Bash, C, Go, Perl and Python that is why this post will focus on these languages. Due to its popularity Java has also been taken into account.

Setup

The following Virtual Box machine has been used as testsetup:

  • 2 Cores: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
  • SSD
  • Debian 9

The following compilers/interpreters has been used:

  • Bash: 4.4.12
  • gcc: 6.3.0
  • Go: 1.9
  • Java: 1.8.0_144
  • Perl: v5.24.1
  • Python 2.7.13

The programs are just simple Hello-World example, because this will show a baseline for the different types of tests. They are at the end of this post.

Tests

CPU time

The first test measures the CPU time, with the following command:

time for i in {1..1000}; do ./$PROGRAM_TO_TEST; done

CPU result

LanguageRealUserSys
Bash1,6640,00560,224
C0,9070,0320,224
Go1,7650,0520,216
Java67,20753,9928,956
Perl2,0030,0720,216
Python14,0628,9281,9

Memory

The second test measures the maximum memory(RSS - Resident set size) usage:

/usr/bin/time -v ./$PROGRAM_TO_TEST

memory result

LanguageRSS in KB
Bash2924
C1096
Go1468
Java23592
Perl4076
Python6840

Filesize

The last aspect is the filesize of the executable/script:

filesize result

LanguageFilesize in Bytes
Bash46
C8624
Go1225312
Java446
Perl55
Python105

Conclusion

If you want to write your Monitoring Plugin in Java you should maybe think about it twice. If it is just a simple Script which does not require libraries, a simple Bash script should be your choice. Python does also not look like a perfect choice, but it is very easy (most of the time) to accomplish your goal. Go generates the biggest binary files but it is very efficient and it has a nice design. C maybe the choice but you have to like it the hard way. “We all make choices, but in the end, our choices make us.” (Andrew Ryan, 2007)

Further information

Due to the fact these test cover only minimalistic programs, there are other sources which cover more complex programs. Like the following site which compares different languages with a mandelbrot problem. At this problem, the tested languages scored like following:

Bash: not tested
C: 1,65s
Go: 5,46s
Java: 7,10s
Perl: 12min!?
Python: 273,43s

Testfiles

Bash:

#!/bin/bash

echo "simple bash plugin"
exit 0

C:

#include <stdio.h>

int main(void) {
    printf("simple c plugin\n");
    return 0;
}

Go:

package main

import "fmt"
import "os"

func main() {
    fmt.Println("simple go plugin")
    os.Exit(0)
}

Java:

public class Java {
    public static void main(String[] args) {
        System.out.println("simple java plugin");
        System.exit(0);
    }
}

Perl:

#!/usr/bin/perl

print "simple perl plugin\n";
exit 0;

Python:

#!/usr/bin/env python
import sys

if __name__ == '__main__':
  print "simple python plugin"
  sys.exit(0)