Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

How can I add newrelic.labels in the php-newrelic installation through Dockerfile?

docker
php
dockerfiles

#1

I’m doing the New Relic installation through the Dockerfile and I need to add labels. Among those labels I want to add 3 (sandbox, qa and prod), the owner of the service for each environment and the Datacenter

This is the code that I already added in my Dockerfile (of course I already set the URL, Key and app name), but I’m missing the labels:

RUN \
  curl -L your_url | tar -C /tmp -zx && \
   export NR_INSTALL_USE_CP_NOT_LN=1 && \
    export NR_INSTALL_SILENT=1 && \
     /tmp/newrelic-php5-*/newrelic-install install && \
      rm -rf /tmp/newrelic-php5-* /tmp/nrinstall* && \
       sed -i -e 's/"REPLACE_WITH_REAL_KEY"/"Your_License_Key"/' \
     -e 's/newrelic.appname = "PHP Application"/newrelic.appname = "Your_Application_Name"/' \
         /usr/local/etc/php/conf.d/newrelic.ini

I expect these labels (and one for sandbox too):


#2

The newrelic.labels setting is blank by default so you could just append it to the end of the newrelic.ini:

echo "newrelic.labels = \"Environment:QA;Owner:Me;Datacenter:US-West-2\"" >> /usr/local/etc/php/conf.d/newrelic.ini

#4

It would be something like this?

RUN curl -L $URL | tar -C /tmp -zx && \
export NR_INSTALL_USE_CP_NOT_LN=1 && \
export NR_INSTALL_SILENT=1 && \
/tmp/newrelic-php5-${NR_AGENT_VERSION}-linux/newrelic-install install && \
rm -rf /tmp/newrelic-php5-* /tmp/nrinstall* && \
sed -i -e 's/"REPLACE_WITH_REAL_KEY"/"${NEW_RELIC_LICENSE_KEY}"/' \
-e 's/newrelic.appname = "PHP Application"/newrelic.appname = "sandbox.us-east-1.blogs-web-admin"/' \
/etc/php.d/newrelic.ini && \
echo "newrelic.labels = \"Environment:sandbox;Owner:CPE-Content;Datacenter:us-east-1;AlertThresholdErrorRate:1;AlertThresholdResponseTime:15\"" >> /etc/php.d/newrelic.ini && \
sed -i -e 's/newrelic.appname = "PHP Application"/newrelic.appname = "qa.us-west-2.blogs-web-admin"/' \
/etc/php.d/newrelic.ini && \
echo "newrelic.labels = \"Environment:qa;Owner:CPE-Content;Datacenter:us-west-2;AlertThresholdErrorRate:1;AlertThresholdResponseTime:15\"" >> /etc/php.d/newrelic.ini && \
sed -i -e 's/newrelic.appname = "PHP Application"/newrelic.appname = "prod.us-west-2.blogs-web-admin"/' \
/etc/php.d/newrelic.ini && \
echo "newrelic.labels = \"Environment:prod;Owner:CPE-Content;Datacenter:us-west-2;AlertThresholdErrorRate:1;AlertThresholdResponseTime:15\"" >> /etc/php.d/newrelic.ini

#5

This looks good except for the multiple appnames and labels you are adding. Only one appname and one set of labels will be used. So you would want just one echo and one sed command for each dockerfile and set different values depending on the environments. These could also be passed in as docker arguments to let you configure the values when you run docker instead of hardcoded into the dockerfile.